treewide: replace GPLv2 long form headers with SPDX header
[coreboot.git] / src / drivers / spi / spansion.c
blob7818ec7813dbcc663650852163c4336812ff47bb
1 /* This file is part of the coreboot project. */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 #include <console/console.h>
5 #include <commonlib/helpers.h>
6 #include <spi_flash.h>
7 #include <spi-generic.h>
8 #include <string.h>
10 #include "spi_flash_internal.h"
12 /* S25FLxx-specific commands */
13 #define CMD_S25FLXX_READ 0x03 /* Read Data Bytes */
14 #define CMD_S25FLXX_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
15 #define CMD_S25FLXX_READID 0x90 /* Read Manufacture ID and Device ID */
16 #define CMD_S25FLXX_WREN 0x06 /* Write Enable */
17 #define CMD_S25FLXX_WRDI 0x04 /* Write Disable */
18 #define CMD_S25FLXX_RDSR 0x05 /* Read Status Register */
19 #define CMD_S25FLXX_WRSR 0x01 /* Write Status Register */
20 #define CMD_S25FLXX_PP 0x02 /* Page Program */
21 #define CMD_S25FLXX_SE 0xd8 /* Sector Erase */
22 #define CMD_S25FLXX_BE 0xc7 /* Bulk Erase */
23 #define CMD_S25FLXX_DP 0xb9 /* Deep Power-down */
24 #define CMD_S25FLXX_RES 0xab /* Release from DP, and Read Signature */
26 #define SPSN_ID_S25FL008A 0x0213
27 #define SPSN_ID_S25FL016A 0x0214
28 #define SPSN_ID_S25FL032A 0x0215
29 #define SPSN_ID_S25FL064A 0x0216
30 #define SPSN_ID_S25FL128S 0x0219
31 #define SPSN_ID_S25FL128P 0x2018
32 #define SPSN_ID_S25FL208K 0x4014
33 #define SPSN_ID_S25FL116K 0x4015
34 #define SPSN_ID_S25FL132K 0x4016
35 #define SPSN_ID_S25FL164K 0x4017
36 #define SPSN_EXT_ID_S25FL128P_256KB 0x0300
37 #define SPSN_EXT_ID_S25FL128P_64KB 0x0301
38 #define SPSN_EXT_ID_S25FL032P 0x4d00
39 #define SPSN_EXT_ID_S25FLXXS_64KB 0x4d01
41 static const struct spi_flash_part_id flash_table_ext[] = {
43 /* S25FL008A */
44 .id[0] = SPSN_ID_S25FL008A,
45 .nr_sectors_shift = 4,
48 /* S25FL016A */
49 .id[0] = SPSN_ID_S25FL016A,
50 .nr_sectors_shift = 5,
53 /* S25FL032A */
54 .id[0] = SPSN_ID_S25FL032A,
55 .nr_sectors_shift = 6,
58 /* S25FL064A */
59 .id[0] = SPSN_ID_S25FL064A,
60 .nr_sectors_shift = 7,
63 /* S25FL128P_64K */
64 .id[0] = SPSN_ID_S25FL128P,
65 .id[1] = SPSN_EXT_ID_S25FL128P_64KB,
66 .nr_sectors_shift = 8,
69 /* S25FL128S_256K */
70 .id[0] = SPSN_ID_S25FL128S,
71 .id[1] = SPSN_EXT_ID_S25FLXXS_64KB,
72 .nr_sectors_shift = 9,
75 /* S25FL032P */
76 .id[0] = SPSN_ID_S25FL032A,
77 .id[1] = SPSN_EXT_ID_S25FL032P,
78 .nr_sectors_shift = 6,
81 /* S25FS128S */
82 .id[0] = SPSN_ID_S25FL128P,
83 .id[1] = SPSN_EXT_ID_S25FLXXS_64KB,
84 .nr_sectors_shift = 8,
88 static const struct spi_flash_part_id flash_table_256k_sector[] = {
90 /* S25FL128P_256K */
91 .id[0] = SPSN_ID_S25FL128P,
92 .id[1] = SPSN_EXT_ID_S25FL128P_256KB,
93 .nr_sectors_shift = 6,
97 static const struct spi_flash_part_id flash_table[] = {
99 /* S25FL208K */
100 .id[0] = SPSN_ID_S25FL208K,
101 .nr_sectors_shift = 4,
104 /* S25FL116K_16M */
105 .id[0] = SPSN_ID_S25FL116K,
106 .nr_sectors_shift = 5,
109 /* S25FL132K */
110 .id[0] = SPSN_ID_S25FL132K,
111 .nr_sectors_shift = 6,
114 /* S25FL164K */
115 .id[0] = SPSN_ID_S25FL164K,
116 .nr_sectors_shift = 7,
120 const struct spi_flash_vendor_info spi_flash_spansion_ext1_vi = {
121 .id = VENDOR_ID_SPANSION,
122 .page_size_shift = 8,
123 .sector_size_kib_shift = 6,
124 .match_id_mask[0] = 0xffff,
125 .match_id_mask[1] = 0xffff,
126 .ids = flash_table_ext,
127 .nr_part_ids = ARRAY_SIZE(flash_table_ext),
128 .desc = &spi_flash_pp_0xd8_sector_desc,
131 const struct spi_flash_vendor_info spi_flash_spansion_ext2_vi = {
132 .id = VENDOR_ID_SPANSION,
133 .page_size_shift = 8,
134 .sector_size_kib_shift = 8,
135 .match_id_mask[0] = 0xffff,
136 .match_id_mask[1] = 0xffff,
137 .ids = flash_table_256k_sector,
138 .nr_part_ids = ARRAY_SIZE(flash_table_256k_sector),
139 .desc = &spi_flash_pp_0xd8_sector_desc,
142 const struct spi_flash_vendor_info spi_flash_spansion_vi = {
143 .id = VENDOR_ID_SPANSION,
144 .page_size_shift = 8,
145 .sector_size_kib_shift = 6,
146 .match_id_mask[0] = 0xffff,
147 .ids = flash_table,
148 .nr_part_ids = ARRAY_SIZE(flash_table),
149 .desc = &spi_flash_pp_0xd8_sector_desc,