Lines Matching full:nor
17 #include <linux/mtd/spi-nor.h>
49 * @nor: pointer to a 'struct spi_nor'
57 static u8 spi_nor_get_cmd_ext(const struct spi_nor *nor, in spi_nor_get_cmd_ext() argument
60 switch (nor->cmd_ext_type) { in spi_nor_get_cmd_ext()
68 dev_err(nor->dev, "Unknown command extension type\n"); in spi_nor_get_cmd_ext()
75 * @nor: pointer to a 'struct spi_nor'
80 void spi_nor_spimem_setup_op(const struct spi_nor *nor, in spi_nor_spimem_setup_op() argument
101 * something like 4S-4D-4D, but SPI NOR can't. So, set all 4 in spi_nor_spimem_setup_op()
112 ext = spi_nor_get_cmd_ext(nor, op); in spi_nor_spimem_setup_op()
121 * @nor: pointer to 'struct spi_nor'
128 static bool spi_nor_spimem_bounce(struct spi_nor *nor, struct spi_mem_op *op) in spi_nor_spimem_bounce() argument
133 if (op->data.nbytes > nor->bouncebuf_size) in spi_nor_spimem_bounce()
134 op->data.nbytes = nor->bouncebuf_size; in spi_nor_spimem_bounce()
135 op->data.buf.in = nor->bouncebuf; in spi_nor_spimem_bounce()
144 * @nor: pointer to 'struct spi_nor'
149 static int spi_nor_spimem_exec_op(struct spi_nor *nor, struct spi_mem_op *op) in spi_nor_spimem_exec_op() argument
153 error = spi_mem_adjust_op_size(nor->spimem, op); in spi_nor_spimem_exec_op()
157 return spi_mem_exec_op(nor->spimem, op); in spi_nor_spimem_exec_op()
160 int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode, in spi_nor_controller_ops_read_reg() argument
163 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_read_reg()
166 return nor->controller_ops->read_reg(nor, opcode, buf, len); in spi_nor_controller_ops_read_reg()
169 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode, in spi_nor_controller_ops_write_reg() argument
172 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_write_reg()
175 return nor->controller_ops->write_reg(nor, opcode, buf, len); in spi_nor_controller_ops_write_reg()
178 static int spi_nor_controller_ops_erase(struct spi_nor *nor, loff_t offs) in spi_nor_controller_ops_erase() argument
180 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_erase()
183 return nor->controller_ops->erase(nor, offs); in spi_nor_controller_ops_erase()
189 * @nor: pointer to 'struct spi_nor'
196 static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from, in spi_nor_spimem_read_data() argument
200 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), in spi_nor_spimem_read_data()
201 SPI_MEM_OP_ADDR(nor->addr_nbytes, from, 0), in spi_nor_spimem_read_data()
202 SPI_MEM_OP_DUMMY(nor->read_dummy, 0), in spi_nor_spimem_read_data()
208 spi_nor_spimem_setup_op(nor, &op, nor->read_proto); in spi_nor_spimem_read_data()
211 op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; in spi_nor_spimem_read_data()
212 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_spimem_read_data()
215 usebouncebuf = spi_nor_spimem_bounce(nor, &op); in spi_nor_spimem_read_data()
217 if (nor->dirmap.rdesc) { in spi_nor_spimem_read_data()
218 nbytes = spi_mem_dirmap_read(nor->dirmap.rdesc, op.addr.val, in spi_nor_spimem_read_data()
221 error = spi_nor_spimem_exec_op(nor, &op); in spi_nor_spimem_read_data()
235 * @nor: pointer to 'struct spi_nor'
242 ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, u8 *buf) in spi_nor_read_data() argument
244 if (nor->spimem) in spi_nor_read_data()
245 return spi_nor_spimem_read_data(nor, from, len, buf); in spi_nor_read_data()
247 return nor->controller_ops->read(nor, from, len, buf); in spi_nor_read_data()
253 * @nor: pointer to 'struct spi_nor'
260 static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to, in spi_nor_spimem_write_data() argument
264 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), in spi_nor_spimem_write_data()
265 SPI_MEM_OP_ADDR(nor->addr_nbytes, to, 0), in spi_nor_spimem_write_data()
271 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in spi_nor_spimem_write_data()
274 spi_nor_spimem_setup_op(nor, &op, nor->write_proto); in spi_nor_spimem_write_data()
276 if (spi_nor_spimem_bounce(nor, &op)) in spi_nor_spimem_write_data()
277 memcpy(nor->bouncebuf, buf, op.data.nbytes); in spi_nor_spimem_write_data()
279 if (nor->dirmap.wdesc) { in spi_nor_spimem_write_data()
280 nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc, op.addr.val, in spi_nor_spimem_write_data()
283 error = spi_nor_spimem_exec_op(nor, &op); in spi_nor_spimem_write_data()
294 * @nor: pointer to 'struct spi_nor'
301 ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len, in spi_nor_write_data() argument
304 if (nor->spimem) in spi_nor_write_data()
305 return spi_nor_spimem_write_data(nor, to, len, buf); in spi_nor_write_data()
307 return nor->controller_ops->write(nor, to, len, buf); in spi_nor_write_data()
313 * @nor: pointer to 'struct spi_nor'.
319 int spi_nor_read_any_reg(struct spi_nor *nor, struct spi_mem_op *op, in spi_nor_read_any_reg() argument
322 if (!nor->spimem) in spi_nor_read_any_reg()
325 spi_nor_spimem_setup_op(nor, op, proto); in spi_nor_read_any_reg()
326 return spi_nor_spimem_exec_op(nor, op); in spi_nor_read_any_reg()
332 * @nor: pointer to 'struct spi_nor'
341 int spi_nor_write_any_volatile_reg(struct spi_nor *nor, struct spi_mem_op *op, in spi_nor_write_any_volatile_reg() argument
346 if (!nor->spimem) in spi_nor_write_any_volatile_reg()
349 ret = spi_nor_write_enable(nor); in spi_nor_write_any_volatile_reg()
352 spi_nor_spimem_setup_op(nor, op, proto); in spi_nor_write_any_volatile_reg()
353 return spi_nor_spimem_exec_op(nor, op); in spi_nor_write_any_volatile_reg()
358 * @nor: pointer to 'struct spi_nor'.
362 int spi_nor_write_enable(struct spi_nor *nor) in spi_nor_write_enable() argument
366 if (nor->spimem) { in spi_nor_write_enable()
369 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_enable()
371 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_enable()
373 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREN, in spi_nor_write_enable()
378 dev_dbg(nor->dev, "error %d on Write Enable\n", ret); in spi_nor_write_enable()
385 * @nor: pointer to 'struct spi_nor'.
389 int spi_nor_write_disable(struct spi_nor *nor) in spi_nor_write_disable() argument
393 if (nor->spimem) { in spi_nor_write_disable()
396 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_disable()
398 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_disable()
400 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRDI, in spi_nor_write_disable()
405 dev_dbg(nor->dev, "error %d on Write Disable\n", ret); in spi_nor_write_disable()
412 * @nor: pointer to 'struct spi_nor'.
423 int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ndummy, u8 *id, in spi_nor_read_id() argument
428 if (nor->spimem) { in spi_nor_read_id()
432 spi_nor_spimem_setup_op(nor, &op, proto); in spi_nor_read_id()
433 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_id()
435 ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id, in spi_nor_read_id()
443 * @nor: pointer to 'struct spi_nor'.
449 int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) in spi_nor_read_sr() argument
453 if (nor->spimem) { in spi_nor_read_sr()
456 if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) { in spi_nor_read_sr()
457 op.addr.nbytes = nor->params->rdsr_addr_nbytes; in spi_nor_read_sr()
458 op.dummy.nbytes = nor->params->rdsr_dummy; in spi_nor_read_sr()
466 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_sr()
468 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_sr()
470 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr, in spi_nor_read_sr()
475 dev_dbg(nor->dev, "error %d reading SR\n", ret); in spi_nor_read_sr()
483 * @nor: pointer to 'struct spi_nor'
489 int spi_nor_read_cr(struct spi_nor *nor, u8 *cr) in spi_nor_read_cr() argument
493 if (nor->spimem) { in spi_nor_read_cr()
496 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_cr()
498 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_cr()
500 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDCR, cr, in spi_nor_read_cr()
505 dev_dbg(nor->dev, "error %d reading CR\n", ret); in spi_nor_read_cr()
514 * @nor: pointer to 'struct spi_nor'.
520 int spi_nor_set_4byte_addr_mode_en4b_ex4b(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode_en4b_ex4b() argument
524 if (nor->spimem) { in spi_nor_set_4byte_addr_mode_en4b_ex4b()
527 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
529 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
531 ret = spi_nor_controller_ops_write_reg(nor, in spi_nor_set_4byte_addr_mode_en4b_ex4b()
538 dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
547 * @nor: pointer to 'struct spi_nor'.
553 int spi_nor_set_4byte_addr_mode_wren_en4b_ex4b(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b() argument
557 ret = spi_nor_write_enable(nor); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
561 ret = spi_nor_set_4byte_addr_mode_en4b_ex4b(nor, enable); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
565 return spi_nor_write_disable(nor); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
571 * @nor: pointer to 'struct spi_nor'.
582 int spi_nor_set_4byte_addr_mode_brwr(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode_brwr() argument
586 nor->bouncebuf[0] = enable << 7; in spi_nor_set_4byte_addr_mode_brwr()
588 if (nor->spimem) { in spi_nor_set_4byte_addr_mode_brwr()
589 struct spi_mem_op op = SPI_NOR_BRWR_OP(nor->bouncebuf); in spi_nor_set_4byte_addr_mode_brwr()
591 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_set_4byte_addr_mode_brwr()
593 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_set_4byte_addr_mode_brwr()
595 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_BRWR, in spi_nor_set_4byte_addr_mode_brwr()
596 nor->bouncebuf, 1); in spi_nor_set_4byte_addr_mode_brwr()
600 dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); in spi_nor_set_4byte_addr_mode_brwr()
608 * @nor: pointer to 'struct spi_nor'.
612 int spi_nor_sr_ready(struct spi_nor *nor) in spi_nor_sr_ready() argument
616 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr_ready()
620 return !(nor->bouncebuf[0] & SR_WIP); in spi_nor_sr_ready()
625 * @nor: pointer to 'struct spi_nor'.
629 static bool spi_nor_use_parallel_locking(struct spi_nor *nor) in spi_nor_use_parallel_locking() argument
631 return nor->flags & SNOR_F_RWW; in spi_nor_use_parallel_locking()
635 static int spi_nor_rww_start_rdst(struct spi_nor *nor) in spi_nor_rww_start_rdst() argument
637 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_rdst()
640 mutex_lock(&nor->lock); in spi_nor_rww_start_rdst()
650 mutex_unlock(&nor->lock); in spi_nor_rww_start_rdst()
654 static void spi_nor_rww_end_rdst(struct spi_nor *nor) in spi_nor_rww_end_rdst() argument
656 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_rdst()
658 mutex_lock(&nor->lock); in spi_nor_rww_end_rdst()
663 mutex_unlock(&nor->lock); in spi_nor_rww_end_rdst()
666 static int spi_nor_lock_rdst(struct spi_nor *nor) in spi_nor_lock_rdst() argument
668 if (spi_nor_use_parallel_locking(nor)) in spi_nor_lock_rdst()
669 return spi_nor_rww_start_rdst(nor); in spi_nor_lock_rdst()
674 static void spi_nor_unlock_rdst(struct spi_nor *nor) in spi_nor_unlock_rdst() argument
676 if (spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_rdst()
677 spi_nor_rww_end_rdst(nor); in spi_nor_unlock_rdst()
678 wake_up(&nor->rww.wait); in spi_nor_unlock_rdst()
684 * @nor: pointer to 'struct spi_nor'.
688 static int spi_nor_ready(struct spi_nor *nor) in spi_nor_ready() argument
692 ret = spi_nor_lock_rdst(nor); in spi_nor_ready()
697 if (nor->params->ready) in spi_nor_ready()
698 ret = nor->params->ready(nor); in spi_nor_ready()
700 ret = spi_nor_sr_ready(nor); in spi_nor_ready()
702 spi_nor_unlock_rdst(nor); in spi_nor_ready()
710 * @nor: pointer to "struct spi_nor".
715 static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, in spi_nor_wait_till_ready_with_timeout() argument
727 ret = spi_nor_ready(nor); in spi_nor_wait_till_ready_with_timeout()
736 dev_dbg(nor->dev, "flash operation timed out\n"); in spi_nor_wait_till_ready_with_timeout()
744 * @nor: pointer to "struct spi_nor".
748 int spi_nor_wait_till_ready(struct spi_nor *nor) in spi_nor_wait_till_ready() argument
750 return spi_nor_wait_till_ready_with_timeout(nor, in spi_nor_wait_till_ready()
756 * @nor: pointer to 'struct spi_nor'.
760 int spi_nor_global_block_unlock(struct spi_nor *nor) in spi_nor_global_block_unlock() argument
764 ret = spi_nor_write_enable(nor); in spi_nor_global_block_unlock()
768 if (nor->spimem) { in spi_nor_global_block_unlock()
771 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_global_block_unlock()
773 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_global_block_unlock()
775 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_GBULK, in spi_nor_global_block_unlock()
780 dev_dbg(nor->dev, "error %d on Global Block Unlock\n", ret); in spi_nor_global_block_unlock()
784 return spi_nor_wait_till_ready(nor); in spi_nor_global_block_unlock()
789 * @nor: pointer to 'struct spi_nor'.
795 int spi_nor_write_sr(struct spi_nor *nor, const u8 *sr, size_t len) in spi_nor_write_sr() argument
799 ret = spi_nor_write_enable(nor); in spi_nor_write_sr()
803 if (nor->spimem) { in spi_nor_write_sr()
806 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_sr()
808 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_sr()
810 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR, sr, in spi_nor_write_sr()
815 dev_dbg(nor->dev, "error %d writing SR\n", ret); in spi_nor_write_sr()
819 return spi_nor_wait_till_ready(nor); in spi_nor_write_sr()
825 * @nor: pointer to a 'struct spi_nor'.
830 static int spi_nor_write_sr1_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_sr1_and_check() argument
834 nor->bouncebuf[0] = sr1; in spi_nor_write_sr1_and_check()
836 ret = spi_nor_write_sr(nor, nor->bouncebuf, 1); in spi_nor_write_sr1_and_check()
840 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_write_sr1_and_check()
844 if (nor->bouncebuf[0] != sr1) { in spi_nor_write_sr1_and_check()
845 dev_dbg(nor->dev, "SR1: read back test failed\n"); in spi_nor_write_sr1_and_check()
857 * @nor: pointer to a 'struct spi_nor'.
862 static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_16bit_sr_and_check() argument
865 u8 *sr_cr = nor->bouncebuf; in spi_nor_write_16bit_sr_and_check()
869 if (!(nor->flags & SNOR_F_NO_READ_CR)) { in spi_nor_write_16bit_sr_and_check()
870 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_sr_and_check()
873 } else if (spi_nor_get_protocol_width(nor->read_proto) == 4 && in spi_nor_write_16bit_sr_and_check()
874 spi_nor_get_protocol_width(nor->write_proto) == 4 && in spi_nor_write_16bit_sr_and_check()
875 nor->params->quad_enable) { in spi_nor_write_16bit_sr_and_check()
883 * consequence of the nor->params->quad_enable() call. in spi_nor_write_16bit_sr_and_check()
897 ret = spi_nor_write_sr(nor, sr_cr, 2); in spi_nor_write_16bit_sr_and_check()
901 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_sr_and_check()
906 dev_dbg(nor->dev, "SR: Read back test failed\n"); in spi_nor_write_16bit_sr_and_check()
910 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_write_16bit_sr_and_check()
915 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_sr_and_check()
920 dev_dbg(nor->dev, "CR: read back test failed\n"); in spi_nor_write_16bit_sr_and_check()
932 * @nor: pointer to a 'struct spi_nor'.
937 int spi_nor_write_16bit_cr_and_check(struct spi_nor *nor, u8 cr) in spi_nor_write_16bit_cr_and_check() argument
940 u8 *sr_cr = nor->bouncebuf; in spi_nor_write_16bit_cr_and_check()
944 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_cr_and_check()
950 ret = spi_nor_write_sr(nor, sr_cr, 2); in spi_nor_write_16bit_cr_and_check()
956 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_cr_and_check()
961 dev_dbg(nor->dev, "SR: Read back test failed\n"); in spi_nor_write_16bit_cr_and_check()
965 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_write_16bit_cr_and_check()
968 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_cr_and_check()
973 dev_dbg(nor->dev, "CR: read back test failed\n"); in spi_nor_write_16bit_cr_and_check()
984 * @nor: pointer to a 'struct spi_nor'.
989 int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_sr_and_check() argument
991 if (nor->flags & SNOR_F_HAS_16BIT_SR) in spi_nor_write_sr_and_check()
992 return spi_nor_write_16bit_sr_and_check(nor, sr1); in spi_nor_write_sr_and_check()
994 return spi_nor_write_sr1_and_check(nor, sr1); in spi_nor_write_sr_and_check()
1000 * @nor: pointer to 'struct spi_nor'.
1005 static int spi_nor_write_sr2(struct spi_nor *nor, const u8 *sr2) in spi_nor_write_sr2() argument
1009 ret = spi_nor_write_enable(nor); in spi_nor_write_sr2()
1013 if (nor->spimem) { in spi_nor_write_sr2()
1016 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_sr2()
1018 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_sr2()
1020 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR2, in spi_nor_write_sr2()
1025 dev_dbg(nor->dev, "error %d writing SR2\n", ret); in spi_nor_write_sr2()
1029 return spi_nor_wait_till_ready(nor); in spi_nor_write_sr2()
1035 * @nor: pointer to 'struct spi_nor'.
1041 static int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2) in spi_nor_read_sr2() argument
1045 if (nor->spimem) { in spi_nor_read_sr2()
1048 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_sr2()
1050 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_sr2()
1052 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR2, sr2, in spi_nor_read_sr2()
1057 dev_dbg(nor->dev, "error %d reading SR2\n", ret); in spi_nor_read_sr2()
1064 * @nor: pointer to 'struct spi_nor'.
1070 static int spi_nor_erase_die(struct spi_nor *nor, loff_t addr, size_t die_size) in spi_nor_erase_die() argument
1072 bool multi_die = nor->mtd.size != die_size; in spi_nor_erase_die()
1075 dev_dbg(nor->dev, " %lldKiB\n", (long long)(die_size >> 10)); in spi_nor_erase_die()
1077 if (nor->spimem) { in spi_nor_erase_die()
1079 SPI_NOR_DIE_ERASE_OP(nor->params->die_erase_opcode, in spi_nor_erase_die()
1080 nor->addr_nbytes, addr, multi_die); in spi_nor_erase_die()
1082 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_erase_die()
1084 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_erase_die()
1089 ret = spi_nor_controller_ops_write_reg(nor, in spi_nor_erase_die()
1095 dev_dbg(nor->dev, "error %d erasing chip\n", ret); in spi_nor_erase_die()
1159 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor) in spi_nor_has_uniform_erase() argument
1161 return !!nor->params->erase_map.uniform_region.erase_mask; in spi_nor_has_uniform_erase()
1164 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) in spi_nor_set_4byte_opcodes() argument
1166 nor->read_opcode = spi_nor_convert_3to4_read(nor->read_opcode); in spi_nor_set_4byte_opcodes()
1167 nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode); in spi_nor_set_4byte_opcodes()
1168 nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode); in spi_nor_set_4byte_opcodes()
1170 if (!spi_nor_has_uniform_erase(nor)) { in spi_nor_set_4byte_opcodes()
1171 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_set_4byte_opcodes()
1183 static int spi_nor_prep(struct spi_nor *nor) in spi_nor_prep() argument
1187 if (nor->controller_ops && nor->controller_ops->prepare) in spi_nor_prep()
1188 ret = nor->controller_ops->prepare(nor); in spi_nor_prep()
1193 static void spi_nor_unprep(struct spi_nor *nor) in spi_nor_unprep() argument
1195 if (nor->controller_ops && nor->controller_ops->unprepare) in spi_nor_unprep()
1196 nor->controller_ops->unprepare(nor); in spi_nor_unprep()
1208 static bool spi_nor_rww_start_io(struct spi_nor *nor) in spi_nor_rww_start_io() argument
1210 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_io()
1213 mutex_lock(&nor->lock); in spi_nor_rww_start_io()
1222 mutex_unlock(&nor->lock); in spi_nor_rww_start_io()
1226 static void spi_nor_rww_end_io(struct spi_nor *nor) in spi_nor_rww_end_io() argument
1228 mutex_lock(&nor->lock); in spi_nor_rww_end_io()
1229 nor->rww.ongoing_io = false; in spi_nor_rww_end_io()
1230 mutex_unlock(&nor->lock); in spi_nor_rww_end_io()
1233 static int spi_nor_lock_device(struct spi_nor *nor) in spi_nor_lock_device() argument
1235 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_lock_device()
1238 return wait_event_killable(nor->rww.wait, spi_nor_rww_start_io(nor)); in spi_nor_lock_device()
1241 static void spi_nor_unlock_device(struct spi_nor *nor) in spi_nor_unlock_device() argument
1243 if (spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_device()
1244 spi_nor_rww_end_io(nor); in spi_nor_unlock_device()
1245 wake_up(&nor->rww.wait); in spi_nor_unlock_device()
1250 static bool spi_nor_rww_start_exclusive(struct spi_nor *nor) in spi_nor_rww_start_exclusive() argument
1252 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_exclusive()
1255 mutex_lock(&nor->lock); in spi_nor_rww_start_exclusive()
1266 mutex_unlock(&nor->lock); in spi_nor_rww_start_exclusive()
1270 static void spi_nor_rww_end_exclusive(struct spi_nor *nor) in spi_nor_rww_end_exclusive() argument
1272 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_exclusive()
1274 mutex_lock(&nor->lock); in spi_nor_rww_end_exclusive()
1278 mutex_unlock(&nor->lock); in spi_nor_rww_end_exclusive()
1281 int spi_nor_prep_and_lock(struct spi_nor *nor) in spi_nor_prep_and_lock() argument
1285 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock()
1289 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock()
1290 mutex_lock(&nor->lock); in spi_nor_prep_and_lock()
1292 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock()
1293 spi_nor_rww_start_exclusive(nor)); in spi_nor_prep_and_lock()
1298 void spi_nor_unlock_and_unprep(struct spi_nor *nor) in spi_nor_unlock_and_unprep() argument
1300 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep()
1301 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep()
1303 spi_nor_rww_end_exclusive(nor); in spi_nor_unlock_and_unprep()
1304 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep()
1307 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep()
1311 static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_start_pe() argument
1313 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_pe()
1319 mutex_lock(&nor->lock); in spi_nor_rww_start_pe()
1324 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_start_pe()
1337 mutex_unlock(&nor->lock); in spi_nor_rww_start_pe()
1341 static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_end_pe() argument
1343 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_pe()
1347 mutex_lock(&nor->lock); in spi_nor_rww_end_pe()
1349 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_end_pe()
1355 mutex_unlock(&nor->lock); in spi_nor_rww_end_pe()
1358 static int spi_nor_prep_and_lock_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_prep_and_lock_pe() argument
1362 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock_pe()
1366 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock_pe()
1367 mutex_lock(&nor->lock); in spi_nor_prep_and_lock_pe()
1369 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock_pe()
1370 spi_nor_rww_start_pe(nor, start, len)); in spi_nor_prep_and_lock_pe()
1375 static void spi_nor_unlock_and_unprep_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_unlock_and_unprep_pe() argument
1377 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep_pe()
1378 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep_pe()
1380 spi_nor_rww_end_pe(nor, start, len); in spi_nor_unlock_and_unprep_pe()
1381 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep_pe()
1384 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep_pe()
1388 static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_start_rd() argument
1390 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_rd()
1396 mutex_lock(&nor->lock); in spi_nor_rww_start_rd()
1401 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_start_rd()
1415 mutex_unlock(&nor->lock); in spi_nor_rww_start_rd()
1419 static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_end_rd() argument
1421 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_rd()
1425 mutex_lock(&nor->lock); in spi_nor_rww_end_rd()
1427 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_end_rd()
1429 nor->rww.used_banks &= ~BIT(bank); in spi_nor_rww_end_rd()
1434 mutex_unlock(&nor->lock); in spi_nor_rww_end_rd()
1437 static int spi_nor_prep_and_lock_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_prep_and_lock_rd() argument
1441 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock_rd()
1445 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock_rd()
1446 mutex_lock(&nor->lock); in spi_nor_prep_and_lock_rd()
1448 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock_rd()
1449 spi_nor_rww_start_rd(nor, start, len)); in spi_nor_prep_and_lock_rd()
1454 static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_unlock_and_unprep_rd() argument
1456 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep_rd()
1457 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep_rd()
1459 spi_nor_rww_end_rd(nor, start, len); in spi_nor_unlock_and_unprep_rd()
1460 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep_rd()
1463 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep_rd()
1469 int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) in spi_nor_erase_sector() argument
1473 if (nor->spimem) { in spi_nor_erase_sector()
1475 SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode, in spi_nor_erase_sector()
1476 nor->addr_nbytes, addr); in spi_nor_erase_sector()
1478 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_erase_sector()
1480 return spi_mem_exec_op(nor->spimem, &op); in spi_nor_erase_sector()
1481 } else if (nor->controller_ops->erase) { in spi_nor_erase_sector()
1482 return spi_nor_controller_ops_erase(nor, addr); in spi_nor_erase_sector()
1489 for (i = nor->addr_nbytes - 1; i >= 0; i--) { in spi_nor_erase_sector()
1490 nor->bouncebuf[i] = addr & 0xff; in spi_nor_erase_sector()
1494 return spi_nor_controller_ops_write_reg(nor, nor->erase_opcode, in spi_nor_erase_sector()
1495 nor->bouncebuf, nor->addr_nbytes); in spi_nor_erase_sector()
1500 * @erase: pointer to a structure that describes a SPI NOR erase type
1520 * @map: the erase map of the SPI NOR
1521 * @region: pointer to a structure that describes a SPI NOR erase region
1567 * @region: pointer to a structure that describes a SPI NOR erase region
1568 * @erase: pointer to a structure that describes a SPI NOR erase type
1611 * @nor: pointer to a 'struct spi_nor'
1622 static int spi_nor_init_erase_cmd_list(struct spi_nor *nor, in spi_nor_init_erase_cmd_list() argument
1626 const struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_init_erase_cmd_list()
1672 * @nor: pointer to a 'struct spi_nor'
1681 static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len) in spi_nor_erase_multi_sectors() argument
1687 ret = spi_nor_init_erase_cmd_list(nor, &erase_list, addr, len); in spi_nor_erase_multi_sectors()
1692 nor->erase_opcode = cmd->opcode; in spi_nor_erase_multi_sectors()
1694 …dev_vdbg(nor->dev, "erase_cmd->size = 0x%08x, erase_cmd->opcode = 0x%02x, erase_cmd->count = %u\n", in spi_nor_erase_multi_sectors()
1697 ret = spi_nor_lock_device(nor); in spi_nor_erase_multi_sectors()
1701 ret = spi_nor_write_enable(nor); in spi_nor_erase_multi_sectors()
1703 spi_nor_unlock_device(nor); in spi_nor_erase_multi_sectors()
1707 ret = spi_nor_erase_sector(nor, addr); in spi_nor_erase_multi_sectors()
1708 spi_nor_unlock_device(nor); in spi_nor_erase_multi_sectors()
1712 ret = spi_nor_wait_till_ready(nor); in spi_nor_erase_multi_sectors()
1730 static int spi_nor_erase_dice(struct spi_nor *nor, loff_t addr, in spi_nor_erase_dice() argument
1744 (unsigned long)(nor->mtd.size / SZ_2M)); in spi_nor_erase_dice()
1747 ret = spi_nor_lock_device(nor); in spi_nor_erase_dice()
1751 ret = spi_nor_write_enable(nor); in spi_nor_erase_dice()
1753 spi_nor_unlock_device(nor); in spi_nor_erase_dice()
1757 ret = spi_nor_erase_die(nor, addr, die_size); in spi_nor_erase_dice()
1759 spi_nor_unlock_device(nor); in spi_nor_erase_dice()
1763 ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); in spi_nor_erase_dice()
1776 * Erase an address range on the nor chip. The address range may extend
1781 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_erase() local
1782 u8 n_dice = nor->params->n_dice; in spi_nor_erase()
1788 dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr, in spi_nor_erase()
1791 if (spi_nor_has_uniform_erase(nor)) { in spi_nor_erase()
1808 ret = spi_nor_prep_and_lock_pe(nor, instr->addr, instr->len); in spi_nor_erase()
1813 if ((len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) || in spi_nor_erase()
1815 ret = spi_nor_erase_dice(nor, addr, len, die_size); in spi_nor_erase()
1825 } else if (spi_nor_has_uniform_erase(nor)) { in spi_nor_erase()
1827 ret = spi_nor_lock_device(nor); in spi_nor_erase()
1831 ret = spi_nor_write_enable(nor); in spi_nor_erase()
1833 spi_nor_unlock_device(nor); in spi_nor_erase()
1837 ret = spi_nor_erase_sector(nor, addr); in spi_nor_erase()
1838 spi_nor_unlock_device(nor); in spi_nor_erase()
1842 ret = spi_nor_wait_till_ready(nor); in spi_nor_erase()
1852 ret = spi_nor_erase_multi_sectors(nor, addr, len); in spi_nor_erase()
1857 ret = spi_nor_write_disable(nor); in spi_nor_erase()
1860 spi_nor_unlock_and_unprep_pe(nor, instr->addr, instr->len); in spi_nor_erase()
1868 * @nor: pointer to a 'struct spi_nor'
1874 int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor) in spi_nor_sr1_bit6_quad_enable() argument
1878 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr1_bit6_quad_enable()
1882 if (nor->bouncebuf[0] & SR1_QUAD_EN_BIT6) in spi_nor_sr1_bit6_quad_enable()
1885 nor->bouncebuf[0] |= SR1_QUAD_EN_BIT6; in spi_nor_sr1_bit6_quad_enable()
1887 return spi_nor_write_sr1_and_check(nor, nor->bouncebuf[0]); in spi_nor_sr1_bit6_quad_enable()
1893 * @nor: pointer to a 'struct spi_nor'.
1899 int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor) in spi_nor_sr2_bit1_quad_enable() argument
1903 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_sr2_bit1_quad_enable()
1904 return spi_nor_write_16bit_cr_and_check(nor, SR2_QUAD_EN_BIT1); in spi_nor_sr2_bit1_quad_enable()
1906 ret = spi_nor_read_cr(nor, nor->bouncebuf); in spi_nor_sr2_bit1_quad_enable()
1910 if (nor->bouncebuf[0] & SR2_QUAD_EN_BIT1) in spi_nor_sr2_bit1_quad_enable()
1913 nor->bouncebuf[0] |= SR2_QUAD_EN_BIT1; in spi_nor_sr2_bit1_quad_enable()
1915 return spi_nor_write_16bit_cr_and_check(nor, nor->bouncebuf[0]); in spi_nor_sr2_bit1_quad_enable()
1920 * @nor: pointer to a 'struct spi_nor'
1930 int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor) in spi_nor_sr2_bit7_quad_enable() argument
1932 u8 *sr2 = nor->bouncebuf; in spi_nor_sr2_bit7_quad_enable()
1937 ret = spi_nor_read_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1946 ret = spi_nor_write_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1953 ret = spi_nor_read_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1958 dev_dbg(nor->dev, "SR2: Read back test failed\n"); in spi_nor_sr2_bit7_quad_enable()
1983 .name = "spi-nor-generic",
1986 static const struct flash_info *spi_nor_match_id(struct spi_nor *nor, in spi_nor_match_id() argument
1997 nor->manufacturer = manufacturers[i]; in spi_nor_match_id()
2006 static const struct flash_info *spi_nor_detect(struct spi_nor *nor) in spi_nor_detect() argument
2009 u8 *id = nor->bouncebuf; in spi_nor_detect()
2012 ret = spi_nor_read_id(nor, 0, 0, id, nor->reg_proto); in spi_nor_detect()
2014 dev_dbg(nor->dev, "error %d reading JEDEC ID\n", ret); in spi_nor_detect()
2019 nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL); in spi_nor_detect()
2020 if (!nor->id) in spi_nor_detect()
2023 info = spi_nor_match_id(nor, id); in spi_nor_detect()
2027 ret = spi_nor_check_sfdp_signature(nor); in spi_nor_detect()
2033 dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", in spi_nor_detect()
2043 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_read() local
2048 dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len); in spi_nor_read()
2050 ret = spi_nor_prep_and_lock_rd(nor, from_lock, len_lock); in spi_nor_read()
2057 ret = spi_nor_read_data(nor, addr, len, buf); in spi_nor_read()
2075 spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock); in spi_nor_read()
2081 * Write an address range to the nor chip. Data must be written in
2088 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_write() local
2091 u32 page_size = nor->params->page_size; in spi_nor_write()
2093 dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); in spi_nor_write()
2095 ret = spi_nor_prep_and_lock_pe(nor, to, len); in spi_nor_write()
2106 ret = spi_nor_lock_device(nor); in spi_nor_write()
2110 ret = spi_nor_write_enable(nor); in spi_nor_write()
2112 spi_nor_unlock_device(nor); in spi_nor_write()
2116 ret = spi_nor_write_data(nor, addr, page_remain, buf + i); in spi_nor_write()
2117 spi_nor_unlock_device(nor); in spi_nor_write()
2122 ret = spi_nor_wait_till_ready(nor); in spi_nor_write()
2130 spi_nor_unlock_and_unprep_pe(nor, to, len); in spi_nor_write()
2135 static int spi_nor_check(struct spi_nor *nor) in spi_nor_check() argument
2137 if (!nor->dev || in spi_nor_check()
2138 (!nor->spimem && !nor->controller_ops) || in spi_nor_check()
2139 (!nor->spimem && nor->controller_ops && in spi_nor_check()
2140 (!nor->controller_ops->read || in spi_nor_check()
2141 !nor->controller_ops->write || in spi_nor_check()
2142 !nor->controller_ops->read_reg || in spi_nor_check()
2143 !nor->controller_ops->write_reg))) { in spi_nor_check()
2144 pr_err("spi-nor: please fill all the necessary fields!\n"); in spi_nor_check()
2148 if (nor->spimem && nor->controller_ops) { in spi_nor_check()
2149 …dev_err(nor->dev, "nor->spimem and nor->controller_ops are mutually exclusive, please set just one… in spi_nor_check()
2232 *@nor: pointer to a 'struct spi_nor'
2237 static int spi_nor_spimem_check_op(struct spi_nor *nor, in spi_nor_spimem_check_op() argument
2247 if (!spi_mem_supports_op(nor->spimem, op)) { in spi_nor_spimem_check_op()
2248 if (nor->params->size > SZ_16M) in spi_nor_spimem_check_op()
2253 if (!spi_mem_supports_op(nor->spimem, op)) in spi_nor_spimem_check_op()
2263 *@nor: pointer to a 'struct spi_nor'
2268 static int spi_nor_spimem_check_readop(struct spi_nor *nor, in spi_nor_spimem_check_readop() argument
2273 spi_nor_spimem_setup_op(nor, &op, read->proto); in spi_nor_spimem_check_readop()
2278 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_spimem_check_readop()
2281 return spi_nor_spimem_check_op(nor, &op); in spi_nor_spimem_check_readop()
2287 *@nor: pointer to a 'struct spi_nor'
2292 static int spi_nor_spimem_check_pp(struct spi_nor *nor, in spi_nor_spimem_check_pp() argument
2297 spi_nor_spimem_setup_op(nor, &op, pp->proto); in spi_nor_spimem_check_pp()
2299 return spi_nor_spimem_check_op(nor, &op); in spi_nor_spimem_check_pp()
2305 * @nor: pointer to a 'struct spi_nor'
2310 spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps) in spi_nor_spimem_adjust_hwcaps() argument
2312 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_spimem_adjust_hwcaps()
2322 if (nor->flags & SNOR_F_BROKEN_RESET) in spi_nor_spimem_adjust_hwcaps()
2333 spi_nor_spimem_check_readop(nor, ¶ms->reads[rdidx])) in spi_nor_spimem_adjust_hwcaps()
2340 if (spi_nor_spimem_check_pp(nor, in spi_nor_spimem_adjust_hwcaps()
2347 * spi_nor_set_erase_type() - set a SPI NOR erase type
2348 * @erase: pointer to a structure that describes a SPI NOR erase type
2363 * spi_nor_mask_erase_type() - mask out a SPI NOR erase type
2364 * @erase: pointer to a structure that describes a SPI NOR erase type
2373 * @map: the erase map of the SPI NOR
2376 * @flash_size: the spi nor flash memory size
2388 int spi_nor_post_bfpt_fixups(struct spi_nor *nor, in spi_nor_post_bfpt_fixups() argument
2394 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_post_bfpt_fixups()
2395 nor->manufacturer->fixups->post_bfpt) { in spi_nor_post_bfpt_fixups()
2396 ret = nor->manufacturer->fixups->post_bfpt(nor, bfpt_header, in spi_nor_post_bfpt_fixups()
2402 if (nor->info->fixups && nor->info->fixups->post_bfpt) in spi_nor_post_bfpt_fixups()
2403 return nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt); in spi_nor_post_bfpt_fixups()
2408 static int spi_nor_select_read(struct spi_nor *nor, in spi_nor_select_read() argument
2421 read = &nor->params->reads[cmd]; in spi_nor_select_read()
2422 nor->read_opcode = read->opcode; in spi_nor_select_read()
2423 nor->read_proto = read->proto; in spi_nor_select_read()
2426 * In the SPI NOR framework, we don't need to make the difference in spi_nor_select_read()
2435 nor->read_dummy = read->num_mode_clocks + read->num_wait_states; in spi_nor_select_read()
2439 static int spi_nor_select_pp(struct spi_nor *nor, in spi_nor_select_pp() argument
2452 pp = &nor->params->page_programs[cmd]; in spi_nor_select_pp()
2453 nor->program_opcode = pp->opcode; in spi_nor_select_pp()
2454 nor->write_proto = pp->proto; in spi_nor_select_pp()
2460 * @map: the erase map of the SPI NOR
2515 static int spi_nor_select_erase(struct spi_nor *nor) in spi_nor_select_erase() argument
2517 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_select_erase()
2519 struct mtd_info *mtd = &nor->mtd; in spi_nor_select_erase()
2530 if (spi_nor_has_uniform_erase(nor)) { in spi_nor_select_erase()
2534 nor->erase_opcode = erase->opcode; in spi_nor_select_erase()
2541 * maximum erase sector size. No need to set nor->erase_opcode. in spi_nor_select_erase()
2557 static int spi_nor_set_addr_nbytes(struct spi_nor *nor) in spi_nor_set_addr_nbytes() argument
2559 if (nor->params->addr_nbytes) { in spi_nor_set_addr_nbytes()
2560 nor->addr_nbytes = nor->params->addr_nbytes; in spi_nor_set_addr_nbytes()
2561 } else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) { in spi_nor_set_addr_nbytes()
2574 nor->addr_nbytes = 4; in spi_nor_set_addr_nbytes()
2575 } else if (nor->info->addr_nbytes) { in spi_nor_set_addr_nbytes()
2576 nor->addr_nbytes = nor->info->addr_nbytes; in spi_nor_set_addr_nbytes()
2578 nor->addr_nbytes = 3; in spi_nor_set_addr_nbytes()
2581 if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) { in spi_nor_set_addr_nbytes()
2583 nor->addr_nbytes = 4; in spi_nor_set_addr_nbytes()
2586 if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) { in spi_nor_set_addr_nbytes()
2587 dev_dbg(nor->dev, "The number of address bytes is too large: %u\n", in spi_nor_set_addr_nbytes()
2588 nor->addr_nbytes); in spi_nor_set_addr_nbytes()
2593 if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES && in spi_nor_set_addr_nbytes()
2594 !(nor->flags & SNOR_F_HAS_4BAIT)) in spi_nor_set_addr_nbytes()
2595 spi_nor_set_4byte_opcodes(nor); in spi_nor_set_addr_nbytes()
2600 static int spi_nor_setup(struct spi_nor *nor, in spi_nor_setup() argument
2603 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_setup()
2613 if (nor->spimem) { in spi_nor_setup()
2619 spi_nor_spimem_adjust_hwcaps(nor, &shared_mask); in spi_nor_setup()
2628 dev_dbg(nor->dev, in spi_nor_setup()
2635 err = spi_nor_select_read(nor, shared_mask); in spi_nor_setup()
2637 dev_dbg(nor->dev, in spi_nor_setup()
2643 err = spi_nor_select_pp(nor, shared_mask); in spi_nor_setup()
2645 dev_dbg(nor->dev, in spi_nor_setup()
2651 err = spi_nor_select_erase(nor); in spi_nor_setup()
2653 dev_dbg(nor->dev, in spi_nor_setup()
2658 return spi_nor_set_addr_nbytes(nor); in spi_nor_setup()
2664 * @nor: pointer to a 'struct spi_nor'.
2666 static void spi_nor_manufacturer_init_params(struct spi_nor *nor) in spi_nor_manufacturer_init_params() argument
2668 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_manufacturer_init_params()
2669 nor->manufacturer->fixups->default_init) in spi_nor_manufacturer_init_params()
2670 nor->manufacturer->fixups->default_init(nor); in spi_nor_manufacturer_init_params()
2672 if (nor->info->fixups && nor->info->fixups->default_init) in spi_nor_manufacturer_init_params()
2673 nor->info->fixups->default_init(nor); in spi_nor_manufacturer_init_params()
2678 * settings based on nor->info->sfdp_flags. This method should be called only by
2683 * @nor: pointer to a 'struct spi_nor'.
2685 static void spi_nor_no_sfdp_init_params(struct spi_nor *nor) in spi_nor_no_sfdp_init_params() argument
2687 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_no_sfdp_init_params()
2689 const struct flash_info *info = nor->info; in spi_nor_no_sfdp_init_params()
2751 * spi_nor_init_flags() - Initialize NOR flags for settings that are not defined
2753 * @nor: pointer to a 'struct spi_nor'
2755 static void spi_nor_init_flags(struct spi_nor *nor) in spi_nor_init_flags() argument
2757 struct device_node *np = spi_nor_get_flash_node(nor); in spi_nor_init_flags()
2758 const u16 flags = nor->info->flags; in spi_nor_init_flags()
2761 nor->flags |= SNOR_F_BROKEN_RESET; in spi_nor_init_flags()
2764 nor->flags |= SNOR_F_NO_WP; in spi_nor_init_flags()
2767 nor->flags |= SNOR_F_SWP_IS_VOLATILE; in spi_nor_init_flags()
2770 nor->flags |= SNOR_F_HAS_LOCK; in spi_nor_init_flags()
2773 nor->flags |= SNOR_F_HAS_SR_TB; in spi_nor_init_flags()
2775 nor->flags |= SNOR_F_HAS_SR_TB_BIT6; in spi_nor_init_flags()
2779 nor->flags |= SNOR_F_HAS_4BIT_BP; in spi_nor_init_flags()
2781 nor->flags |= SNOR_F_HAS_SR_BP3_BIT6; in spi_nor_init_flags()
2784 if (flags & SPI_NOR_RWW && nor->params->n_banks > 1 && in spi_nor_init_flags()
2785 !nor->controller_ops) in spi_nor_init_flags()
2786 nor->flags |= SNOR_F_RWW; in spi_nor_init_flags()
2790 * spi_nor_init_fixup_flags() - Initialize NOR flags for settings that can not
2795 * @nor: pointer to a 'struct spi_nor'
2797 static void spi_nor_init_fixup_flags(struct spi_nor *nor) in spi_nor_init_fixup_flags() argument
2799 const u8 fixup_flags = nor->info->fixup_flags; in spi_nor_init_fixup_flags()
2802 nor->flags |= SNOR_F_4B_OPCODES; in spi_nor_init_fixup_flags()
2805 nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE; in spi_nor_init_fixup_flags()
2810 * @nor: pointer to a 'struct spi_nor'
2816 static int spi_nor_late_init_params(struct spi_nor *nor) in spi_nor_late_init_params() argument
2818 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_late_init_params()
2821 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_late_init_params()
2822 nor->manufacturer->fixups->late_init) { in spi_nor_late_init_params()
2823 ret = nor->manufacturer->fixups->late_init(nor); in spi_nor_late_init_params()
2829 spi_nor_init_flags(nor); in spi_nor_late_init_params()
2831 if (nor->info->fixups && nor->info->fixups->late_init) { in spi_nor_late_init_params()
2832 ret = nor->info->fixups->late_init(nor); in spi_nor_late_init_params()
2837 if (!nor->params->die_erase_opcode) in spi_nor_late_init_params()
2838 nor->params->die_erase_opcode = SPINOR_OP_CHIP_ERASE; in spi_nor_late_init_params()
2844 spi_nor_init_fixup_flags(nor); in spi_nor_late_init_params()
2847 * NOR protection support. When locking_ops are not provided, we pick in spi_nor_late_init_params()
2850 if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops) in spi_nor_late_init_params()
2851 spi_nor_init_default_locking_ops(nor); in spi_nor_late_init_params()
2862 * @nor: pointer to a 'struct spi_nor'.
2867 static void spi_nor_sfdp_init_params_deprecated(struct spi_nor *nor) in spi_nor_sfdp_init_params_deprecated() argument
2871 memcpy(&sfdp_params, nor->params, sizeof(sfdp_params)); in spi_nor_sfdp_init_params_deprecated()
2873 if (spi_nor_parse_sfdp(nor)) { in spi_nor_sfdp_init_params_deprecated()
2874 memcpy(nor->params, &sfdp_params, sizeof(*nor->params)); in spi_nor_sfdp_init_params_deprecated()
2875 nor->flags &= ~SNOR_F_4B_OPCODES; in spi_nor_sfdp_init_params_deprecated()
2882 * @nor: pointer to a 'struct spi_nor'.
2888 static void spi_nor_init_params_deprecated(struct spi_nor *nor) in spi_nor_init_params_deprecated() argument
2890 spi_nor_no_sfdp_init_params(nor); in spi_nor_init_params_deprecated()
2892 spi_nor_manufacturer_init_params(nor); in spi_nor_init_params_deprecated()
2894 if (nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ | in spi_nor_init_params_deprecated()
2898 spi_nor_sfdp_init_params_deprecated(nor); in spi_nor_init_params_deprecated()
2905 * @nor: pointer to a 'struct spi_nor'.
2907 static void spi_nor_init_default_params(struct spi_nor *nor) in spi_nor_init_default_params() argument
2909 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_init_default_params()
2910 const struct flash_info *info = nor->info; in spi_nor_init_default_params()
2911 struct device_node *np = spi_nor_get_flash_node(nor); in spi_nor_init_default_params()
2917 nor->flags |= SNOR_F_HAS_16BIT_SR; in spi_nor_init_default_params()
2919 /* Set SPI NOR sizes. */ in spi_nor_init_default_params()
2954 * @nor: pointer to a 'struct spi_nor'.
2960 * based on nor->info data:
2989 static int spi_nor_init_params(struct spi_nor *nor) in spi_nor_init_params() argument
2993 nor->params = devm_kzalloc(nor->dev, sizeof(*nor->params), GFP_KERNEL); in spi_nor_init_params()
2994 if (!nor->params) in spi_nor_init_params()
2997 spi_nor_init_default_params(nor); in spi_nor_init_params()
2999 if (spi_nor_needs_sfdp(nor)) { in spi_nor_init_params()
3000 ret = spi_nor_parse_sfdp(nor); in spi_nor_init_params()
3002 …dev_err(nor->dev, "BFPT parsing failed. Please consider using SPI_NOR_SKIP_SFDP when declaring the… in spi_nor_init_params()
3005 } else if (nor->info->no_sfdp_flags & SPI_NOR_SKIP_SFDP) { in spi_nor_init_params()
3006 spi_nor_no_sfdp_init_params(nor); in spi_nor_init_params()
3008 spi_nor_init_params_deprecated(nor); in spi_nor_init_params()
3011 ret = spi_nor_late_init_params(nor); in spi_nor_init_params()
3015 if (WARN_ON(!is_power_of_2(nor->params->page_size))) in spi_nor_init_params()
3022 * @nor: pointer to a 'struct spi_nor'
3027 static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) in spi_nor_set_octal_dtr() argument
3031 if (!nor->params->set_octal_dtr) in spi_nor_set_octal_dtr()
3034 if (!(nor->read_proto == SNOR_PROTO_8_8_8_DTR && in spi_nor_set_octal_dtr()
3035 nor->write_proto == SNOR_PROTO_8_8_8_DTR)) in spi_nor_set_octal_dtr()
3038 if (!(nor->flags & SNOR_F_IO_MODE_EN_VOLATILE)) in spi_nor_set_octal_dtr()
3041 ret = nor->params->set_octal_dtr(nor, enable); in spi_nor_set_octal_dtr()
3046 nor->reg_proto = SNOR_PROTO_8_8_8_DTR; in spi_nor_set_octal_dtr()
3048 nor->reg_proto = SNOR_PROTO_1_1_1; in spi_nor_set_octal_dtr()
3055 * @nor: pointer to a 'struct spi_nor'
3059 static int spi_nor_quad_enable(struct spi_nor *nor) in spi_nor_quad_enable() argument
3061 if (!nor->params->quad_enable) in spi_nor_quad_enable()
3064 if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || in spi_nor_quad_enable()
3065 spi_nor_get_protocol_width(nor->write_proto) == 4)) in spi_nor_quad_enable()
3068 return nor->params->quad_enable(nor); in spi_nor_quad_enable()
3073 * @nor: pointer to a 'struct spi_nor'.
3078 int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode() argument
3080 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_set_4byte_addr_mode()
3091 WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET, in spi_nor_set_4byte_addr_mode()
3095 ret = params->set_4byte_addr_mode(nor, enable); in spi_nor_set_4byte_addr_mode()
3110 static int spi_nor_init(struct spi_nor *nor) in spi_nor_init() argument
3114 err = spi_nor_set_octal_dtr(nor, true); in spi_nor_init()
3116 dev_dbg(nor->dev, "octal mode not supported\n"); in spi_nor_init()
3120 err = spi_nor_quad_enable(nor); in spi_nor_init()
3122 dev_dbg(nor->dev, "quad mode not supported\n"); in spi_nor_init()
3127 * Some SPI NOR flashes are write protected by default after a power-on in spi_nor_init()
3138 nor->flags & SNOR_F_SWP_IS_VOLATILE)) in spi_nor_init()
3139 spi_nor_try_unlock_all(nor); in spi_nor_init()
3141 if (nor->addr_nbytes == 4 && in spi_nor_init()
3142 nor->read_proto != SNOR_PROTO_8_8_8_DTR && in spi_nor_init()
3143 !(nor->flags & SNOR_F_4B_OPCODES)) in spi_nor_init()
3144 return spi_nor_set_4byte_addr_mode(nor, true); in spi_nor_init()
3151 * @nor: pointer to 'struct spi_nor'
3164 static void spi_nor_soft_reset(struct spi_nor *nor) in spi_nor_soft_reset() argument
3171 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_soft_reset()
3173 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_soft_reset()
3176 dev_warn(nor->dev, "Software reset failed: %d\n", ret); in spi_nor_soft_reset()
3182 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_soft_reset()
3184 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_soft_reset()
3186 dev_warn(nor->dev, "Software reset failed: %d\n", ret); in spi_nor_soft_reset()
3201 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_suspend() local
3205 ret = spi_nor_set_octal_dtr(nor, false); in spi_nor_suspend()
3207 dev_err(nor->dev, "suspend() failed\n"); in spi_nor_suspend()
3215 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_resume() local
3216 struct device *dev = nor->dev; in spi_nor_resume()
3219 /* re-initialize the nor chip */ in spi_nor_resume()
3220 ret = spi_nor_init(nor); in spi_nor_resume()
3228 struct spi_nor *nor = mtd_to_spi_nor(master); in spi_nor_get_device() local
3231 if (nor->spimem) in spi_nor_get_device()
3232 dev = nor->spimem->spi->controller->dev.parent; in spi_nor_get_device()
3234 dev = nor->dev; in spi_nor_get_device()
3245 struct spi_nor *nor = mtd_to_spi_nor(master); in spi_nor_put_device() local
3248 if (nor->spimem) in spi_nor_put_device()
3249 dev = nor->spimem->spi->controller->dev.parent; in spi_nor_put_device()
3251 dev = nor->dev; in spi_nor_put_device()
3256 static void spi_nor_restore(struct spi_nor *nor) in spi_nor_restore() argument
3261 if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && in spi_nor_restore()
3262 nor->flags & SNOR_F_BROKEN_RESET) { in spi_nor_restore()
3263 ret = spi_nor_set_4byte_addr_mode(nor, false); in spi_nor_restore()
3270 dev_err(nor->dev, "Failed to exit 4-byte address mode, err = %d\n", ret); in spi_nor_restore()
3273 if (nor->flags & SNOR_F_SOFT_RESET) in spi_nor_restore()
3274 spi_nor_soft_reset(nor); in spi_nor_restore()
3277 static const struct flash_info *spi_nor_match_name(struct spi_nor *nor, in spi_nor_match_name() argument
3286 nor->manufacturer = manufacturers[i]; in spi_nor_match_name()
3295 static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, in spi_nor_get_flash_info() argument
3301 info = spi_nor_match_name(nor, name); in spi_nor_get_flash_info()
3310 jinfo = spi_nor_detect(nor); in spi_nor_get_flash_info()
3319 dev_warn(nor->dev, "found %s, expected %s\n", in spi_nor_get_flash_info()
3346 static int spi_nor_set_mtd_eraseregions(struct spi_nor *nor) in spi_nor_set_mtd_eraseregions() argument
3348 const struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_set_mtd_eraseregions()
3351 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_eraseregions()
3354 mtd_region = devm_kcalloc(nor->dev, map->n_regions, sizeof(*mtd_region), in spi_nor_set_mtd_eraseregions()
3376 static int spi_nor_set_mtd_info(struct spi_nor *nor) in spi_nor_set_mtd_info() argument
3378 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_info()
3379 struct device *dev = nor->dev; in spi_nor_set_mtd_info()
3381 spi_nor_set_mtd_locking_ops(nor); in spi_nor_set_mtd_info()
3382 spi_nor_set_mtd_otp_ops(nor); in spi_nor_set_mtd_info()
3389 /* Unset BIT_WRITEABLE to enable JFFS2 write buffer for ECC'd NOR */ in spi_nor_set_mtd_info()
3390 if (nor->flags & SNOR_F_ECC) in spi_nor_set_mtd_info()
3392 if (nor->info->flags & SPI_NOR_NO_ERASE) in spi_nor_set_mtd_info()
3396 mtd->writesize = nor->params->writesize; in spi_nor_set_mtd_info()
3397 mtd->writebufsize = nor->params->page_size; in spi_nor_set_mtd_info()
3398 mtd->size = nor->params->size; in spi_nor_set_mtd_info()
3408 if (!spi_nor_has_uniform_erase(nor)) in spi_nor_set_mtd_info()
3409 return spi_nor_set_mtd_eraseregions(nor); in spi_nor_set_mtd_info()
3414 static int spi_nor_hw_reset(struct spi_nor *nor) in spi_nor_hw_reset() argument
3418 reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW); in spi_nor_hw_reset()
3435 int spi_nor_scan(struct spi_nor *nor, const char *name, in spi_nor_scan() argument
3439 struct device *dev = nor->dev; in spi_nor_scan()
3442 ret = spi_nor_check(nor); in spi_nor_scan()
3447 nor->reg_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3448 nor->read_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3449 nor->write_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3455 * nor->params->page_size turns out to be greater than PAGE_SIZE (which in spi_nor_scan()
3456 * shouldn't happen before long since NOR pages are usually less in spi_nor_scan()
3459 nor->bouncebuf_size = PAGE_SIZE; in spi_nor_scan()
3460 nor->bouncebuf = devm_kmalloc(dev, nor->bouncebuf_size, in spi_nor_scan()
3462 if (!nor->bouncebuf) in spi_nor_scan()
3465 ret = spi_nor_hw_reset(nor); in spi_nor_scan()
3469 info = spi_nor_get_flash_info(nor, name); in spi_nor_scan()
3473 nor->info = info; in spi_nor_scan()
3475 mutex_init(&nor->lock); in spi_nor_scan()
3478 ret = spi_nor_init_params(nor); in spi_nor_scan()
3482 if (spi_nor_use_parallel_locking(nor)) in spi_nor_scan()
3483 init_waitqueue_head(&nor->rww.wait); in spi_nor_scan()
3492 ret = spi_nor_setup(nor, hwcaps); in spi_nor_scan()
3497 ret = spi_nor_init(nor); in spi_nor_scan()
3502 ret = spi_nor_set_mtd_info(nor); in spi_nor_scan()
3507 SPI_NOR_MAX_ID_LEN, nor->id); in spi_nor_scan()
3513 static int spi_nor_create_read_dirmap(struct spi_nor *nor) in spi_nor_create_read_dirmap() argument
3516 .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), in spi_nor_create_read_dirmap()
3517 SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), in spi_nor_create_read_dirmap()
3518 SPI_MEM_OP_DUMMY(nor->read_dummy, 0), in spi_nor_create_read_dirmap()
3521 .length = nor->params->size, in spi_nor_create_read_dirmap()
3525 spi_nor_spimem_setup_op(nor, op, nor->read_proto); in spi_nor_create_read_dirmap()
3528 op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8; in spi_nor_create_read_dirmap()
3529 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_create_read_dirmap()
3537 op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); in spi_nor_create_read_dirmap()
3539 nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, in spi_nor_create_read_dirmap()
3541 return PTR_ERR_OR_ZERO(nor->dirmap.rdesc); in spi_nor_create_read_dirmap()
3544 static int spi_nor_create_write_dirmap(struct spi_nor *nor) in spi_nor_create_write_dirmap() argument
3547 .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), in spi_nor_create_write_dirmap()
3548 SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), in spi_nor_create_write_dirmap()
3552 .length = nor->params->size, in spi_nor_create_write_dirmap()
3556 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in spi_nor_create_write_dirmap()
3559 spi_nor_spimem_setup_op(nor, op, nor->write_proto); in spi_nor_create_write_dirmap()
3566 op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto); in spi_nor_create_write_dirmap()
3568 nor->dirmap.wdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, in spi_nor_create_write_dirmap()
3570 return PTR_ERR_OR_ZERO(nor->dirmap.wdesc); in spi_nor_create_write_dirmap()
3577 struct spi_nor *nor; in spi_nor_probe() local
3586 nor = devm_kzalloc(&spi->dev, sizeof(*nor), GFP_KERNEL); in spi_nor_probe()
3587 if (!nor) in spi_nor_probe()
3590 nor->spimem = spimem; in spi_nor_probe()
3591 nor->dev = &spi->dev; in spi_nor_probe()
3592 spi_nor_set_flash_node(nor, spi->dev.of_node); in spi_nor_probe()
3594 spi_mem_set_drvdata(spimem, nor); in spi_nor_probe()
3597 nor->mtd.name = data->name; in spi_nor_probe()
3599 if (!nor->mtd.name) in spi_nor_probe()
3600 nor->mtd.name = spi_mem_get_name(spimem); in spi_nor_probe()
3610 else if (!strcmp(spi->modalias, "spi-nor")) in spi_nor_probe()
3615 ret = spi_nor_scan(nor, flash_name, &hwcaps); in spi_nor_probe()
3619 spi_nor_debugfs_register(nor); in spi_nor_probe()
3624 * a NOR we don't end up with buffer overflows. in spi_nor_probe()
3626 if (nor->params->page_size > PAGE_SIZE) { in spi_nor_probe()
3627 nor->bouncebuf_size = nor->params->page_size; in spi_nor_probe()
3628 devm_kfree(nor->dev, nor->bouncebuf); in spi_nor_probe()
3629 nor->bouncebuf = devm_kmalloc(nor->dev, in spi_nor_probe()
3630 nor->bouncebuf_size, in spi_nor_probe()
3632 if (!nor->bouncebuf) in spi_nor_probe()
3636 ret = spi_nor_create_read_dirmap(nor); in spi_nor_probe()
3640 ret = spi_nor_create_write_dirmap(nor); in spi_nor_probe()
3644 return mtd_device_register(&nor->mtd, data ? data->parts : NULL, in spi_nor_probe()
3650 struct spi_nor *nor = spi_mem_get_drvdata(spimem); in spi_nor_remove() local
3652 spi_nor_restore(nor); in spi_nor_remove()
3655 return mtd_device_unregister(&nor->mtd); in spi_nor_remove()
3660 struct spi_nor *nor = spi_mem_get_drvdata(spimem); in spi_nor_shutdown() local
3662 spi_nor_restore(nor); in spi_nor_shutdown()
3671 * encourage new users to add support to the spi-nor library, and simply bind
3672 * against a generic string here (e.g., "jedec,spi-nor").
3679 * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
3683 {"spi-nor"},
3687 * them with "spi-nor" in platform data.
3692 * Entries that were used in DTs without "jedec,spi-nor" fallback and
3724 * Generic compatibility for SPI NOR that can be identified by the
3727 { .compatible = "jedec,spi-nor" },
3740 .name = "spi-nor",
3767 MODULE_DESCRIPTION("framework for SPI NOR");