2 * Copyright 2008, Network Appliance Inc.
3 * Author: Jason McMullan <mcmullan <at> netapp.com>
4 * Licensed under the GPL-2 or later.
11 #include "spi_flash_internal.h"
13 /* M25Pxx-specific commands */
14 #define CMD_W25_WREN 0x06 /* Write Enable */
15 #define CMD_W25_WRDI 0x04 /* Write Disable */
16 #define CMD_W25_RDSR 0x05 /* Read Status Register */
17 #define CMD_W25_WRSR 0x01 /* Write Status Register */
18 #define CMD_W25_READ 0x03 /* Read Data Bytes */
19 #define CMD_W25_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
20 #define CMD_W25_PP 0x02 /* Page Program */
21 #define CMD_W25_SE 0x20 /* Sector (4K) Erase */
22 #define CMD_W25_BE 0xd8 /* Block (64K) Erase */
23 #define CMD_W25_CE 0xc7 /* Chip Erase */
24 #define CMD_W25_DP 0xb9 /* Deep Power-down */
25 #define CMD_W25_RES 0xab /* Release from DP, and Read Signature */
27 struct winbond_spi_flash_params {
29 /* Log2 of page size in power-of-two mode */
31 uint16_t pages_per_sector;
32 uint16_t sectors_per_block;
37 /* spi_flash needs to be first so upper layers can free() it */
38 struct winbond_spi_flash {
39 struct spi_flash flash;
40 const struct winbond_spi_flash_params *params;
43 static inline struct winbond_spi_flash *
44 to_winbond_spi_flash(struct spi_flash *flash)
46 return container_of(flash, struct winbond_spi_flash, flash);
49 static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
53 .pages_per_sector = 16,
54 .sectors_per_block = 16,
61 .pages_per_sector = 16,
62 .sectors_per_block = 16,
69 .pages_per_sector = 16,
70 .sectors_per_block = 16,
77 .pages_per_sector = 16,
78 .sectors_per_block = 16,
85 .pages_per_sector = 16,
86 .sectors_per_block = 16,
93 .pages_per_sector = 16,
94 .sectors_per_block = 16,
101 .pages_per_sector = 16,
102 .sectors_per_block = 16,
108 static int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
110 return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
113 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
115 const struct winbond_spi_flash_params *params;
117 struct winbond_spi_flash *stm;
120 for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
121 params = &winbond_spi_flash_table[i];
122 if (params->id == ((idcode[1] << 8) | idcode[2]))
126 if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
127 debug("SF: Unsupported Winbond ID %02x%02x\n",
128 idcode[1], idcode[2]);
132 stm = malloc(sizeof(struct winbond_spi_flash));
134 debug("SF: Failed to allocate memory\n");
138 stm->params = params;
139 stm->flash.spi = spi;
140 stm->flash.name = params->name;
142 /* Assuming power-of-two page size initially. */
143 page_size = 1 << params->l2_page_size;
145 stm->flash.write = spi_flash_cmd_write_multi;
146 stm->flash.erase = winbond_erase;
147 stm->flash.read = spi_flash_cmd_read_fast;
148 stm->flash.page_size = page_size;
149 stm->flash.sector_size = page_size * stm->params->pages_per_sector;
150 stm->flash.size = page_size * params->pages_per_sector
151 * params->sectors_per_block