summaryrefslogtreecommitdiff
path: root/src/drivers/spi/adesto.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/spi/adesto.c')
-rw-r--r--src/drivers/spi/adesto.c54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index 1091d9a4b1..c5c68b546b 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -42,18 +42,6 @@ struct adesto_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct adesto_spi_flash {
- struct spi_flash flash;
- const struct adesto_spi_flash_params *params;
-};
-
-static inline struct adesto_spi_flash *
-to_adesto_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct adesto_spi_flash, flash);
-}
-
static const struct adesto_spi_flash_params adesto_spi_flash_table[] = {
{
.id = 0x4501,
@@ -84,7 +72,6 @@ static const struct adesto_spi_flash_params adesto_spi_flash_table[] = {
static int adesto_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct adesto_spi_flash *stm = to_adesto_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -92,7 +79,7 @@ static int adesto_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret;
u8 cmd[4];
- page_size = 1 << stm->params->l2_page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -142,8 +129,7 @@ out:
struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
{
const struct adesto_spi_flash_params *params;
- unsigned page_size;
- struct adesto_spi_flash *stm;
+ struct spi_flash *flash;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(adesto_spi_flash_table); i++) {
@@ -158,32 +144,28 @@ struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- stm = malloc(sizeof(struct adesto_spi_flash));
- if (!stm) {
+ flash = malloc(sizeof(*flash));
+ if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
return NULL;
}
- stm->params = params;
- memcpy(&stm->flash.spi, spi, sizeof(*spi));
- stm->flash.name = params->name;
-
+ memcpy(&flash->spi, spi, sizeof(*spi));
+ flash->name = params->name;
/* Assuming power-of-two page size initially. */
- page_size = 1 << params->l2_page_size;
-
- stm->flash.internal_write = adesto_write;
- stm->flash.internal_erase = spi_flash_cmd_erase;
+ flash->page_size = 1 << params->l2_page_size;
+ flash->sector_size = flash->page_size * params->pages_per_sector;
+ flash->size = flash->sector_size *params->sectors_per_block *
+ params->nr_blocks;
+ flash->erase_cmd = CMD_AT25DF_SE;
+
+ flash->internal_write = adesto_write;
+ flash->internal_erase = spi_flash_cmd_erase;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- stm->flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- stm->flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- stm->flash.sector_size = (1 << stm->params->l2_page_size) *
- stm->params->pages_per_sector;
- stm->flash.size = page_size * params->pages_per_sector
- * params->sectors_per_block
- * params->nr_blocks;
- stm->flash.erase_cmd = CMD_AT25DF_SE;
-
- return &stm->flash;
+
+ return flash;
}