1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2005, Intec Automation Inc.
4 * Copyright (C) 2014, Freescale Semiconductor, Inc.
7 #include <linux/bitfield.h>
8 #include <linux/device.h>
9 #include <linux/errno.h>
10 #include <linux/mtd/spi-nor.h>
14 /* flash_info mfr_flag. Used to clear sticky prorietary SR bits. */
15 #define USE_CLSR BIT(0)
16 #define USE_CLPEF BIT(1)
18 #define SPINOR_OP_CLSR 0x30 /* Clear status register 1 */
19 #define SPINOR_OP_CLPEF 0x82 /* Clear program/erase failure flags */
20 #define SPINOR_OP_CYPRESS_DIE_ERASE 0x61 /* Chip (die) erase */
21 #define SPINOR_OP_RD_ANY_REG 0x65 /* Read any register */
22 #define SPINOR_OP_WR_ANY_REG 0x71 /* Write any register */
23 #define SPINOR_REG_CYPRESS_VREG 0x00800000
24 #define SPINOR_REG_CYPRESS_STR1 0x0
25 #define SPINOR_REG_CYPRESS_STR1V \
26 (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_STR1)
27 #define SPINOR_REG_CYPRESS_CFR1 0x2
28 #define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1) /* Quad Enable */
29 #define SPINOR_REG_CYPRESS_CFR2 0x3
30 #define SPINOR_REG_CYPRESS_CFR2V \
31 (SPINOR_REG_CYPRESS_VREG + SPINOR_REG_CYPRESS_CFR2)
32 #define SPINOR_REG_CYPRESS_CFR2_MEMLAT_MASK GENMASK(3, 0)
33 #define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb
34 #define SPINOR_REG_CYPRESS_CFR2_ADRBYT BIT(7)
35 #define SPINOR_REG_CYPRESS_CFR3 0x4
36 #define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4) /* Page size. */
37 #define SPINOR_REG_CYPRESS_CFR5 0x6
38 #define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6)
39 #define SPINOR_REG_CYPRESS_CFR5_DDR BIT(1)
40 #define SPINOR_REG_CYPRESS_CFR5_OPI BIT(0)
41 #define SPINOR_REG_CYPRESS_CFR5_OCT_DTR_EN \
42 (SPINOR_REG_CYPRESS_CFR5_BIT6 | SPINOR_REG_CYPRESS_CFR5_DDR | \
43 SPINOR_REG_CYPRESS_CFR5_OPI)
44 #define SPINOR_REG_CYPRESS_CFR5_OCT_DTR_DS SPINOR_REG_CYPRESS_CFR5_BIT6
45 #define SPINOR_OP_CYPRESS_RD_FAST 0xee
46 #define SPINOR_REG_CYPRESS_ARCFN 0x00000006
48 /* Cypress SPI NOR flash operations. */
49 #define CYPRESS_NOR_WR_ANY_REG_OP(naddr, addr, ndata, buf) \
50 SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_WR_ANY_REG, 0), \
51 SPI_MEM_OP_ADDR(naddr, addr, 0), \
52 SPI_MEM_OP_NO_DUMMY, \
53 SPI_MEM_OP_DATA_OUT(ndata, buf, 0))
55 #define CYPRESS_NOR_RD_ANY_REG_OP(naddr, addr, ndummy, buf) \
56 SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RD_ANY_REG, 0), \
57 SPI_MEM_OP_ADDR(naddr, addr, 0), \
58 SPI_MEM_OP_DUMMY(ndummy, 0), \
59 SPI_MEM_OP_DATA_IN(1, buf, 0))
61 #define SPANSION_OP(opcode) \
62 SPI_MEM_OP(SPI_MEM_OP_CMD(opcode, 0), \
64 SPI_MEM_OP_NO_DUMMY, \
68 * struct spansion_nor_params - Spansion private parameters.
69 * @clsr: Clear Status Register or Clear Program and Erase Failure Flag
72 struct spansion_nor_params
{
77 * spansion_nor_clear_sr() - Clear the Status Register.
78 * @nor: pointer to 'struct spi_nor'.
80 static void spansion_nor_clear_sr(struct spi_nor
*nor
)
82 const struct spansion_nor_params
*priv_params
= nor
->params
->priv
;
86 struct spi_mem_op op
= SPANSION_OP(priv_params
->clsr
);
88 spi_nor_spimem_setup_op(nor
, &op
, nor
->reg_proto
);
90 ret
= spi_mem_exec_op(nor
->spimem
, &op
);
92 ret
= spi_nor_controller_ops_write_reg(nor
, SPINOR_OP_CLSR
,
97 dev_dbg(nor
->dev
, "error %d clearing SR\n", ret
);
100 static int cypress_nor_sr_ready_and_clear_reg(struct spi_nor
*nor
, u64 addr
)
102 struct spi_nor_flash_parameter
*params
= nor
->params
;
103 struct spi_mem_op op
=
104 CYPRESS_NOR_RD_ANY_REG_OP(params
->addr_mode_nbytes
, addr
,
108 if (nor
->reg_proto
== SNOR_PROTO_8_8_8_DTR
) {
109 op
.addr
.nbytes
= nor
->addr_nbytes
;
110 op
.dummy
.nbytes
= params
->rdsr_dummy
;
114 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
118 if (nor
->bouncebuf
[0] & (SR_E_ERR
| SR_P_ERR
)) {
119 if (nor
->bouncebuf
[0] & SR_E_ERR
)
120 dev_err(nor
->dev
, "Erase Error occurred\n");
122 dev_err(nor
->dev
, "Programming Error occurred\n");
124 spansion_nor_clear_sr(nor
);
126 ret
= spi_nor_write_disable(nor
);
133 return !(nor
->bouncebuf
[0] & SR_WIP
);
136 * cypress_nor_sr_ready_and_clear() - Query the Status Register of each die by
137 * using Read Any Register command to see if the whole flash is ready for new
138 * commands and clear it if there are any errors.
139 * @nor: pointer to 'struct spi_nor'.
141 * Return: 1 if ready, 0 if not ready, -errno on errors.
143 static int cypress_nor_sr_ready_and_clear(struct spi_nor
*nor
)
145 struct spi_nor_flash_parameter
*params
= nor
->params
;
150 for (i
= 0; i
< params
->n_dice
; i
++) {
151 addr
= params
->vreg_offset
[i
] + SPINOR_REG_CYPRESS_STR1
;
152 ret
= cypress_nor_sr_ready_and_clear_reg(nor
, addr
);
162 static int cypress_nor_set_memlat(struct spi_nor
*nor
, u64 addr
)
164 struct spi_mem_op op
;
165 u8
*buf
= nor
->bouncebuf
;
167 u8 addr_mode_nbytes
= nor
->params
->addr_mode_nbytes
;
169 op
= (struct spi_mem_op
)
170 CYPRESS_NOR_RD_ANY_REG_OP(addr_mode_nbytes
, addr
, 0, buf
);
172 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
176 /* Use 24 dummy cycles for memory array reads. */
177 *buf
&= ~SPINOR_REG_CYPRESS_CFR2_MEMLAT_MASK
;
178 *buf
|= FIELD_PREP(SPINOR_REG_CYPRESS_CFR2_MEMLAT_MASK
,
179 SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24
);
180 op
= (struct spi_mem_op
)
181 CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes
, addr
, 1, buf
);
183 ret
= spi_nor_write_any_volatile_reg(nor
, &op
, nor
->reg_proto
);
187 nor
->read_dummy
= 24;
192 static int cypress_nor_set_octal_dtr_bits(struct spi_nor
*nor
, u64 addr
)
194 struct spi_mem_op op
;
195 u8
*buf
= nor
->bouncebuf
;
197 /* Set the octal and DTR enable bits. */
198 buf
[0] = SPINOR_REG_CYPRESS_CFR5_OCT_DTR_EN
;
199 op
= (struct spi_mem_op
)
200 CYPRESS_NOR_WR_ANY_REG_OP(nor
->params
->addr_mode_nbytes
,
203 return spi_nor_write_any_volatile_reg(nor
, &op
, nor
->reg_proto
);
206 static int cypress_nor_octal_dtr_en(struct spi_nor
*nor
)
208 const struct spi_nor_flash_parameter
*params
= nor
->params
;
209 u8
*buf
= nor
->bouncebuf
;
213 for (i
= 0; i
< params
->n_dice
; i
++) {
214 addr
= params
->vreg_offset
[i
] + SPINOR_REG_CYPRESS_CFR2
;
215 ret
= cypress_nor_set_memlat(nor
, addr
);
219 addr
= params
->vreg_offset
[i
] + SPINOR_REG_CYPRESS_CFR5
;
220 ret
= cypress_nor_set_octal_dtr_bits(nor
, addr
);
225 /* Read flash ID to make sure the switch was successful. */
226 ret
= spi_nor_read_id(nor
, nor
->addr_nbytes
, 3, buf
,
227 SNOR_PROTO_8_8_8_DTR
);
229 dev_dbg(nor
->dev
, "error %d reading JEDEC ID after enabling 8D-8D-8D mode\n", ret
);
233 if (memcmp(buf
, nor
->info
->id
->bytes
, nor
->info
->id
->len
))
239 static int cypress_nor_set_single_spi_bits(struct spi_nor
*nor
, u64 addr
)
241 struct spi_mem_op op
;
242 u8
*buf
= nor
->bouncebuf
;
245 * The register is 1-byte wide, but 1-byte transactions are not allowed
246 * in 8D-8D-8D mode. Since there is no register at the next location,
247 * just initialize the value to 0 and let the transaction go on.
249 buf
[0] = SPINOR_REG_CYPRESS_CFR5_OCT_DTR_DS
;
251 op
= (struct spi_mem_op
)
252 CYPRESS_NOR_WR_ANY_REG_OP(nor
->addr_nbytes
, addr
, 2, buf
);
253 return spi_nor_write_any_volatile_reg(nor
, &op
, SNOR_PROTO_8_8_8_DTR
);
256 static int cypress_nor_octal_dtr_dis(struct spi_nor
*nor
)
258 const struct spi_nor_flash_parameter
*params
= nor
->params
;
259 u8
*buf
= nor
->bouncebuf
;
263 for (i
= 0; i
< params
->n_dice
; i
++) {
264 addr
= params
->vreg_offset
[i
] + SPINOR_REG_CYPRESS_CFR5
;
265 ret
= cypress_nor_set_single_spi_bits(nor
, addr
);
270 /* Read flash ID to make sure the switch was successful. */
271 ret
= spi_nor_read_id(nor
, 0, 0, buf
, SNOR_PROTO_1_1_1
);
273 dev_dbg(nor
->dev
, "error %d reading JEDEC ID after disabling 8D-8D-8D mode\n", ret
);
277 if (memcmp(buf
, nor
->info
->id
->bytes
, nor
->info
->id
->len
))
283 static int cypress_nor_quad_enable_volatile_reg(struct spi_nor
*nor
, u64 addr
)
285 struct spi_mem_op op
;
286 u8 addr_mode_nbytes
= nor
->params
->addr_mode_nbytes
;
290 op
= (struct spi_mem_op
)
291 CYPRESS_NOR_RD_ANY_REG_OP(addr_mode_nbytes
, addr
, 0,
294 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
298 if (nor
->bouncebuf
[0] & SPINOR_REG_CYPRESS_CFR1_QUAD_EN
)
301 /* Update the Quad Enable bit. */
302 nor
->bouncebuf
[0] |= SPINOR_REG_CYPRESS_CFR1_QUAD_EN
;
303 op
= (struct spi_mem_op
)
304 CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes
, addr
, 1,
306 ret
= spi_nor_write_any_volatile_reg(nor
, &op
, nor
->reg_proto
);
310 cfr1v_written
= nor
->bouncebuf
[0];
312 /* Read back and check it. */
313 op
= (struct spi_mem_op
)
314 CYPRESS_NOR_RD_ANY_REG_OP(addr_mode_nbytes
, addr
, 0,
316 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
320 if (nor
->bouncebuf
[0] != cfr1v_written
) {
321 dev_err(nor
->dev
, "CFR1: Read back test failed\n");
329 * cypress_nor_quad_enable_volatile() - enable Quad I/O mode in volatile
331 * @nor: pointer to a 'struct spi_nor'
333 * It is recommended to update volatile registers in the field application due
334 * to a risk of the non-volatile registers corruption by power interrupt. This
335 * function sets Quad Enable bit in CFR1 volatile. If users set the Quad Enable
336 * bit in the CFR1 non-volatile in advance (typically by a Flash programmer
337 * before mounting Flash on PCB), the Quad Enable bit in the CFR1 volatile is
338 * also set during Flash power-up.
340 * Return: 0 on success, -errno otherwise.
342 static int cypress_nor_quad_enable_volatile(struct spi_nor
*nor
)
344 struct spi_nor_flash_parameter
*params
= nor
->params
;
349 for (i
= 0; i
< params
->n_dice
; i
++) {
350 addr
= params
->vreg_offset
[i
] + SPINOR_REG_CYPRESS_CFR1
;
351 ret
= cypress_nor_quad_enable_volatile_reg(nor
, addr
);
360 * cypress_nor_determine_addr_mode_by_sr1() - Determine current address mode
361 * (3 or 4-byte) by querying status
363 * @nor: pointer to a 'struct spi_nor'
364 * @addr_mode: ponter to a buffer where we return the determined
367 * This function tries to determine current address mode by comparing SR1 value
368 * from RDSR1(no address), RDAR(3-byte address), and RDAR(4-byte address).
370 * Return: 0 on success, -errno otherwise.
372 static int cypress_nor_determine_addr_mode_by_sr1(struct spi_nor
*nor
,
375 struct spi_mem_op op
=
376 CYPRESS_NOR_RD_ANY_REG_OP(3, SPINOR_REG_CYPRESS_STR1V
, 0,
378 bool is3byte
, is4byte
;
381 ret
= spi_nor_read_sr(nor
, &nor
->bouncebuf
[1]);
385 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
389 is3byte
= (nor
->bouncebuf
[0] == nor
->bouncebuf
[1]);
391 op
= (struct spi_mem_op
)
392 CYPRESS_NOR_RD_ANY_REG_OP(4, SPINOR_REG_CYPRESS_STR1V
, 0,
394 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
398 is4byte
= (nor
->bouncebuf
[0] == nor
->bouncebuf
[1]);
400 if (is3byte
== is4byte
)
411 * cypress_nor_set_addr_mode_nbytes() - Set the number of address bytes mode of
412 * current address mode.
413 * @nor: pointer to a 'struct spi_nor'
415 * Determine current address mode by reading SR1 with different methods, then
416 * query CFR2V[7] to confirm. If determination is failed, force enter to 4-byte
419 * Return: 0 on success, -errno otherwise.
421 static int cypress_nor_set_addr_mode_nbytes(struct spi_nor
*nor
)
423 struct spi_mem_op op
;
428 * Read SR1 by RDSR1 and RDAR(3- AND 4-byte addr). Use write enable
429 * that sets bit-1 in SR1.
431 ret
= spi_nor_write_enable(nor
);
434 ret
= cypress_nor_determine_addr_mode_by_sr1(nor
, &addr_mode
);
436 ret
= spi_nor_set_4byte_addr_mode(nor
, true);
439 return spi_nor_write_disable(nor
);
441 ret
= spi_nor_write_disable(nor
);
446 * Query CFR2V and make sure no contradiction between determined address
449 op
= (struct spi_mem_op
)
450 CYPRESS_NOR_RD_ANY_REG_OP(addr_mode
, SPINOR_REG_CYPRESS_CFR2V
,
452 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
456 if (nor
->bouncebuf
[0] & SPINOR_REG_CYPRESS_CFR2_ADRBYT
) {
458 return spi_nor_set_4byte_addr_mode(nor
, true);
461 return spi_nor_set_4byte_addr_mode(nor
, true);
464 nor
->params
->addr_nbytes
= addr_mode
;
465 nor
->params
->addr_mode_nbytes
= addr_mode
;
471 * cypress_nor_get_page_size() - Get flash page size configuration.
472 * @nor: pointer to a 'struct spi_nor'
474 * The BFPT table advertises a 512B or 256B page size depending on part but the
475 * page size is actually configurable (with the default being 256B). Read from
476 * CFR3V[4] and set the correct size.
478 * Return: 0 on success, -errno otherwise.
480 static int cypress_nor_get_page_size(struct spi_nor
*nor
)
482 struct spi_mem_op op
=
483 CYPRESS_NOR_RD_ANY_REG_OP(nor
->params
->addr_mode_nbytes
,
484 0, 0, nor
->bouncebuf
);
485 struct spi_nor_flash_parameter
*params
= nor
->params
;
490 * Use the minimum common page size configuration. Programming 256-byte
491 * under 512-byte page size configuration is safe.
493 params
->page_size
= 256;
494 for (i
= 0; i
< params
->n_dice
; i
++) {
495 op
.addr
.val
= params
->vreg_offset
[i
] + SPINOR_REG_CYPRESS_CFR3
;
497 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
501 if (!(nor
->bouncebuf
[0] & SPINOR_REG_CYPRESS_CFR3_PGSZ
))
505 params
->page_size
= 512;
510 static void cypress_nor_ecc_init(struct spi_nor
*nor
)
513 * Programming is supported only in 16-byte ECC data unit granularity.
514 * Byte-programming, bit-walking, or multiple program operations to the
515 * same ECC data unit without an erase are not allowed.
517 nor
->params
->writesize
= 16;
518 nor
->flags
|= SNOR_F_ECC
;
522 s25fs256t_post_bfpt_fixup(struct spi_nor
*nor
,
523 const struct sfdp_parameter_header
*bfpt_header
,
524 const struct sfdp_bfpt
*bfpt
)
526 struct spi_mem_op op
;
529 ret
= cypress_nor_set_addr_mode_nbytes(nor
);
533 /* Read Architecture Configuration Register (ARCFN) */
534 op
= (struct spi_mem_op
)
535 CYPRESS_NOR_RD_ANY_REG_OP(nor
->params
->addr_mode_nbytes
,
536 SPINOR_REG_CYPRESS_ARCFN
, 1,
538 ret
= spi_nor_read_any_reg(nor
, &op
, nor
->reg_proto
);
542 /* ARCFN value must be 0 if uniform sector is selected */
543 if (nor
->bouncebuf
[0])
549 static int s25fs256t_post_sfdp_fixup(struct spi_nor
*nor
)
551 struct spi_nor_flash_parameter
*params
= nor
->params
;
554 * S25FS256T does not define the SCCR map, but we would like to use the
555 * same code base for both single and multi chip package devices, thus
556 * set the vreg_offset and n_dice to be able to do so.
558 params
->vreg_offset
= devm_kmalloc(nor
->dev
, sizeof(u32
), GFP_KERNEL
);
559 if (!params
->vreg_offset
)
562 params
->vreg_offset
[0] = SPINOR_REG_CYPRESS_VREG
;
565 /* PP_1_1_4_4B is supported but missing in 4BAIT. */
566 params
->hwcaps
.mask
|= SNOR_HWCAPS_PP_1_1_4
;
567 spi_nor_set_pp_settings(¶ms
->page_programs
[SNOR_CMD_PP_1_1_4
],
568 SPINOR_OP_PP_1_1_4_4B
,
571 return cypress_nor_get_page_size(nor
);
574 static int s25fs256t_late_init(struct spi_nor
*nor
)
576 cypress_nor_ecc_init(nor
);
581 static struct spi_nor_fixups s25fs256t_fixups
= {
582 .post_bfpt
= s25fs256t_post_bfpt_fixup
,
583 .post_sfdp
= s25fs256t_post_sfdp_fixup
,
584 .late_init
= s25fs256t_late_init
,
588 s25hx_t_post_bfpt_fixup(struct spi_nor
*nor
,
589 const struct sfdp_parameter_header
*bfpt_header
,
590 const struct sfdp_bfpt
*bfpt
)
594 ret
= cypress_nor_set_addr_mode_nbytes(nor
);
598 /* Replace Quad Enable with volatile version */
599 nor
->params
->quad_enable
= cypress_nor_quad_enable_volatile
;
604 static int s25hx_t_post_sfdp_fixup(struct spi_nor
*nor
)
606 struct spi_nor_flash_parameter
*params
= nor
->params
;
607 struct spi_nor_erase_type
*erase_type
= params
->erase_map
.erase_type
;
610 if (!params
->n_dice
|| !params
->vreg_offset
) {
611 dev_err(nor
->dev
, "%s failed. The volatile register offset could not be retrieved from SFDP.\n",
616 /* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */
617 if (params
->size
== SZ_256M
)
621 * In some parts, 3byte erase opcodes are advertised by 4BAIT.
622 * Convert them to 4byte erase opcodes.
624 for (i
= 0; i
< SNOR_ERASE_TYPE_MAX
; i
++) {
625 switch (erase_type
[i
].opcode
) {
627 erase_type
[i
].opcode
= SPINOR_OP_SE_4B
;
629 case SPINOR_OP_BE_4K
:
630 erase_type
[i
].opcode
= SPINOR_OP_BE_4K_4B
;
637 return cypress_nor_get_page_size(nor
);
640 static int s25hx_t_late_init(struct spi_nor
*nor
)
642 struct spi_nor_flash_parameter
*params
= nor
->params
;
644 /* Fast Read 4B requires mode cycles */
645 params
->reads
[SNOR_CMD_READ_FAST
].num_mode_clocks
= 8;
646 params
->ready
= cypress_nor_sr_ready_and_clear
;
647 cypress_nor_ecc_init(nor
);
649 params
->die_erase_opcode
= SPINOR_OP_CYPRESS_DIE_ERASE
;
653 static struct spi_nor_fixups s25hx_t_fixups
= {
654 .post_bfpt
= s25hx_t_post_bfpt_fixup
,
655 .post_sfdp
= s25hx_t_post_sfdp_fixup
,
656 .late_init
= s25hx_t_late_init
,
660 * cypress_nor_set_octal_dtr() - Enable or disable octal DTR on Cypress flashes.
661 * @nor: pointer to a 'struct spi_nor'
662 * @enable: whether to enable or disable Octal DTR
664 * This also sets the memory access latency cycles to 24 to allow the flash to
665 * run at up to 200MHz.
667 * Return: 0 on success, -errno otherwise.
669 static int cypress_nor_set_octal_dtr(struct spi_nor
*nor
, bool enable
)
671 return enable
? cypress_nor_octal_dtr_en(nor
) :
672 cypress_nor_octal_dtr_dis(nor
);
675 static int s28hx_t_post_sfdp_fixup(struct spi_nor
*nor
)
677 struct spi_nor_flash_parameter
*params
= nor
->params
;
679 if (!params
->n_dice
|| !params
->vreg_offset
) {
680 dev_err(nor
->dev
, "%s failed. The volatile register offset could not be retrieved from SFDP.\n",
685 /* The 2 Gb parts duplicate info and advertise 4 dice instead of 2. */
686 if (params
->size
== SZ_256M
)
690 * On older versions of the flash the xSPI Profile 1.0 table has the
691 * 8D-8D-8D Fast Read opcode as 0x00. But it actually should be 0xEE.
693 if (params
->reads
[SNOR_CMD_READ_8_8_8_DTR
].opcode
== 0)
694 params
->reads
[SNOR_CMD_READ_8_8_8_DTR
].opcode
=
695 SPINOR_OP_CYPRESS_RD_FAST
;
697 /* This flash is also missing the 4-byte Page Program opcode bit. */
698 spi_nor_set_pp_settings(¶ms
->page_programs
[SNOR_CMD_PP
],
699 SPINOR_OP_PP_4B
, SNOR_PROTO_1_1_1
);
701 * Since xSPI Page Program opcode is backward compatible with
702 * Legacy SPI, use Legacy SPI opcode there as well.
704 spi_nor_set_pp_settings(¶ms
->page_programs
[SNOR_CMD_PP_8_8_8_DTR
],
705 SPINOR_OP_PP_4B
, SNOR_PROTO_8_8_8_DTR
);
708 * The xSPI Profile 1.0 table advertises the number of additional
709 * address bytes needed for Read Status Register command as 0 but the
710 * actual value for that is 4.
712 params
->rdsr_addr_nbytes
= 4;
714 return cypress_nor_get_page_size(nor
);
717 static int s28hx_t_post_bfpt_fixup(struct spi_nor
*nor
,
718 const struct sfdp_parameter_header
*bfpt_header
,
719 const struct sfdp_bfpt
*bfpt
)
721 return cypress_nor_set_addr_mode_nbytes(nor
);
724 static int s28hx_t_late_init(struct spi_nor
*nor
)
726 struct spi_nor_flash_parameter
*params
= nor
->params
;
728 params
->set_octal_dtr
= cypress_nor_set_octal_dtr
;
729 params
->ready
= cypress_nor_sr_ready_and_clear
;
730 cypress_nor_ecc_init(nor
);
735 static const struct spi_nor_fixups s28hx_t_fixups
= {
736 .post_sfdp
= s28hx_t_post_sfdp_fixup
,
737 .post_bfpt
= s28hx_t_post_bfpt_fixup
,
738 .late_init
= s28hx_t_late_init
,
742 s25fs_s_nor_post_bfpt_fixups(struct spi_nor
*nor
,
743 const struct sfdp_parameter_header
*bfpt_header
,
744 const struct sfdp_bfpt
*bfpt
)
747 * The S25FS-S chip family reports 512-byte pages in BFPT but
748 * in reality the write buffer still wraps at the safe default
749 * of 256 bytes. Overwrite the page size advertised by BFPT
750 * to get the writes working.
752 nor
->params
->page_size
= 256;
757 static const struct spi_nor_fixups s25fs_s_nor_fixups
= {
758 .post_bfpt
= s25fs_s_nor_post_bfpt_fixups
,
761 static const struct flash_info spansion_nor_parts
[] = {
763 .id
= SNOR_ID(0x01, 0x02, 0x12),
767 .id
= SNOR_ID(0x01, 0x02, 0x13),
771 .id
= SNOR_ID(0x01, 0x02, 0x14),
775 .id
= SNOR_ID(0x01, 0x02, 0x15, 0x4d, 0x00),
778 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
780 .id
= SNOR_ID(0x01, 0x02, 0x15),
784 .id
= SNOR_ID(0x01, 0x02, 0x16, 0x4d, 0x00),
787 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
789 .id
= SNOR_ID(0x01, 0x02, 0x16),
793 .id
= SNOR_ID(0x01, 0x02, 0x19, 0x4d, 0x00, 0x80),
794 .name
= "s25fl256s0",
796 .sector_size
= SZ_256K
,
797 .no_sfdp_flags
= SPI_NOR_SKIP_SFDP
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
798 .mfr_flags
= USE_CLSR
,
800 .id
= SNOR_ID(0x01, 0x02, 0x19, 0x4d, 0x00, 0x81),
801 .name
= "s25fs256s0",
803 .sector_size
= SZ_256K
,
804 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
805 .mfr_flags
= USE_CLSR
,
807 .id
= SNOR_ID(0x01, 0x02, 0x19, 0x4d, 0x01, 0x80),
808 .name
= "s25fl256s1",
810 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
811 .mfr_flags
= USE_CLSR
,
813 .id
= SNOR_ID(0x01, 0x02, 0x19, 0x4d, 0x01, 0x81),
814 .name
= "s25fs256s1",
816 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
817 .mfr_flags
= USE_CLSR
,
819 .id
= SNOR_ID(0x01, 0x02, 0x20, 0x4d, 0x00, 0x80),
822 .sector_size
= SZ_256K
,
823 .flags
= SPI_NOR_HAS_LOCK
,
824 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
825 .mfr_flags
= USE_CLSR
,
827 .id
= SNOR_ID(0x01, 0x02, 0x20, 0x4d, 0x00, 0x81),
830 .sector_size
= SZ_256K
,
831 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
832 .mfr_flags
= USE_CLSR
,
833 .fixups
= &s25fs_s_nor_fixups
,
835 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x03, 0x00),
836 .name
= "s25sl12800",
838 .sector_size
= SZ_256K
,
840 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x03, 0x01),
841 .name
= "s25sl12801",
844 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x4d, 0x00, 0x80),
845 .name
= "s25fl128s0",
847 .sector_size
= SZ_256K
,
848 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
849 .mfr_flags
= USE_CLSR
,
851 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x4d, 0x00),
852 .name
= "s25fl129p0",
854 .sector_size
= SZ_256K
,
855 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
856 .mfr_flags
= USE_CLSR
,
858 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x4d, 0x01, 0x80),
859 .name
= "s25fl128s1",
861 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
862 .mfr_flags
= USE_CLSR
,
864 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x4d, 0x01, 0x81),
865 .name
= "s25fs128s1",
867 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
868 .mfr_flags
= USE_CLSR
,
869 .fixups
= &s25fs_s_nor_fixups
,
871 .id
= SNOR_ID(0x01, 0x20, 0x18, 0x4d, 0x01),
872 .name
= "s25fl129p1",
874 .no_sfdp_flags
= SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
875 .mfr_flags
= USE_CLSR
,
877 .id
= SNOR_ID(0x01, 0x40, 0x13),
880 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
,
882 .id
= SNOR_ID(0x01, 0x40, 0x14),
885 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
,
887 .id
= SNOR_ID(0x01, 0x40, 0x15),
890 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
892 .id
= SNOR_ID(0x01, 0x40, 0x16),
895 .no_sfdp_flags
= SECT_4K
,
897 .id
= SNOR_ID(0x01, 0x40, 0x17),
900 .no_sfdp_flags
= SECT_4K
,
902 .id
= SNOR_ID(0x01, 0x60, 0x17),
905 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
906 .fixup_flags
= SPI_NOR_4B_OPCODES
,
908 .id
= SNOR_ID(0x01, 0x60, 0x18),
911 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
912 .fixup_flags
= SPI_NOR_4B_OPCODES
,
914 .id
= SNOR_ID(0x01, 0x60, 0x19),
917 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
918 .fixup_flags
= SPI_NOR_4B_OPCODES
,
920 .id
= SNOR_ID(0x04, 0x2c, 0xc2, 0x7f, 0x7f, 0x7f),
923 .sector_size
= SZ_512K
,
924 .flags
= SPI_NOR_NO_ERASE
,
926 .id
= SNOR_ID(0x34, 0x2a, 0x1a, 0x0f, 0x03, 0x90),
928 .mfr_flags
= USE_CLPEF
,
929 .fixups
= &s25hx_t_fixups
931 .id
= SNOR_ID(0x34, 0x2a, 0x1b, 0x0f, 0x03, 0x90),
933 .mfr_flags
= USE_CLPEF
,
934 .fixups
= &s25hx_t_fixups
936 .id
= SNOR_ID(0x34, 0x2a, 0x1c, 0x0f, 0x00, 0x90),
938 .mfr_flags
= USE_CLPEF
,
939 .fixups
= &s25hx_t_fixups
941 .id
= SNOR_ID(0x34, 0x2b, 0x19, 0x0f, 0x08, 0x90),
943 .mfr_flags
= USE_CLPEF
,
944 .fixups
= &s25fs256t_fixups
946 .id
= SNOR_ID(0x34, 0x2b, 0x1a, 0x0f, 0x03, 0x90),
948 .mfr_flags
= USE_CLPEF
,
949 .fixups
= &s25hx_t_fixups
951 .id
= SNOR_ID(0x34, 0x2b, 0x1b, 0x0f, 0x03, 0x90),
953 .mfr_flags
= USE_CLPEF
,
954 .fixups
= &s25hx_t_fixups
956 .id
= SNOR_ID(0x34, 0x2b, 0x1c, 0x0f, 0x00, 0x90),
958 .mfr_flags
= USE_CLPEF
,
959 .fixups
= &s25hx_t_fixups
961 .id
= SNOR_ID(0x34, 0x5a, 0x1a),
963 .mfr_flags
= USE_CLPEF
,
964 .fixups
= &s28hx_t_fixups
,
966 .id
= SNOR_ID(0x34, 0x5a, 0x1b),
968 .mfr_flags
= USE_CLPEF
,
969 .fixups
= &s28hx_t_fixups
,
971 .id
= SNOR_ID(0x34, 0x5b, 0x19),
972 .mfr_flags
= USE_CLPEF
,
973 .fixups
= &s28hx_t_fixups
,
975 .id
= SNOR_ID(0x34, 0x5b, 0x1a),
977 .mfr_flags
= USE_CLPEF
,
978 .fixups
= &s28hx_t_fixups
,
980 .id
= SNOR_ID(0x34, 0x5b, 0x1b),
982 .mfr_flags
= USE_CLPEF
,
983 .fixups
= &s28hx_t_fixups
,
985 .id
= SNOR_ID(0x34, 0x5b, 0x1c),
987 .mfr_flags
= USE_CLPEF
,
988 .fixups
= &s28hx_t_fixups
,
990 .id
= SNOR_ID(0xef, 0x40, 0x13),
993 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
995 .id
= SNOR_ID(0xef, 0x40, 0x14),
998 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
1000 .id
= SNOR_ID(0xef, 0x40, 0x15),
1001 .name
= "s25fl016k",
1003 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
1005 .id
= SNOR_ID(0xef, 0x40, 0x17),
1006 .name
= "s25fl064k",
1008 .no_sfdp_flags
= SECT_4K
| SPI_NOR_DUAL_READ
| SPI_NOR_QUAD_READ
,
1013 * spansion_nor_sr_ready_and_clear() - Query the Status Register to see if the
1014 * flash is ready for new commands and clear it if there are any errors.
1015 * @nor: pointer to 'struct spi_nor'.
1017 * Return: 1 if ready, 0 if not ready, -errno on errors.
1019 static int spansion_nor_sr_ready_and_clear(struct spi_nor
*nor
)
1023 ret
= spi_nor_read_sr(nor
, nor
->bouncebuf
);
1027 if (nor
->bouncebuf
[0] & (SR_E_ERR
| SR_P_ERR
)) {
1028 if (nor
->bouncebuf
[0] & SR_E_ERR
)
1029 dev_err(nor
->dev
, "Erase Error occurred\n");
1031 dev_err(nor
->dev
, "Programming Error occurred\n");
1033 spansion_nor_clear_sr(nor
);
1036 * WEL bit remains set to one when an erase or page program
1037 * error occurs. Issue a Write Disable command to protect
1038 * against inadvertent writes that can possibly corrupt the
1039 * contents of the memory.
1041 ret
= spi_nor_write_disable(nor
);
1048 return !(nor
->bouncebuf
[0] & SR_WIP
);
1051 static int spansion_nor_late_init(struct spi_nor
*nor
)
1053 struct spi_nor_flash_parameter
*params
= nor
->params
;
1054 struct spansion_nor_params
*priv_params
;
1055 u8 mfr_flags
= nor
->info
->mfr_flags
;
1057 if (params
->size
> SZ_16M
) {
1058 nor
->flags
|= SNOR_F_4B_OPCODES
;
1059 /* No small sector erase for 4-byte command set */
1060 nor
->erase_opcode
= SPINOR_OP_SE
;
1061 nor
->mtd
.erasesize
= nor
->info
->sector_size
?:
1062 SPI_NOR_DEFAULT_SECTOR_SIZE
;
1065 if (mfr_flags
& (USE_CLSR
| USE_CLPEF
)) {
1066 priv_params
= devm_kmalloc(nor
->dev
, sizeof(*priv_params
),
1071 if (mfr_flags
& USE_CLSR
)
1072 priv_params
->clsr
= SPINOR_OP_CLSR
;
1073 else if (mfr_flags
& USE_CLPEF
)
1074 priv_params
->clsr
= SPINOR_OP_CLPEF
;
1076 params
->priv
= priv_params
;
1077 params
->ready
= spansion_nor_sr_ready_and_clear
;
1083 static const struct spi_nor_fixups spansion_nor_fixups
= {
1084 .late_init
= spansion_nor_late_init
,
1087 const struct spi_nor_manufacturer spi_nor_spansion
= {
1089 .parts
= spansion_nor_parts
,
1090 .nparts
= ARRAY_SIZE(spansion_nor_parts
),
1091 .fixups
= &spansion_nor_fixups
,