Lines Matching full:nor
10 #include <linux/mtd/spi-nor.h>
48 /* Cypress SPI NOR flash operations. */
78 * @nor: pointer to 'struct spi_nor'.
80 static void spansion_nor_clear_sr(struct spi_nor *nor) in spansion_nor_clear_sr() argument
82 const struct spansion_nor_params *priv_params = nor->params->priv; in spansion_nor_clear_sr()
85 if (nor->spimem) { in spansion_nor_clear_sr()
88 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spansion_nor_clear_sr()
90 ret = spi_mem_exec_op(nor->spimem, &op); in spansion_nor_clear_sr()
92 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_CLSR, in spansion_nor_clear_sr()
97 dev_dbg(nor->dev, "error %d clearing SR\n", ret); in spansion_nor_clear_sr()
100 static int cypress_nor_sr_ready_and_clear_reg(struct spi_nor *nor, u64 addr) in cypress_nor_sr_ready_and_clear_reg() argument
102 struct spi_nor_flash_parameter *params = nor->params; in cypress_nor_sr_ready_and_clear_reg()
105 0, nor->bouncebuf); in cypress_nor_sr_ready_and_clear_reg()
108 if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) { in cypress_nor_sr_ready_and_clear_reg()
113 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_sr_ready_and_clear_reg()
117 if (nor->bouncebuf[0] & (SR_E_ERR | SR_P_ERR)) { in cypress_nor_sr_ready_and_clear_reg()
118 if (nor->bouncebuf[0] & SR_E_ERR) in cypress_nor_sr_ready_and_clear_reg()
119 dev_err(nor->dev, "Erase Error occurred\n"); in cypress_nor_sr_ready_and_clear_reg()
121 dev_err(nor->dev, "Programming Error occurred\n"); in cypress_nor_sr_ready_and_clear_reg()
123 spansion_nor_clear_sr(nor); in cypress_nor_sr_ready_and_clear_reg()
125 ret = spi_nor_write_disable(nor); in cypress_nor_sr_ready_and_clear_reg()
132 return !(nor->bouncebuf[0] & SR_WIP); in cypress_nor_sr_ready_and_clear_reg()
138 * @nor: pointer to 'struct spi_nor'.
142 static int cypress_nor_sr_ready_and_clear(struct spi_nor *nor) in cypress_nor_sr_ready_and_clear() argument
144 struct spi_nor_flash_parameter *params = nor->params; in cypress_nor_sr_ready_and_clear()
151 ret = cypress_nor_sr_ready_and_clear_reg(nor, addr); in cypress_nor_sr_ready_and_clear()
161 static int cypress_nor_set_memlat(struct spi_nor *nor, u64 addr) in cypress_nor_set_memlat() argument
164 u8 *buf = nor->bouncebuf; in cypress_nor_set_memlat()
166 u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; in cypress_nor_set_memlat()
171 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_set_memlat()
182 ret = spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto); in cypress_nor_set_memlat()
186 nor->read_dummy = 24; in cypress_nor_set_memlat()
191 static int cypress_nor_set_octal_dtr_bits(struct spi_nor *nor, u64 addr) in cypress_nor_set_octal_dtr_bits() argument
194 u8 *buf = nor->bouncebuf; in cypress_nor_set_octal_dtr_bits()
199 CYPRESS_NOR_WR_ANY_REG_OP(nor->params->addr_mode_nbytes, in cypress_nor_set_octal_dtr_bits()
202 return spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto); in cypress_nor_set_octal_dtr_bits()
205 static int cypress_nor_octal_dtr_en(struct spi_nor *nor) in cypress_nor_octal_dtr_en() argument
207 const struct spi_nor_flash_parameter *params = nor->params; in cypress_nor_octal_dtr_en()
208 u8 *buf = nor->bouncebuf; in cypress_nor_octal_dtr_en()
214 ret = cypress_nor_set_memlat(nor, addr); in cypress_nor_octal_dtr_en()
219 ret = cypress_nor_set_octal_dtr_bits(nor, addr); in cypress_nor_octal_dtr_en()
225 ret = spi_nor_read_id(nor, nor->addr_nbytes, 3, buf, in cypress_nor_octal_dtr_en()
228 dev_dbg(nor->dev, "error %d reading JEDEC ID after enabling 8D-8D-8D mode\n", ret); in cypress_nor_octal_dtr_en()
232 if (memcmp(buf, nor->info->id->bytes, nor->info->id->len)) in cypress_nor_octal_dtr_en()
238 static int cypress_nor_set_single_spi_bits(struct spi_nor *nor, u64 addr) in cypress_nor_set_single_spi_bits() argument
241 u8 *buf = nor->bouncebuf; in cypress_nor_set_single_spi_bits()
251 CYPRESS_NOR_WR_ANY_REG_OP(nor->addr_nbytes, addr, 2, buf); in cypress_nor_set_single_spi_bits()
252 return spi_nor_write_any_volatile_reg(nor, &op, SNOR_PROTO_8_8_8_DTR); in cypress_nor_set_single_spi_bits()
255 static int cypress_nor_octal_dtr_dis(struct spi_nor *nor) in cypress_nor_octal_dtr_dis() argument
257 const struct spi_nor_flash_parameter *params = nor->params; in cypress_nor_octal_dtr_dis()
258 u8 *buf = nor->bouncebuf; in cypress_nor_octal_dtr_dis()
264 ret = cypress_nor_set_single_spi_bits(nor, addr); in cypress_nor_octal_dtr_dis()
270 ret = spi_nor_read_id(nor, 0, 0, buf, SNOR_PROTO_1_1_1); in cypress_nor_octal_dtr_dis()
272 dev_dbg(nor->dev, "error %d reading JEDEC ID after disabling 8D-8D-8D mode\n", ret); in cypress_nor_octal_dtr_dis()
276 if (memcmp(buf, nor->info->id->bytes, nor->info->id->len)) in cypress_nor_octal_dtr_dis()
282 static int cypress_nor_quad_enable_volatile_reg(struct spi_nor *nor, u64 addr) in cypress_nor_quad_enable_volatile_reg() argument
285 u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; in cypress_nor_quad_enable_volatile_reg()
291 nor->bouncebuf); in cypress_nor_quad_enable_volatile_reg()
293 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_quad_enable_volatile_reg()
297 if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR1_QUAD_EN) in cypress_nor_quad_enable_volatile_reg()
301 nor->bouncebuf[0] |= SPINOR_REG_CYPRESS_CFR1_QUAD_EN; in cypress_nor_quad_enable_volatile_reg()
304 nor->bouncebuf); in cypress_nor_quad_enable_volatile_reg()
305 ret = spi_nor_write_any_volatile_reg(nor, &op, nor->reg_proto); in cypress_nor_quad_enable_volatile_reg()
309 cfr1v_written = nor->bouncebuf[0]; in cypress_nor_quad_enable_volatile_reg()
314 nor->bouncebuf); in cypress_nor_quad_enable_volatile_reg()
315 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_quad_enable_volatile_reg()
319 if (nor->bouncebuf[0] != cfr1v_written) { in cypress_nor_quad_enable_volatile_reg()
320 dev_err(nor->dev, "CFR1: Read back test failed\n"); in cypress_nor_quad_enable_volatile_reg()
330 * @nor: pointer to a 'struct spi_nor'
341 static int cypress_nor_quad_enable_volatile(struct spi_nor *nor) in cypress_nor_quad_enable_volatile() argument
343 struct spi_nor_flash_parameter *params = nor->params; in cypress_nor_quad_enable_volatile()
350 ret = cypress_nor_quad_enable_volatile_reg(nor, addr); in cypress_nor_quad_enable_volatile()
362 * @nor: pointer to a 'struct spi_nor'
371 static int cypress_nor_determine_addr_mode_by_sr1(struct spi_nor *nor, in cypress_nor_determine_addr_mode_by_sr1() argument
376 nor->bouncebuf); in cypress_nor_determine_addr_mode_by_sr1()
380 ret = spi_nor_read_sr(nor, &nor->bouncebuf[1]); in cypress_nor_determine_addr_mode_by_sr1()
384 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_determine_addr_mode_by_sr1()
388 is3byte = (nor->bouncebuf[0] == nor->bouncebuf[1]); in cypress_nor_determine_addr_mode_by_sr1()
392 nor->bouncebuf); in cypress_nor_determine_addr_mode_by_sr1()
393 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_determine_addr_mode_by_sr1()
397 is4byte = (nor->bouncebuf[0] == nor->bouncebuf[1]); in cypress_nor_determine_addr_mode_by_sr1()
412 * @nor: pointer to a 'struct spi_nor'
420 static int cypress_nor_set_addr_mode_nbytes(struct spi_nor *nor) in cypress_nor_set_addr_mode_nbytes() argument
430 ret = spi_nor_write_enable(nor); in cypress_nor_set_addr_mode_nbytes()
433 ret = cypress_nor_determine_addr_mode_by_sr1(nor, &addr_mode); in cypress_nor_set_addr_mode_nbytes()
435 ret = spi_nor_set_4byte_addr_mode(nor, true); in cypress_nor_set_addr_mode_nbytes()
438 return spi_nor_write_disable(nor); in cypress_nor_set_addr_mode_nbytes()
440 ret = spi_nor_write_disable(nor); in cypress_nor_set_addr_mode_nbytes()
450 0, nor->bouncebuf); in cypress_nor_set_addr_mode_nbytes()
451 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_set_addr_mode_nbytes()
455 if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR2_ADRBYT) { in cypress_nor_set_addr_mode_nbytes()
457 return spi_nor_set_4byte_addr_mode(nor, true); in cypress_nor_set_addr_mode_nbytes()
460 return spi_nor_set_4byte_addr_mode(nor, true); in cypress_nor_set_addr_mode_nbytes()
463 nor->params->addr_nbytes = addr_mode; in cypress_nor_set_addr_mode_nbytes()
464 nor->params->addr_mode_nbytes = addr_mode; in cypress_nor_set_addr_mode_nbytes()
471 * @nor: pointer to a 'struct spi_nor'
479 static int cypress_nor_get_page_size(struct spi_nor *nor) in cypress_nor_get_page_size() argument
482 CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, in cypress_nor_get_page_size()
483 0, 0, nor->bouncebuf); in cypress_nor_get_page_size()
484 struct spi_nor_flash_parameter *params = nor->params; in cypress_nor_get_page_size()
496 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in cypress_nor_get_page_size()
500 if (!(nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3_PGSZ)) in cypress_nor_get_page_size()
509 static void cypress_nor_ecc_init(struct spi_nor *nor) in cypress_nor_ecc_init() argument
516 nor->params->writesize = 16; in cypress_nor_ecc_init()
517 nor->flags |= SNOR_F_ECC; in cypress_nor_ecc_init()
521 s25fs256t_post_bfpt_fixup(struct spi_nor *nor, in s25fs256t_post_bfpt_fixup() argument
528 ret = cypress_nor_set_addr_mode_nbytes(nor); in s25fs256t_post_bfpt_fixup()
534 CYPRESS_NOR_RD_ANY_REG_OP(nor->params->addr_mode_nbytes, in s25fs256t_post_bfpt_fixup()
536 nor->bouncebuf); in s25fs256t_post_bfpt_fixup()
537 ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto); in s25fs256t_post_bfpt_fixup()
542 if (nor->bouncebuf[0]) in s25fs256t_post_bfpt_fixup()
548 static int s25fs256t_post_sfdp_fixup(struct spi_nor *nor) in s25fs256t_post_sfdp_fixup() argument
550 struct spi_nor_flash_parameter *params = nor->params; in s25fs256t_post_sfdp_fixup()
557 params->vreg_offset = devm_kmalloc(nor->dev, sizeof(u32), GFP_KERNEL); in s25fs256t_post_sfdp_fixup()
570 return cypress_nor_get_page_size(nor); in s25fs256t_post_sfdp_fixup()
573 static int s25fs256t_late_init(struct spi_nor *nor) in s25fs256t_late_init() argument
575 cypress_nor_ecc_init(nor); in s25fs256t_late_init()
587 s25hx_t_post_bfpt_fixup(struct spi_nor *nor, in s25hx_t_post_bfpt_fixup() argument
593 ret = cypress_nor_set_addr_mode_nbytes(nor); in s25hx_t_post_bfpt_fixup()
598 nor->params->quad_enable = cypress_nor_quad_enable_volatile; in s25hx_t_post_bfpt_fixup()
603 static int s25hx_t_post_sfdp_fixup(struct spi_nor *nor) in s25hx_t_post_sfdp_fixup() argument
605 struct spi_nor_flash_parameter *params = nor->params; in s25hx_t_post_sfdp_fixup()
610 dev_err(nor->dev, "%s failed. The volatile register offset could not be retrieved from SFDP.\n", in s25hx_t_post_sfdp_fixup()
636 return cypress_nor_get_page_size(nor); in s25hx_t_post_sfdp_fixup()
639 static int s25hx_t_late_init(struct spi_nor *nor) in s25hx_t_late_init() argument
641 struct spi_nor_flash_parameter *params = nor->params; in s25hx_t_late_init()
646 cypress_nor_ecc_init(nor); in s25hx_t_late_init()
660 * @nor: pointer to a 'struct spi_nor'
668 static int cypress_nor_set_octal_dtr(struct spi_nor *nor, bool enable) in cypress_nor_set_octal_dtr() argument
670 return enable ? cypress_nor_octal_dtr_en(nor) : in cypress_nor_set_octal_dtr()
671 cypress_nor_octal_dtr_dis(nor); in cypress_nor_set_octal_dtr()
674 static int s28hx_t_post_sfdp_fixup(struct spi_nor *nor) in s28hx_t_post_sfdp_fixup() argument
676 struct spi_nor_flash_parameter *params = nor->params; in s28hx_t_post_sfdp_fixup()
679 dev_err(nor->dev, "%s failed. The volatile register offset could not be retrieved from SFDP.\n", in s28hx_t_post_sfdp_fixup()
713 return cypress_nor_get_page_size(nor); in s28hx_t_post_sfdp_fixup()
716 static int s28hx_t_post_bfpt_fixup(struct spi_nor *nor, in s28hx_t_post_bfpt_fixup() argument
720 return cypress_nor_set_addr_mode_nbytes(nor); in s28hx_t_post_bfpt_fixup()
723 static int s28hx_t_late_init(struct spi_nor *nor) in s28hx_t_late_init() argument
725 struct spi_nor_flash_parameter *params = nor->params; in s28hx_t_late_init()
729 cypress_nor_ecc_init(nor); in s28hx_t_late_init()
741 s25fs_s_nor_post_bfpt_fixups(struct spi_nor *nor, in s25fs_s_nor_post_bfpt_fixups() argument
751 nor->params->page_size = 256; in s25fs_s_nor_post_bfpt_fixups()
1014 * @nor: pointer to 'struct spi_nor'.
1018 static int spansion_nor_sr_ready_and_clear(struct spi_nor *nor) in spansion_nor_sr_ready_and_clear() argument
1022 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spansion_nor_sr_ready_and_clear()
1026 if (nor->bouncebuf[0] & (SR_E_ERR | SR_P_ERR)) { in spansion_nor_sr_ready_and_clear()
1027 if (nor->bouncebuf[0] & SR_E_ERR) in spansion_nor_sr_ready_and_clear()
1028 dev_err(nor->dev, "Erase Error occurred\n"); in spansion_nor_sr_ready_and_clear()
1030 dev_err(nor->dev, "Programming Error occurred\n"); in spansion_nor_sr_ready_and_clear()
1032 spansion_nor_clear_sr(nor); in spansion_nor_sr_ready_and_clear()
1040 ret = spi_nor_write_disable(nor); in spansion_nor_sr_ready_and_clear()
1047 return !(nor->bouncebuf[0] & SR_WIP); in spansion_nor_sr_ready_and_clear()
1050 static int spansion_nor_late_init(struct spi_nor *nor) in spansion_nor_late_init() argument
1052 struct spi_nor_flash_parameter *params = nor->params; in spansion_nor_late_init()
1054 u8 mfr_flags = nor->info->mfr_flags; in spansion_nor_late_init()
1057 nor->flags |= SNOR_F_4B_OPCODES; in spansion_nor_late_init()
1059 nor->erase_opcode = SPINOR_OP_SE; in spansion_nor_late_init()
1060 nor->mtd.erasesize = nor->info->sector_size ?: in spansion_nor_late_init()
1065 priv_params = devm_kmalloc(nor->dev, sizeof(*priv_params), in spansion_nor_late_init()