blob: cc834d9ee9aceed2178f8f01d4f22cf46b6eb66f [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -07002
Elyes HAOUAS361a9352019-12-18 21:26:33 +01003#include <commonlib/helpers.h>
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -07004#include <spi_flash.h>
Furquan Shaikhc28984d2016-11-20 21:04:00 -08005#include <spi-generic.h>
Edward O'Callaghanc4561e22014-06-26 15:02:40 +10006
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -07007#include "spi_flash_internal.h"
8
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 */
22
23#define MACRONIX_SR_WIP (1 << 0) /* Write-in-Progress */
24
Aaron Durbina6c73c82020-01-11 23:18:51 -070025static const struct spi_flash_part_id flash_table[] = {
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070026 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070027 /* MX25L8005 */
28 .id[0] = 0x2014,
Aaron Durbina6c73c82020-01-11 23:18:51 -070029 .nr_sectors_shift = 8,
Arthur Heymanse73a85c2018-06-13 00:20:31 +020030 },
31 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070032 /* MX25L1605D */
33 .id[0] = 0x2015,
Aaron Durbina6c73c82020-01-11 23:18:51 -070034 .nr_sectors_shift = 9,
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070035 },
36 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070037 /* MX25L3205D */
38 .id[0] = 0x2016,
Aaron Durbina6c73c82020-01-11 23:18:51 -070039 .nr_sectors_shift = 10,
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070040 },
41 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070042 /* MX25L6405D */
43 .id[0] = 0x2017,
Aaron Durbina6c73c82020-01-11 23:18:51 -070044 .nr_sectors_shift = 11,
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070045 },
46 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070047 /* MX25L12805D */
48 .id[0] = 0x2018,
Aaron Durbina6c73c82020-01-11 23:18:51 -070049 .nr_sectors_shift = 12,
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070050 },
51 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070052 /* MX25L25635F */
53 .id[0] = 0x2019,
Aaron Durbina6c73c82020-01-11 23:18:51 -070054 .nr_sectors_shift = 13,
Mike Banon4902a802019-01-12 13:55:09 +030055 },
56 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070057 /* MX66L51235F */
58 .id[0] = 0x201a,
Aaron Durbina6c73c82020-01-11 23:18:51 -070059 .nr_sectors_shift = 14,
Mike Banon4902a802019-01-12 13:55:09 +030060 },
61 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070062 /* MX25L1635D */
63 .id[0] = 0x2415,
Aaron Durbina6c73c82020-01-11 23:18:51 -070064 .nr_sectors_shift = 9,
Mike Banon4902a802019-01-12 13:55:09 +030065 },
Julius Wernerdf506222021-07-13 15:57:29 -070066 /*
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).
75 */
Mike Banon4902a802019-01-12 13:55:09 +030076 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070077 /* MX25L1635E */
78 .id[0] = 0x2515,
Aaron Durbina6c73c82020-01-11 23:18:51 -070079 .nr_sectors_shift = 9,
Julius Wernerdf506222021-07-13 15:57:29 -070080 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +030081 },
82 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -070083 /* MX25U8032E */
84 .id[0] = 0x2534,
Aaron Durbina6c73c82020-01-11 23:18:51 -070085 .nr_sectors_shift = 8,
Julius Wernerdf506222021-07-13 15:57:29 -070086 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +030087 },
88 {
Julius Wernerdf506222021-07-13 15:57:29 -070089 /* MX25U1635E/MX25U1635F */
Aaron Durbinfc7b9532020-01-23 11:45:30 -070090 .id[0] = 0x2535,
Aaron Durbina6c73c82020-01-11 23:18:51 -070091 .nr_sectors_shift = 9,
Julius Wernerdf506222021-07-13 15:57:29 -070092 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +030093 },
94 {
Julius Wernerdf506222021-07-13 15:57:29 -070095 /* MX25U3235E/MX25U3235F */
Aaron Durbinfc7b9532020-01-23 11:45:30 -070096 .id[0] = 0x2536,
Aaron Durbina6c73c82020-01-11 23:18:51 -070097 .nr_sectors_shift = 10,
Julius Wernerdf506222021-07-13 15:57:29 -070098 .fast_read_dual_io_support = 1,
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -070099 },
Idwer Vollering06413ff2014-10-26 01:20:20 +0200100 {
Julius Wernerdf506222021-07-13 15:57:29 -0700101 /* MX25U6435E/MX25U6435F */
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700102 .id[0] = 0x2537,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700103 .nr_sectors_shift = 11,
Julius Wernerdf506222021-07-13 15:57:29 -0700104 .fast_read_dual_io_support = 1,
Idwer Vollering06413ff2014-10-26 01:20:20 +0200105 },
106 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700107 /* MX25U12835F */
108 .id[0] = 0x2538,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700109 .nr_sectors_shift = 12,
Julius Wernerdf506222021-07-13 15:57:29 -0700110 .fast_read_dual_io_support = 1,
Kyösti Mälkki3f382c72014-11-11 15:01:31 +0200111 },
112 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700113 /* MX25U25635F */
114 .id[0] = 0x2539,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700115 .nr_sectors_shift = 13,
Julius Wernerdf506222021-07-13 15:57:29 -0700116 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +0300117 },
118 {
Julius Wernerdf506222021-07-13 15:57:29 -0700119 /* MX25U51235F */
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700120 .id[0] = 0x253a,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700121 .nr_sectors_shift = 14,
Julius Wernerdf506222021-07-13 15:57:29 -0700122 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +0300123 },
124 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700125 /* MX25L12855E */
126 .id[0] = 0x2618,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700127 .nr_sectors_shift = 12,
Julius Wernerdf506222021-07-13 15:57:29 -0700128 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +0300129 },
130 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700131 /* MX25L3235D/MX25L3225D/MX25L3236D/MX25L3237D */
132 .id[0] = 0x5e16,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700133 .nr_sectors_shift = 10,
Julius Wernerdf506222021-07-13 15:57:29 -0700134 .fast_read_dual_io_support = 1,
Mike Banon4902a802019-01-12 13:55:09 +0300135 },
136 {
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700137 /* MX25L6495F */
138 .id[0] = 0x9517,
Aaron Durbina6c73c82020-01-11 23:18:51 -0700139 .nr_sectors_shift = 11,
Idwer Vollering06413ff2014-10-26 01:20:20 +0200140 },
Ritul Guruf3e4cec2022-11-08 16:59:03 +0530141 {
142 /* MX77U25650F */
143 .id[0] = 0x7539,
144 .nr_sectors_shift = 13,
145 },
Stefan Reinauer1c56d9b2012-05-10 11:27:32 -0700146};
147
Aaron Durbin5abeb062020-01-12 15:12:18 -0700148const 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,
Aaron Durbinfc7b9532020-01-23 11:45:30 -0700152 .match_id_mask[0] = 0xffff,
Aaron Durbin5abeb062020-01-12 15:12:18 -0700153 .ids = flash_table,
154 .nr_part_ids = ARRAY_SIZE(flash_table),
155 .desc = &spi_flash_pp_0x20_sector_desc,
Furquan Shaikhe2fc5e22017-05-17 17:26:01 -0700156};