xref: /aosp_15_r20/external/coreboot/src/drivers/spi/spansion.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <commonlib/helpers.h>
4 #include <spi_flash.h>
5 #include <spi-generic.h>
6 
7 #include "spi_flash_internal.h"
8 
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 */
22 
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
37 
38 static const struct spi_flash_part_id flash_table_ext[] = {
39 	{
40 		/* S25FL008A */
41 		.id[0] = SPSN_ID_S25FL008A,
42 		.nr_sectors_shift = 4,
43 	},
44 	{
45 		/* S25FL016A */
46 		.id[0] = SPSN_ID_S25FL016A,
47 		.nr_sectors_shift = 5,
48 	},
49 	{
50 		/* S25FL032A */
51 		.id[0] = SPSN_ID_S25FL032A,
52 		.nr_sectors_shift = 6,
53 	},
54 	{
55 		/* S25FL064A */
56 		.id[0] = SPSN_ID_S25FL064A,
57 		.nr_sectors_shift = 7,
58 	},
59 	{
60 		/* S25FL128P_64K */
61 		.id[0] = SPSN_ID_S25FL128P,
62 		.id[1] = SPSN_EXT_ID_S25FL128P_64KB,
63 		.nr_sectors_shift = 8,
64 	},
65 	{
66 		/* S25FL128S_256K */
67 		.id[0] = SPSN_ID_S25FL128S,
68 		.id[1] = SPSN_EXT_ID_S25FLXXS_64KB,
69 		.nr_sectors_shift = 9,
70 	},
71 	{
72 		/* S25FL032P */
73 		.id[0] = SPSN_ID_S25FL032A,
74 		.id[1] = SPSN_EXT_ID_S25FL032P,
75 		.nr_sectors_shift = 6,
76 	},
77 	{
78 		/* S25FS128S */
79 		.id[0] = SPSN_ID_S25FL128P,
80 		.id[1] = SPSN_EXT_ID_S25FLXXS_64KB,
81 		.nr_sectors_shift = 8,
82 	},
83 };
84 
85 static const struct spi_flash_part_id flash_table_256k_sector[] = {
86 	{
87 		/* S25FL128P_256K */
88 		.id[0] = SPSN_ID_S25FL128P,
89 		.id[1] = SPSN_EXT_ID_S25FL128P_256KB,
90 		.nr_sectors_shift = 6,
91 	},
92 };
93 
94 static const struct spi_flash_part_id flash_table[] = {
95 	{
96 		/* S25FL208K */
97 		.id[0] = SPSN_ID_S25FL208K,
98 		.nr_sectors_shift = 4,
99 	},
100 	{
101 		/* S25FL116K_16M */
102 		.id[0] = SPSN_ID_S25FL116K,
103 		.nr_sectors_shift = 5,
104 	},
105 	{
106 		/* S25FL132K */
107 		.id[0] = SPSN_ID_S25FL132K,
108 		.nr_sectors_shift = 6,
109 	},
110 	{
111 		/* S25FL164K */
112 		.id[0] = SPSN_ID_S25FL164K,
113 		.nr_sectors_shift = 7,
114 	},
115 };
116 
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,
126 };
127 
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,
137 };
138 
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,
144 	.ids = flash_table,
145 	.nr_part_ids = ARRAY_SIZE(flash_table),
146 	.desc = &spi_flash_pp_0xd8_sector_desc,
147 };
148