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 /* MX25xx-specific commands */
10 #define CMD_MX25XX_WREN 0x06 /* Write Enable */
11 #define CMD_MX25XX_WRDI 0x04 /* Write Disable */
12 #define CMD_MX25XX_RDSR 0x05 /* Read Status Register */
13 #define CMD_MX25XX_WRSR 0x01 /* Write Status Register */
14 #define CMD_MX25XX_READ 0x03 /* Read Data Bytes */
15 #define CMD_MX25XX_FAST_READ 0x0b /* Read Data Bytes at Higher Speed */
16 #define CMD_MX25XX_PP 0x02 /* Page Program */
17 #define CMD_MX25XX_SE 0x20 /* Sector Erase */
18 #define CMD_MX25XX_BE 0xD8 /* Block Erase */
19 #define CMD_MX25XX_CE 0xc7 /* Chip Erase */
20 #define CMD_MX25XX_DP 0xb9 /* Deep Power-down */
21 #define CMD_MX25XX_RES 0xab /* Release from DP, and Read Signature */
23 #define MACRONIX_SR_WIP (1 << 0) /* Write-in-Progress */
25 static const struct spi_flash_part_id flash_table
[] = {
29 .nr_sectors_shift
= 8,
34 .nr_sectors_shift
= 9,
39 .nr_sectors_shift
= 10,
44 .nr_sectors_shift
= 11,
49 .nr_sectors_shift
= 12,
54 .nr_sectors_shift
= 13,
59 .nr_sectors_shift
= 14,
64 .nr_sectors_shift
= 9,
67 * NOTE: C225xx JEDEC IDs are basically useless because Macronix keeps
68 * reusing the same IDs for vastly different chips. 35E versions always
69 * seem to support Dual I/O but not Dual Output, while 35F versions seem
70 * to support both, so we only set Dual I/O here to improve our chances
71 * of compatibility. Since Macronix makes it impossible to search all
72 * different parts that it recklessly assigned the same IDs to, it's
73 * hard to know if there may be parts that don't even support Dual I/O
74 * with these IDs, though (or what we should do if there are).
79 .nr_sectors_shift
= 9,
80 .fast_read_dual_io_support
= 1,
85 .nr_sectors_shift
= 8,
86 .fast_read_dual_io_support
= 1,
89 /* MX25U1635E/MX25U1635F */
91 .nr_sectors_shift
= 9,
92 .fast_read_dual_io_support
= 1,
95 /* MX25U3235E/MX25U3235F */
97 .nr_sectors_shift
= 10,
98 .fast_read_dual_io_support
= 1,
101 /* MX25U6435E/MX25U6435F */
103 .nr_sectors_shift
= 11,
104 .fast_read_dual_io_support
= 1,
109 .nr_sectors_shift
= 12,
110 .fast_read_dual_io_support
= 1,
115 .nr_sectors_shift
= 13,
116 .fast_read_dual_io_support
= 1,
121 .nr_sectors_shift
= 14,
122 .fast_read_dual_io_support
= 1,
127 .nr_sectors_shift
= 12,
128 .fast_read_dual_io_support
= 1,
131 /* MX25L3235D/MX25L3225D/MX25L3236D/MX25L3237D */
133 .nr_sectors_shift
= 10,
134 .fast_read_dual_io_support
= 1,
139 .nr_sectors_shift
= 11,
144 .nr_sectors_shift
= 13,
148 const struct spi_flash_vendor_info spi_flash_macronix_vi
= {
149 .id
= VENDOR_ID_MACRONIX
,
150 .page_size_shift
= 8,
151 .sector_size_kib_shift
= 2,
152 .match_id_mask
[0] = 0xffff,
154 .nr_part_ids
= ARRAY_SIZE(flash_table
),
155 .desc
= &spi_flash_pp_0x20_sector_desc
,