1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <commonlib/helpers.h>
5 #include <spi-generic.h>
7 #include "spi_flash_internal.h"
9 /* S25FLxx-specific commands */
10 #define CMD_S25FLXX_READ 0x03 /* Read Data Bytes */
11 #define CMD_S25FLXX_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
12 #define CMD_S25FLXX_READID 0x90 /* Read Manufacture ID and Device ID */
13 #define CMD_S25FLXX_WREN 0x06 /* Write Enable */
14 #define CMD_S25FLXX_WRDI 0x04 /* Write Disable */
15 #define CMD_S25FLXX_RDSR 0x05 /* Read Status Register */
16 #define CMD_S25FLXX_WRSR 0x01 /* Write Status Register */
17 #define CMD_S25FLXX_PP 0x02 /* Page Program */
18 #define CMD_S25FLXX_SE 0xd8 /* Sector Erase */
19 #define CMD_S25FLXX_BE 0xc7 /* Bulk Erase */
20 #define CMD_S25FLXX_DP 0xb9 /* Deep Power-down */
21 #define CMD_S25FLXX_RES 0xab /* Release from DP, and Read Signature */
23 #define SPSN_ID_S25FL008A 0x0213
24 #define SPSN_ID_S25FL016A 0x0214
25 #define SPSN_ID_S25FL032A 0x0215
26 #define SPSN_ID_S25FL064A 0x0216
27 #define SPSN_ID_S25FL128S 0x0219
28 #define SPSN_ID_S25FL128P 0x2018
29 #define SPSN_ID_S25FL208K 0x4014
30 #define SPSN_ID_S25FL116K 0x4015
31 #define SPSN_ID_S25FL132K 0x4016
32 #define SPSN_ID_S25FL164K 0x4017
33 #define SPSN_EXT_ID_S25FL128P_256KB 0x0300
34 #define SPSN_EXT_ID_S25FL128P_64KB 0x0301
35 #define SPSN_EXT_ID_S25FL032P 0x4d00
36 #define SPSN_EXT_ID_S25FLXXS_64KB 0x4d01
38 static const struct spi_flash_part_id flash_table_ext
[] = {
41 .id
[0] = SPSN_ID_S25FL008A
,
42 .nr_sectors_shift
= 4,
46 .id
[0] = SPSN_ID_S25FL016A
,
47 .nr_sectors_shift
= 5,
51 .id
[0] = SPSN_ID_S25FL032A
,
52 .nr_sectors_shift
= 6,
56 .id
[0] = SPSN_ID_S25FL064A
,
57 .nr_sectors_shift
= 7,
61 .id
[0] = SPSN_ID_S25FL128P
,
62 .id
[1] = SPSN_EXT_ID_S25FL128P_64KB
,
63 .nr_sectors_shift
= 8,
67 .id
[0] = SPSN_ID_S25FL128S
,
68 .id
[1] = SPSN_EXT_ID_S25FLXXS_64KB
,
69 .nr_sectors_shift
= 9,
73 .id
[0] = SPSN_ID_S25FL032A
,
74 .id
[1] = SPSN_EXT_ID_S25FL032P
,
75 .nr_sectors_shift
= 6,
79 .id
[0] = SPSN_ID_S25FL128P
,
80 .id
[1] = SPSN_EXT_ID_S25FLXXS_64KB
,
81 .nr_sectors_shift
= 8,
85 static const struct spi_flash_part_id flash_table_256k_sector
[] = {
88 .id
[0] = SPSN_ID_S25FL128P
,
89 .id
[1] = SPSN_EXT_ID_S25FL128P_256KB
,
90 .nr_sectors_shift
= 6,
94 static const struct spi_flash_part_id flash_table
[] = {
97 .id
[0] = SPSN_ID_S25FL208K
,
98 .nr_sectors_shift
= 4,
102 .id
[0] = SPSN_ID_S25FL116K
,
103 .nr_sectors_shift
= 5,
107 .id
[0] = SPSN_ID_S25FL132K
,
108 .nr_sectors_shift
= 6,
112 .id
[0] = SPSN_ID_S25FL164K
,
113 .nr_sectors_shift
= 7,
117 const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi
= {
118 .id
= VENDOR_ID_SPANSION
,
119 .page_size_shift
= 8,
120 .sector_size_kib_shift
= 6,
121 .match_id_mask
[0] = 0xffff,
122 .match_id_mask
[1] = 0xffff,
123 .ids
= flash_table_ext
,
124 .nr_part_ids
= ARRAY_SIZE(flash_table_ext
),
125 .desc
= &spi_flash_pp_0xd8_sector_desc
,
128 const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi
= {
129 .id
= VENDOR_ID_SPANSION
,
130 .page_size_shift
= 8,
131 .sector_size_kib_shift
= 8,
132 .match_id_mask
[0] = 0xffff,
133 .match_id_mask
[1] = 0xffff,
134 .ids
= flash_table_256k_sector
,
135 .nr_part_ids
= ARRAY_SIZE(flash_table_256k_sector
),
136 .desc
= &spi_flash_pp_0xd8_sector_desc
,
139 const struct spi_flash_vendor_info spi_flash_spansion_vi
= {
140 .id
= VENDOR_ID_SPANSION
,
141 .page_size_shift
= 8,
142 .sector_size_kib_shift
= 6,
143 .match_id_mask
[0] = 0xffff,
145 .nr_part_ids
= ARRAY_SIZE(flash_table
),
146 .desc
= &spi_flash_pp_0xd8_sector_desc
,