1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2005, Intec Automation Inc.
4 * Copyright (C) 2014, Freescale Semiconductor, Inc.
7 #include <linux/mtd/spi-nor.h>
11 #define WINBOND_NOR_OP_RDEAR 0xc8 /* Read Extended Address Register */
12 #define WINBOND_NOR_OP_WREAR 0xc5 /* Write Extended Address Register */
14 #define WINBOND_NOR_WREAR_OP(buf) \
15 SPI_MEM_OP(SPI_MEM_OP_CMD(WINBOND_NOR_OP_WREAR, 0), \
17 SPI_MEM_OP_NO_DUMMY, \
18 SPI_MEM_OP_DATA_OUT(1, buf, 0))
21 w25q256_post_bfpt_fixups(struct spi_nor *nor,
22 const struct sfdp_parameter_header *bfpt_header,
23 const struct sfdp_bfpt *bfpt)
26 * W25Q256JV supports 4B opcodes but W25Q256FV does not.
27 * Unfortunately, Winbond has re-used the same JEDEC ID for both
28 * variants which prevents us from defining a new entry in the parts
30 * To differentiate between W25Q256JV and W25Q256FV check SFDP header
31 * version: only JV has JESD216A compliant structure (version 5).
33 if (bfpt_header->major == SFDP_JESD216_MAJOR &&
34 bfpt_header->minor == SFDP_JESD216A_MINOR)
35 nor->flags |= SNOR_F_4B_OPCODES;
40 static const struct spi_nor_fixups w25q256_fixups = {
41 .post_bfpt = w25q256_post_bfpt_fixups,
44 static const struct flash_info winbond_nor_parts[] = {
46 .id = SNOR_ID(0xef, 0x30, 0x10),
49 .no_sfdp_flags = SECT_4K,
51 .id = SNOR_ID(0xef, 0x30, 0x11),
54 .no_sfdp_flags = SECT_4K,
56 .id = SNOR_ID(0xef, 0x30, 0x12),
59 .no_sfdp_flags = SECT_4K,
61 .id = SNOR_ID(0xef, 0x30, 0x13),
64 .no_sfdp_flags = SECT_4K,
66 .id = SNOR_ID(0xef, 0x30, 0x14),
69 .no_sfdp_flags = SECT_4K,
71 .id = SNOR_ID(0xef, 0x30, 0x15),
74 .no_sfdp_flags = SECT_4K,
76 .id = SNOR_ID(0xef, 0x30, 0x16),
79 .no_sfdp_flags = SECT_4K,
81 .id = SNOR_ID(0xef, 0x30, 0x17),
84 .no_sfdp_flags = SECT_4K,
86 .id = SNOR_ID(0xef, 0x40, 0x12),
89 .no_sfdp_flags = SECT_4K,
91 .id = SNOR_ID(0xef, 0x40, 0x14),
94 .no_sfdp_flags = SECT_4K,
96 .id = SNOR_ID(0xef, 0x40, 0x16),
99 .no_sfdp_flags = SECT_4K,
101 .id = SNOR_ID(0xef, 0x40, 0x17),
104 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
106 .id = SNOR_ID(0xef, 0x40, 0x18),
108 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
110 .id = SNOR_ID(0xef, 0x40, 0x19),
113 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
114 .fixups = &w25q256_fixups,
116 .id = SNOR_ID(0xef, 0x40, 0x20),
117 .name = "w25q512jvq",
119 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
121 .id = SNOR_ID(0xef, 0x50, 0x12),
124 .no_sfdp_flags = SECT_4K,
126 .id = SNOR_ID(0xef, 0x50, 0x14),
129 .no_sfdp_flags = SECT_4K,
131 .id = SNOR_ID(0xef, 0x60, 0x12),
134 .no_sfdp_flags = SECT_4K,
136 .id = SNOR_ID(0xef, 0x60, 0x15),
139 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
140 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
142 .id = SNOR_ID(0xef, 0x60, 0x16),
145 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
146 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
147 .otp = SNOR_OTP(256, 3, 0x1000, 0x1000),
149 .id = SNOR_ID(0xef, 0x60, 0x17),
152 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
153 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
155 .id = SNOR_ID(0xef, 0x60, 0x18),
158 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
159 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
161 .id = SNOR_ID(0xef, 0x60, 0x19),
164 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
166 .id = SNOR_ID(0xef, 0x60, 0x20),
167 .name = "w25q512nwq",
168 .otp = SNOR_OTP(256, 3, 0x1000, 0x1000),
170 .id = SNOR_ID(0xef, 0x70, 0x15),
171 .name = "w25q16jv-im/jm",
173 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
174 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
176 .id = SNOR_ID(0xef, 0x70, 0x16),
179 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
180 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
182 .id = SNOR_ID(0xef, 0x70, 0x17),
185 .no_sfdp_flags = SECT_4K,
187 .id = SNOR_ID(0xef, 0x70, 0x18),
190 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
191 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
193 .id = SNOR_ID(0xef, 0x70, 0x19),
194 .name = "w25q256jvm",
196 .id = SNOR_ID(0xef, 0x71, 0x19),
199 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
201 .id = SNOR_ID(0xef, 0x80, 0x16),
204 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
205 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
206 .otp = SNOR_OTP(256, 3, 0x1000, 0x1000),
208 .id = SNOR_ID(0xef, 0x80, 0x17),
211 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
212 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
214 .id = SNOR_ID(0xef, 0x80, 0x18),
215 .name = "w25q128jwm",
217 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
218 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
220 .id = SNOR_ID(0xef, 0x80, 0x19),
221 .name = "w25q256jwm",
223 .flags = SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB,
224 .no_sfdp_flags = SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ,
226 .id = SNOR_ID(0xef, 0x80, 0x20),
227 .name = "w25q512nwm",
228 .otp = SNOR_OTP(256, 3, 0x1000, 0x1000),
233 * winbond_nor_write_ear() - Write Extended Address Register.
234 * @nor: pointer to 'struct spi_nor'.
235 * @ear: value to write to the Extended Address Register.
237 * Return: 0 on success, -errno otherwise.
239 static int winbond_nor_write_ear(struct spi_nor *nor, u8 ear)
243 nor->bouncebuf[0] = ear;
246 struct spi_mem_op op = WINBOND_NOR_WREAR_OP(nor->bouncebuf);
248 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
250 ret = spi_mem_exec_op(nor->spimem, &op);
252 ret = spi_nor_controller_ops_write_reg(nor,
253 WINBOND_NOR_OP_WREAR,
258 dev_dbg(nor->dev, "error %d writing EAR\n", ret);
264 * winbond_nor_set_4byte_addr_mode() - Set 4-byte address mode for Winbond
266 * @nor: pointer to 'struct spi_nor'.
267 * @enable: true to enter the 4-byte address mode, false to exit the 4-byte
270 * Return: 0 on success, -errno otherwise.
272 static int winbond_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)
276 ret = spi_nor_set_4byte_addr_mode_en4b_ex4b(nor, enable);
281 * On Winbond W25Q256FV, leaving 4byte mode causes the Extended Address
282 * Register to be set to 1, so all 3-byte-address reads come from the
283 * second 16M. We must clear the register to enable normal behavior.
285 ret = spi_nor_write_enable(nor);
289 ret = winbond_nor_write_ear(nor, 0);
293 return spi_nor_write_disable(nor);
296 static const struct spi_nor_otp_ops winbond_nor_otp_ops = {
297 .read = spi_nor_otp_read_secr,
298 .write = spi_nor_otp_write_secr,
299 .erase = spi_nor_otp_erase_secr,
300 .lock = spi_nor_otp_lock_sr2,
301 .is_locked = spi_nor_otp_is_locked_sr2,
304 static int winbond_nor_late_init(struct spi_nor *nor)
306 struct spi_nor_flash_parameter *params = nor->params;
309 params->otp.ops = &winbond_nor_otp_ops;
312 * Winbond seems to require that the Extended Address Register to be set
313 * to zero when exiting the 4-Byte Address Mode, at least for W25Q256FV.
314 * This requirement is not described in the JESD216 SFDP standard, thus
315 * it is Winbond specific. Since we do not know if other Winbond flashes
316 * have the same requirement, play safe and overwrite the method parsed
319 params->set_4byte_addr_mode = winbond_nor_set_4byte_addr_mode;
324 static const struct spi_nor_fixups winbond_nor_fixups = {
325 .late_init = winbond_nor_late_init,
328 const struct spi_nor_manufacturer spi_nor_winbond = {
330 .parts = winbond_nor_parts,
331 .nparts = ARRAY_SIZE(winbond_nor_parts),
332 .fixups = &winbond_nor_fixups,