Skip to content

Commit

Permalink
drivers/mtd_spi_nor: fix Atmel size calculation
Browse files Browse the repository at this point in the history
Lower bits of the device ID are not the capacity in bytes but in sectors:

 4 - 4 Mb -> 32k << 4
 5 - 8 Mb -> 32k << 5
 …
  • Loading branch information
benpicco committed Feb 25, 2022
1 parent 1ea951d commit 37df78e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/mtd_spi_nor/mtd_spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ static uint32_t mtd_spi_nor_get_size(const mtd_jedec_id_t *id)
if (mtd_spi_manuf_match(id, SPI_NOR_JEDEC_ATMEL) &&
/* ID 2 is used to encode the product version, usually 1 or 2 */
(id->device[1] & ~0x3) == 0) {
return (0x1F & id->device[0]) * MBIT_AS_BYTES;
/* capacity encoded as power of 32k sectors */
return (32 * 1024) << (0x1F & id->device[0]);
}
if (mtd_spi_manuf_match(id, SPI_NOR_JEDEC_MICROCHIP)) {
switch (id->device[1]) {
Expand Down

0 comments on commit 37df78e

Please sign in to comment.