drivers/spi/spi_flash: Move flash ops to spi_flash_ops structure
Define a new spi_flash_ops structure, move all spi flash operations to this structure and add a pointer to this structure in struct spi_flash. BUG=b:38330715 Change-Id: I550cc4556fc4b63ebc174a7e2fde42251fe56052 Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://review.coreboot.org/19757 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
parent
a1491574ef
commit
e2fc5e25f2
|
@ -126,6 +126,16 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = adesto_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
#if IS_ENABLED(CONFIG_SPI_FLASH_NO_FAST_READ)
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
#else
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_adesto(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_adesto(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -153,13 +163,7 @@ int spi_flash_probe_adesto(const struct spi_slave *spi, u8 *idcode,
|
||||||
params->nr_blocks;
|
params->nr_blocks;
|
||||||
flash->erase_cmd = CMD_AT25DF_SE;
|
flash->erase_cmd = CMD_AT25DF_SE;
|
||||||
|
|
||||||
flash->internal_write = adesto_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
#else
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,6 +109,16 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = amic_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
#if IS_ENABLED(CONFIG_SPI_FLASH_NO_FAST_READ)
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
#else
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_amic(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_amic(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -137,13 +147,7 @@ int spi_flash_probe_amic(const struct spi_slave *spi, u8 *idcode,
|
||||||
params->nr_blocks;
|
params->nr_blocks;
|
||||||
flash->erase_cmd = CMD_A25_SE;
|
flash->erase_cmd = CMD_A25_SE;
|
||||||
|
|
||||||
flash->internal_write = amic_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
#else
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,6 +154,16 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = atmel_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
#if IS_ENABLED(CONFIG_SPI_FLASH_NO_FAST_READ)
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
#else
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_atmel(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_atmel(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -182,13 +192,7 @@ int spi_flash_probe_atmel(const struct spi_slave *spi, u8 *idcode,
|
||||||
params->nr_blocks;
|
params->nr_blocks;
|
||||||
flash->erase_cmd = CMD_AT25_SE;
|
flash->erase_cmd = CMD_AT25_SE;
|
||||||
|
|
||||||
flash->internal_write = atmel_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
#else
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,13 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = eon_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_eon(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_eon(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -153,10 +160,7 @@ int spi_flash_probe_eon(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->erase_cmd = CMD_EN25_SE;
|
flash->erase_cmd = CMD_EN25_SE;
|
||||||
flash->status_cmd = CMD_EN25_RDSR;
|
flash->status_cmd = CMD_EN25_RDSR;
|
||||||
|
|
||||||
flash->internal_write = eon_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_status = spi_flash_cmd_status;
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,17 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = gigadevice_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
#if IS_ENABLED(CONFIG_SPI_FLASH_NO_FAST_READ)
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
#else
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_gigadevice(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_gigadevice(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -200,14 +211,7 @@ int spi_flash_probe_gigadevice(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->erase_cmd = CMD_GD25_SE;
|
flash->erase_cmd = CMD_GD25_SE;
|
||||||
flash->status_cmd = CMD_GD25_RDSR;
|
flash->status_cmd = CMD_GD25_RDSR;
|
||||||
|
|
||||||
flash->internal_write = gigadevice_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_status = spi_flash_cmd_status;
|
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
#else
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,17 @@ static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = macronix_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
#if IS_ENABLED(CONFIG_SPI_FLASH_NO_FAST_READ)
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
#else
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_macronix(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_macronix(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -219,14 +230,7 @@ int spi_flash_probe_macronix(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->erase_cmd = CMD_MX25XX_SE;
|
flash->erase_cmd = CMD_MX25XX_SE;
|
||||||
flash->status_cmd = CMD_MX25XX_RDSR;
|
flash->status_cmd = CMD_MX25XX_RDSR;
|
||||||
|
|
||||||
flash->internal_write = macronix_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_status = spi_flash_cmd_status;
|
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
#else
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,6 +246,13 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = spansion_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -273,10 +280,7 @@ int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->erase_cmd = CMD_S25FLXX_SE;
|
flash->erase_cmd = CMD_S25FLXX_SE;
|
||||||
flash->status_cmd = CMD_S25FLXX_RDSR;
|
flash->status_cmd = CMD_S25FLXX_RDSR;
|
||||||
|
|
||||||
flash->internal_write = spansion_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
flash->internal_status = spi_flash_cmd_status;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -350,7 +350,7 @@ int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash)
|
||||||
int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len,
|
int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
void *buf)
|
void *buf)
|
||||||
{
|
{
|
||||||
return flash->internal_read(flash, offset, len, buf);
|
return flash->ops->read(flash, offset, len, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int spi_flash_write(const struct spi_flash *flash, u32 offset, size_t len,
|
int spi_flash_write(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
|
@ -361,7 +361,7 @@ int spi_flash_write(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
if (spi_flash_volatile_group_begin(flash))
|
if (spi_flash_volatile_group_begin(flash))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = flash->internal_write(flash, offset, len, buf);
|
ret = flash->ops->write(flash, offset, len, buf);
|
||||||
|
|
||||||
if (spi_flash_volatile_group_end(flash))
|
if (spi_flash_volatile_group_end(flash))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -376,7 +376,7 @@ int spi_flash_erase(const struct spi_flash *flash, u32 offset, size_t len)
|
||||||
if (spi_flash_volatile_group_begin(flash))
|
if (spi_flash_volatile_group_begin(flash))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = flash->internal_erase(flash, offset, len);
|
ret = flash->ops->erase(flash, offset, len);
|
||||||
|
|
||||||
if (spi_flash_volatile_group_end(flash))
|
if (spi_flash_volatile_group_end(flash))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -386,7 +386,10 @@ int spi_flash_erase(const struct spi_flash *flash, u32 offset, size_t len)
|
||||||
|
|
||||||
int spi_flash_status(const struct spi_flash *flash, u8 *reg)
|
int spi_flash_status(const struct spi_flash *flash, u8 *reg)
|
||||||
{
|
{
|
||||||
return flash->internal_status(flash, reg);
|
if (flash->ops->status)
|
||||||
|
return flash->ops->status(flash, reg);
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t volatile_group_count CAR_GLOBAL;
|
static uint32_t volatile_group_count CAR_GLOBAL;
|
||||||
|
|
|
@ -43,8 +43,7 @@ struct sst_spi_flash_params {
|
||||||
u8 idcode1;
|
u8 idcode1;
|
||||||
u16 nr_sectors;
|
u16 nr_sectors;
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*write)(const struct spi_flash *flash, u32 offset,
|
const struct spi_flash_ops *ops;
|
||||||
size_t len, const void *buf);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len,
|
static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
|
@ -52,53 +51,67 @@ static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len,
|
static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
const void *buf);
|
const void *buf);
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops_write_ai = {
|
||||||
|
.write = sst_write_ai,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops_write_256 = {
|
||||||
|
.write = sst_write_256,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
};
|
||||||
|
|
||||||
#define SST_SECTOR_SIZE (4 * 1024)
|
#define SST_SECTOR_SIZE (4 * 1024)
|
||||||
static const struct sst_spi_flash_params sst_spi_flash_table[] = {
|
static const struct sst_spi_flash_params sst_spi_flash_table[] = {
|
||||||
{
|
{
|
||||||
.idcode1 = 0x8d,
|
.idcode1 = 0x8d,
|
||||||
.nr_sectors = 128,
|
.nr_sectors = 128,
|
||||||
.name = "SST25VF040B",
|
.name = "SST25VF040B",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x8e,
|
.idcode1 = 0x8e,
|
||||||
.nr_sectors = 256,
|
.nr_sectors = 256,
|
||||||
.name = "SST25VF080B",
|
.name = "SST25VF080B",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x41,
|
.idcode1 = 0x41,
|
||||||
.nr_sectors = 512,
|
.nr_sectors = 512,
|
||||||
.name = "SST25VF016B",
|
.name = "SST25VF016B",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x4a,
|
.idcode1 = 0x4a,
|
||||||
.nr_sectors = 1024,
|
.nr_sectors = 1024,
|
||||||
.name = "SST25VF032B",
|
.name = "SST25VF032B",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x4b,
|
.idcode1 = 0x4b,
|
||||||
.nr_sectors = 2048,
|
.nr_sectors = 2048,
|
||||||
.name = "SST25VF064C",
|
.name = "SST25VF064C",
|
||||||
.write = sst_write_256,
|
.ops = &spi_flash_ops_write_256,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x01,
|
.idcode1 = 0x01,
|
||||||
.nr_sectors = 16,
|
.nr_sectors = 16,
|
||||||
.name = "SST25WF512",
|
.name = "SST25WF512",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x02,
|
.idcode1 = 0x02,
|
||||||
.nr_sectors = 32,
|
.nr_sectors = 32,
|
||||||
.name = "SST25WF010",
|
.name = "SST25WF010",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x03,
|
.idcode1 = 0x03,
|
||||||
.nr_sectors = 64,
|
.nr_sectors = 64,
|
||||||
.name = "SST25WF020",
|
.name = "SST25WF020",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},{
|
},{
|
||||||
.idcode1 = 0x04,
|
.idcode1 = 0x04,
|
||||||
.nr_sectors = 128,
|
.nr_sectors = 128,
|
||||||
.name = "SST25WF040",
|
.name = "SST25WF040",
|
||||||
.write = sst_write_ai,
|
.ops = &spi_flash_ops_write_ai,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -338,10 +351,7 @@ int spi_flash_probe_sst(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->erase_cmd = CMD_SST_SE;
|
flash->erase_cmd = CMD_SST_SE;
|
||||||
flash->status_cmd = CMD_SST_RDSR;
|
flash->status_cmd = CMD_SST_RDSR;
|
||||||
|
|
||||||
flash->internal_write = params->write;
|
flash->ops = params->ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_status = spi_flash_cmd_status;
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
|
|
||||||
/* Flash powers up read-only, so clear BP# bits */
|
/* Flash powers up read-only, so clear BP# bits */
|
||||||
sst_unlock(flash);
|
sst_unlock(flash);
|
||||||
|
|
|
@ -222,6 +222,12 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = stmicro_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_stmicro(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_stmicro(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -260,9 +266,7 @@ int spi_flash_probe_stmicro(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->size = flash->sector_size * params->nr_sectors;
|
flash->size = flash->sector_size * params->nr_sectors;
|
||||||
flash->erase_cmd = params->op_erase;
|
flash->erase_cmd = params->op_erase;
|
||||||
|
|
||||||
flash->internal_write = stmicro_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,17 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.write = winbond_write,
|
||||||
|
.erase = spi_flash_cmd_erase,
|
||||||
|
.status = spi_flash_cmd_status,
|
||||||
|
#if IS_ENABLED(CONFIG_SPI_FLASH_NO_FAST_READ)
|
||||||
|
.read = spi_flash_cmd_read_slow,
|
||||||
|
#else
|
||||||
|
.read = spi_flash_cmd_read_fast,
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode,
|
int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -212,14 +223,7 @@ int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode,
|
||||||
flash->erase_cmd = CMD_W25_SE;
|
flash->erase_cmd = CMD_W25_SE;
|
||||||
flash->status_cmd = CMD_W25_RDSR;
|
flash->status_cmd = CMD_W25_RDSR;
|
||||||
|
|
||||||
flash->internal_write = winbond_write;
|
flash->ops = &spi_flash_ops;
|
||||||
flash->internal_erase = spi_flash_cmd_erase;
|
|
||||||
flash->internal_status = spi_flash_cmd_status;
|
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
|
||||||
flash->internal_read = spi_flash_cmd_read_slow;
|
|
||||||
#else
|
|
||||||
flash->internal_read = spi_flash_cmd_read_fast;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,24 @@
|
||||||
#define SPI_OPCODE_WREN 0x06
|
#define SPI_OPCODE_WREN 0x06
|
||||||
#define SPI_OPCODE_FAST_READ 0x0b
|
#define SPI_OPCODE_FAST_READ 0x0b
|
||||||
|
|
||||||
|
struct spi_flash;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Representation of SPI flash operations:
|
||||||
|
* read: Flash read operation.
|
||||||
|
* write: Flash write operation.
|
||||||
|
* erase: Flash erase operation.
|
||||||
|
* status: Read flash status register.
|
||||||
|
*/
|
||||||
|
struct spi_flash_ops {
|
||||||
|
int (*read)(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
|
void *buf);
|
||||||
|
int (*write)(const struct spi_flash *flash, u32 offset, size_t len,
|
||||||
|
const void *buf);
|
||||||
|
int (*erase)(const struct spi_flash *flash, u32 offset, size_t len);
|
||||||
|
int (*status)(const struct spi_flash *flash, u8 *reg);
|
||||||
|
};
|
||||||
|
|
||||||
struct spi_flash {
|
struct spi_flash {
|
||||||
struct spi_slave spi;
|
struct spi_slave spi;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -32,19 +50,7 @@ struct spi_flash {
|
||||||
u32 page_size;
|
u32 page_size;
|
||||||
u8 erase_cmd;
|
u8 erase_cmd;
|
||||||
u8 status_cmd;
|
u8 status_cmd;
|
||||||
/*
|
const struct spi_flash_ops *ops;
|
||||||
* Internal functions are expected to be called ONLY by spi flash
|
|
||||||
* driver. External components should only use the public API calls
|
|
||||||
* spi_flash_{read,write,erase,status,volatile_group_begin,
|
|
||||||
* volatile_group_end}.
|
|
||||||
*/
|
|
||||||
int (*internal_read)(const struct spi_flash *flash, u32 offset,
|
|
||||||
size_t len, void *buf);
|
|
||||||
int (*internal_write)(const struct spi_flash *flash, u32 offset,
|
|
||||||
size_t len, const void *buf);
|
|
||||||
int (*internal_erase)(const struct spi_flash *flash, u32 offset,
|
|
||||||
size_t len);
|
|
||||||
int (*internal_status)(const struct spi_flash *flash, u8 *reg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void lb_spi_flash(struct lb_header *header);
|
void lb_spi_flash(struct lb_header *header);
|
||||||
|
|
|
@ -273,6 +273,13 @@ static int fast_spi_flash_status(const struct spi_flash *flash,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct spi_flash_ops fast_spi_flash_ops = {
|
||||||
|
.read = fast_spi_flash_read,
|
||||||
|
.write = fast_spi_flash_write,
|
||||||
|
.erase = fast_spi_flash_erase,
|
||||||
|
.status = fast_spi_flash_status,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We can't use FDOC and FDOD to read FLCOMP, as previous platforms did.
|
* We can't use FDOC and FDOD to read FLCOMP, as previous platforms did.
|
||||||
* For details see:
|
* For details see:
|
||||||
|
@ -307,11 +314,7 @@ static int fast_spi_flash_probe(const struct spi_slave *dev,
|
||||||
* flash->status_cmd = ???
|
* flash->status_cmd = ???
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flash->internal_write = fast_spi_flash_write;
|
flash->ops = &fast_spi_flash_ops;
|
||||||
flash->internal_erase = fast_spi_flash_erase;
|
|
||||||
flash->internal_read = fast_spi_flash_read;
|
|
||||||
flash->internal_status = fast_spi_flash_status;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -228,18 +228,24 @@ static int nor_erase(const struct spi_flash *flash, u32 offset, size_t len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mtk_spi_flash_probe(const struct spi_slave *spi, struct spi_flash *flash)
|
const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.read = nor_read,
|
||||||
|
.write = nor_write,
|
||||||
|
.erase = nor_erase,
|
||||||
|
};
|
||||||
|
|
||||||
|
int mtk_spi_flash_probe(const struct spi_slave *spi,
|
||||||
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
write32(&mt8173_nor->wrprot, SFLASH_COMMAND_ENABLE);
|
write32(&mt8173_nor->wrprot, SFLASH_COMMAND_ENABLE);
|
||||||
memcpy(&flash->spi, spi, sizeof(*spi));
|
memcpy(&flash->spi, spi, sizeof(*spi));
|
||||||
|
|
||||||
flash->name = "mt8173 flash controller";
|
flash->name = "mt8173 flash controller";
|
||||||
flash->internal_write = nor_write;
|
|
||||||
flash->internal_erase = nor_erase;
|
|
||||||
flash->internal_read = nor_read;
|
|
||||||
flash->internal_status = 0;
|
|
||||||
flash->sector_size = 0x1000;
|
flash->sector_size = 0x1000;
|
||||||
flash->erase_cmd = SECTOR_ERASE_CMD;
|
flash->erase_cmd = SECTOR_ERASE_CMD;
|
||||||
flash->size = CONFIG_ROM_SIZE;
|
flash->size = CONFIG_ROM_SIZE;
|
||||||
|
|
||||||
|
flash->ops = &spi_flash_ops;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -885,6 +885,12 @@ static int ich_hwseq_write(const struct spi_flash *flash, u32 addr, size_t len,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct spi_flash_ops spi_flash_ops = {
|
||||||
|
.read = ich_hwseq_read,
|
||||||
|
.write = ich_hwseq_write,
|
||||||
|
.erase = ich_hwseq_erase,
|
||||||
|
};
|
||||||
|
|
||||||
static int spi_flash_programmer_probe(const struct spi_slave *spi,
|
static int spi_flash_programmer_probe(const struct spi_slave *spi,
|
||||||
struct spi_flash *flash)
|
struct spi_flash *flash)
|
||||||
{
|
{
|
||||||
|
@ -897,9 +903,6 @@ static int spi_flash_programmer_probe(const struct spi_slave *spi,
|
||||||
memcpy(&flash->spi, spi, sizeof(*spi));
|
memcpy(&flash->spi, spi, sizeof(*spi));
|
||||||
flash->name = "Opaque HW-sequencing";
|
flash->name = "Opaque HW-sequencing";
|
||||||
|
|
||||||
flash->internal_write = ich_hwseq_write;
|
|
||||||
flash->internal_erase = ich_hwseq_erase;
|
|
||||||
flash->internal_read = ich_hwseq_read;
|
|
||||||
ich_hwseq_set_addr (0);
|
ich_hwseq_set_addr (0);
|
||||||
switch ((cntlr.hsfs >> 3) & 3)
|
switch ((cntlr.hsfs >> 3) & 3)
|
||||||
{
|
{
|
||||||
|
@ -922,6 +925,8 @@ static int spi_flash_programmer_probe(const struct spi_slave *spi,
|
||||||
|
|
||||||
flash->size = 1 << (19 + (flcomp & 7));
|
flash->size = 1 << (19 + (flcomp & 7));
|
||||||
|
|
||||||
|
flash->ops = &spi_flash_ops;
|
||||||
|
|
||||||
if ((cntlr.hsfs & HSFS_FDV) && ((cntlr.flmap0 >> 8) & 3))
|
if ((cntlr.hsfs & HSFS_FDV) && ((cntlr.flmap0 >> 8) & 3))
|
||||||
flash->size += 1 << (19 + ((flcomp >> 3) & 7));
|
flash->size += 1 << (19 + ((flcomp >> 3) & 7));
|
||||||
printk (BIOS_DEBUG, "flash size 0x%x bytes\n", flash->size);
|
printk (BIOS_DEBUG, "flash size 0x%x bytes\n", flash->size);
|
||||||
|
|
Loading…
Reference in New Issue