Lines Matching full:nor
18 #include <linux/mtd/spi-nor.h>
51 * @nor: pointer to a 'struct spi_nor'
59 static u8 spi_nor_get_cmd_ext(const struct spi_nor *nor, in spi_nor_get_cmd_ext() argument
62 switch (nor->cmd_ext_type) { in spi_nor_get_cmd_ext()
70 dev_err(nor->dev, "Unknown command extension type\n"); in spi_nor_get_cmd_ext()
77 * @nor: pointer to a 'struct spi_nor'
82 void spi_nor_spimem_setup_op(const struct spi_nor *nor, in spi_nor_spimem_setup_op() argument
103 * something like 4S-4D-4D, but SPI NOR can't. So, set all 4 in spi_nor_spimem_setup_op()
114 ext = spi_nor_get_cmd_ext(nor, op); in spi_nor_spimem_setup_op()
119 if (proto == SNOR_PROTO_8_8_8_DTR && nor->flags & SNOR_F_SWAP16) in spi_nor_spimem_setup_op()
126 * @nor: pointer to 'struct spi_nor'
133 static bool spi_nor_spimem_bounce(struct spi_nor *nor, struct spi_mem_op *op) in spi_nor_spimem_bounce() argument
138 if (op->data.nbytes > nor->bouncebuf_size) in spi_nor_spimem_bounce()
139 op->data.nbytes = nor->bouncebuf_size; in spi_nor_spimem_bounce()
140 op->data.buf.in = nor->bouncebuf; in spi_nor_spimem_bounce()
149 * @nor: pointer to 'struct spi_nor'
154 static int spi_nor_spimem_exec_op(struct spi_nor *nor, struct spi_mem_op *op) in spi_nor_spimem_exec_op() argument
158 error = spi_mem_adjust_op_size(nor->spimem, op); in spi_nor_spimem_exec_op()
162 return spi_mem_exec_op(nor->spimem, op); in spi_nor_spimem_exec_op()
165 int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode, in spi_nor_controller_ops_read_reg() argument
168 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_read_reg()
171 return nor->controller_ops->read_reg(nor, opcode, buf, len); in spi_nor_controller_ops_read_reg()
174 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode, in spi_nor_controller_ops_write_reg() argument
177 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_write_reg()
180 return nor->controller_ops->write_reg(nor, opcode, buf, len); in spi_nor_controller_ops_write_reg()
183 static int spi_nor_controller_ops_erase(struct spi_nor *nor, loff_t offs) in spi_nor_controller_ops_erase() argument
185 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_erase()
188 return nor->controller_ops->erase(nor, offs); in spi_nor_controller_ops_erase()
194 * @nor: pointer to 'struct spi_nor'
201 static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from, in spi_nor_spimem_read_data() argument
205 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), in spi_nor_spimem_read_data()
206 SPI_MEM_OP_ADDR(nor->addr_nbytes, from, 0), in spi_nor_spimem_read_data()
207 SPI_MEM_OP_DUMMY(nor->read_dummy, 0), in spi_nor_spimem_read_data()
213 spi_nor_spimem_setup_op(nor, &op, nor->read_proto); in spi_nor_spimem_read_data()
216 op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; in spi_nor_spimem_read_data()
217 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_spimem_read_data()
220 usebouncebuf = spi_nor_spimem_bounce(nor, &op); in spi_nor_spimem_read_data()
222 if (nor->dirmap.rdesc) { in spi_nor_spimem_read_data()
223 nbytes = spi_mem_dirmap_read(nor->dirmap.rdesc, op.addr.val, in spi_nor_spimem_read_data()
226 error = spi_nor_spimem_exec_op(nor, &op); in spi_nor_spimem_read_data()
240 * @nor: pointer to 'struct spi_nor'
247 ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, u8 *buf) in spi_nor_read_data() argument
249 if (nor->spimem) in spi_nor_read_data()
250 return spi_nor_spimem_read_data(nor, from, len, buf); in spi_nor_read_data()
252 return nor->controller_ops->read(nor, from, len, buf); in spi_nor_read_data()
258 * @nor: pointer to 'struct spi_nor'
265 static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to, in spi_nor_spimem_write_data() argument
269 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), in spi_nor_spimem_write_data()
270 SPI_MEM_OP_ADDR(nor->addr_nbytes, to, 0), in spi_nor_spimem_write_data()
276 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in spi_nor_spimem_write_data()
279 spi_nor_spimem_setup_op(nor, &op, nor->write_proto); in spi_nor_spimem_write_data()
281 if (spi_nor_spimem_bounce(nor, &op)) in spi_nor_spimem_write_data()
282 memcpy(nor->bouncebuf, buf, op.data.nbytes); in spi_nor_spimem_write_data()
284 if (nor->dirmap.wdesc) { in spi_nor_spimem_write_data()
285 nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc, op.addr.val, in spi_nor_spimem_write_data()
288 error = spi_nor_spimem_exec_op(nor, &op); in spi_nor_spimem_write_data()
299 * @nor: pointer to 'struct spi_nor'
306 ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len, in spi_nor_write_data() argument
309 if (nor->spimem) in spi_nor_write_data()
310 return spi_nor_spimem_write_data(nor, to, len, buf); in spi_nor_write_data()
312 return nor->controller_ops->write(nor, to, len, buf); in spi_nor_write_data()
318 * @nor: pointer to 'struct spi_nor'.
324 int spi_nor_read_any_reg(struct spi_nor *nor, struct spi_mem_op *op, in spi_nor_read_any_reg() argument
327 if (!nor->spimem) in spi_nor_read_any_reg()
330 spi_nor_spimem_setup_op(nor, op, proto); in spi_nor_read_any_reg()
331 return spi_nor_spimem_exec_op(nor, op); in spi_nor_read_any_reg()
337 * @nor: pointer to 'struct spi_nor'
346 int spi_nor_write_any_volatile_reg(struct spi_nor *nor, struct spi_mem_op *op, in spi_nor_write_any_volatile_reg() argument
351 if (!nor->spimem) in spi_nor_write_any_volatile_reg()
354 ret = spi_nor_write_enable(nor); in spi_nor_write_any_volatile_reg()
357 spi_nor_spimem_setup_op(nor, op, proto); in spi_nor_write_any_volatile_reg()
358 return spi_nor_spimem_exec_op(nor, op); in spi_nor_write_any_volatile_reg()
363 * @nor: pointer to 'struct spi_nor'.
367 int spi_nor_write_enable(struct spi_nor *nor) in spi_nor_write_enable() argument
371 if (nor->spimem) { in spi_nor_write_enable()
374 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_enable()
376 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_enable()
378 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREN, in spi_nor_write_enable()
383 dev_dbg(nor->dev, "error %d on Write Enable\n", ret); in spi_nor_write_enable()
390 * @nor: pointer to 'struct spi_nor'.
394 int spi_nor_write_disable(struct spi_nor *nor) in spi_nor_write_disable() argument
398 if (nor->spimem) { in spi_nor_write_disable()
401 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_disable()
403 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_disable()
405 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRDI, in spi_nor_write_disable()
410 dev_dbg(nor->dev, "error %d on Write Disable\n", ret); in spi_nor_write_disable()
417 * @nor: pointer to 'struct spi_nor'.
428 int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ndummy, u8 *id, in spi_nor_read_id() argument
433 if (nor->spimem) { in spi_nor_read_id()
437 spi_nor_spimem_setup_op(nor, &op, proto); in spi_nor_read_id()
438 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_id()
440 ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id, in spi_nor_read_id()
448 * @nor: pointer to 'struct spi_nor'.
454 int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) in spi_nor_read_sr() argument
458 if (nor->spimem) { in spi_nor_read_sr()
461 if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) { in spi_nor_read_sr()
462 op.addr.nbytes = nor->params->rdsr_addr_nbytes; in spi_nor_read_sr()
463 op.dummy.nbytes = nor->params->rdsr_dummy; in spi_nor_read_sr()
471 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_sr()
473 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_sr()
475 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr, in spi_nor_read_sr()
480 dev_dbg(nor->dev, "error %d reading SR\n", ret); in spi_nor_read_sr()
488 * @nor: pointer to 'struct spi_nor'
494 int spi_nor_read_cr(struct spi_nor *nor, u8 *cr) in spi_nor_read_cr() argument
498 if (nor->spimem) { in spi_nor_read_cr()
501 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_cr()
503 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_cr()
505 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDCR, cr, in spi_nor_read_cr()
510 dev_dbg(nor->dev, "error %d reading CR\n", ret); in spi_nor_read_cr()
519 * @nor: pointer to 'struct spi_nor'.
525 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
529 if (nor->spimem) { in spi_nor_set_4byte_addr_mode_en4b_ex4b()
532 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
534 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
536 ret = spi_nor_controller_ops_write_reg(nor, in spi_nor_set_4byte_addr_mode_en4b_ex4b()
543 dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
552 * @nor: pointer to 'struct spi_nor'.
558 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
562 ret = spi_nor_write_enable(nor); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
566 ret = spi_nor_set_4byte_addr_mode_en4b_ex4b(nor, enable); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
570 return spi_nor_write_disable(nor); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
576 * @nor: pointer to 'struct spi_nor'.
587 int spi_nor_set_4byte_addr_mode_brwr(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode_brwr() argument
591 nor->bouncebuf[0] = enable << 7; in spi_nor_set_4byte_addr_mode_brwr()
593 if (nor->spimem) { in spi_nor_set_4byte_addr_mode_brwr()
594 struct spi_mem_op op = SPI_NOR_BRWR_OP(nor->bouncebuf); in spi_nor_set_4byte_addr_mode_brwr()
596 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_set_4byte_addr_mode_brwr()
598 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_set_4byte_addr_mode_brwr()
600 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_BRWR, in spi_nor_set_4byte_addr_mode_brwr()
601 nor->bouncebuf, 1); in spi_nor_set_4byte_addr_mode_brwr()
605 dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); in spi_nor_set_4byte_addr_mode_brwr()
613 * @nor: pointer to 'struct spi_nor'.
617 int spi_nor_sr_ready(struct spi_nor *nor) in spi_nor_sr_ready() argument
621 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr_ready()
625 return !(nor->bouncebuf[0] & SR_WIP); in spi_nor_sr_ready()
630 * @nor: pointer to 'struct spi_nor'.
634 static bool spi_nor_use_parallel_locking(struct spi_nor *nor) in spi_nor_use_parallel_locking() argument
636 return nor->flags & SNOR_F_RWW; in spi_nor_use_parallel_locking()
640 static int spi_nor_rww_start_rdst(struct spi_nor *nor) in spi_nor_rww_start_rdst() argument
642 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_rdst()
644 guard(mutex)(&nor->lock); in spi_nor_rww_start_rdst()
655 static void spi_nor_rww_end_rdst(struct spi_nor *nor) in spi_nor_rww_end_rdst() argument
657 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_rdst()
659 guard(mutex)(&nor->lock); in spi_nor_rww_end_rdst()
665 static int spi_nor_lock_rdst(struct spi_nor *nor) in spi_nor_lock_rdst() argument
667 if (spi_nor_use_parallel_locking(nor)) in spi_nor_lock_rdst()
668 return spi_nor_rww_start_rdst(nor); in spi_nor_lock_rdst()
673 static void spi_nor_unlock_rdst(struct spi_nor *nor) in spi_nor_unlock_rdst() argument
675 if (spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_rdst()
676 spi_nor_rww_end_rdst(nor); in spi_nor_unlock_rdst()
677 wake_up(&nor->rww.wait); in spi_nor_unlock_rdst()
683 * @nor: pointer to 'struct spi_nor'.
687 static int spi_nor_ready(struct spi_nor *nor) in spi_nor_ready() argument
691 ret = spi_nor_lock_rdst(nor); in spi_nor_ready()
696 if (nor->params->ready) in spi_nor_ready()
697 ret = nor->params->ready(nor); in spi_nor_ready()
699 ret = spi_nor_sr_ready(nor); in spi_nor_ready()
701 spi_nor_unlock_rdst(nor); in spi_nor_ready()
709 * @nor: pointer to "struct spi_nor".
714 static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, in spi_nor_wait_till_ready_with_timeout() argument
726 ret = spi_nor_ready(nor); in spi_nor_wait_till_ready_with_timeout()
735 dev_dbg(nor->dev, "flash operation timed out\n"); in spi_nor_wait_till_ready_with_timeout()
743 * @nor: pointer to "struct spi_nor".
747 int spi_nor_wait_till_ready(struct spi_nor *nor) in spi_nor_wait_till_ready() argument
749 return spi_nor_wait_till_ready_with_timeout(nor, in spi_nor_wait_till_ready()
755 * @nor: pointer to 'struct spi_nor'.
759 int spi_nor_global_block_unlock(struct spi_nor *nor) in spi_nor_global_block_unlock() argument
763 ret = spi_nor_write_enable(nor); in spi_nor_global_block_unlock()
767 if (nor->spimem) { in spi_nor_global_block_unlock()
770 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_global_block_unlock()
772 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_global_block_unlock()
774 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_GBULK, in spi_nor_global_block_unlock()
779 dev_dbg(nor->dev, "error %d on Global Block Unlock\n", ret); in spi_nor_global_block_unlock()
783 return spi_nor_wait_till_ready(nor); in spi_nor_global_block_unlock()
788 * @nor: pointer to 'struct spi_nor'.
794 int spi_nor_write_sr(struct spi_nor *nor, const u8 *sr, size_t len) in spi_nor_write_sr() argument
798 ret = spi_nor_write_enable(nor); in spi_nor_write_sr()
802 if (nor->spimem) { in spi_nor_write_sr()
805 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_sr()
807 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_sr()
809 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR, sr, in spi_nor_write_sr()
814 dev_dbg(nor->dev, "error %d writing SR\n", ret); in spi_nor_write_sr()
818 return spi_nor_wait_till_ready(nor); in spi_nor_write_sr()
824 * @nor: pointer to a 'struct spi_nor'.
829 static int spi_nor_write_sr1_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_sr1_and_check() argument
833 nor->bouncebuf[0] = sr1; in spi_nor_write_sr1_and_check()
835 ret = spi_nor_write_sr(nor, nor->bouncebuf, 1); in spi_nor_write_sr1_and_check()
839 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_write_sr1_and_check()
843 if (nor->bouncebuf[0] != sr1) { in spi_nor_write_sr1_and_check()
844 dev_dbg(nor->dev, "SR1: read back test failed\n"); in spi_nor_write_sr1_and_check()
856 * @nor: pointer to a 'struct spi_nor'.
861 static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_16bit_sr_and_check() argument
864 u8 *sr_cr = nor->bouncebuf; in spi_nor_write_16bit_sr_and_check()
868 if (!(nor->flags & SNOR_F_NO_READ_CR)) { in spi_nor_write_16bit_sr_and_check()
869 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_sr_and_check()
872 } else if (spi_nor_get_protocol_width(nor->read_proto) == 4 && in spi_nor_write_16bit_sr_and_check()
873 spi_nor_get_protocol_width(nor->write_proto) == 4 && in spi_nor_write_16bit_sr_and_check()
874 nor->params->quad_enable) { in spi_nor_write_16bit_sr_and_check()
882 * consequence of the nor->params->quad_enable() call. in spi_nor_write_16bit_sr_and_check()
896 ret = spi_nor_write_sr(nor, sr_cr, 2); in spi_nor_write_16bit_sr_and_check()
900 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_sr_and_check()
905 dev_dbg(nor->dev, "SR: Read back test failed\n"); in spi_nor_write_16bit_sr_and_check()
909 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_write_16bit_sr_and_check()
914 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_sr_and_check()
919 dev_dbg(nor->dev, "CR: read back test failed\n"); in spi_nor_write_16bit_sr_and_check()
931 * @nor: pointer to a 'struct spi_nor'.
936 int spi_nor_write_16bit_cr_and_check(struct spi_nor *nor, u8 cr) in spi_nor_write_16bit_cr_and_check() argument
939 u8 *sr_cr = nor->bouncebuf; in spi_nor_write_16bit_cr_and_check()
943 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_cr_and_check()
949 ret = spi_nor_write_sr(nor, sr_cr, 2); in spi_nor_write_16bit_cr_and_check()
955 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_cr_and_check()
960 dev_dbg(nor->dev, "SR: Read back test failed\n"); in spi_nor_write_16bit_cr_and_check()
964 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_write_16bit_cr_and_check()
967 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_cr_and_check()
972 dev_dbg(nor->dev, "CR: read back test failed\n"); in spi_nor_write_16bit_cr_and_check()
983 * @nor: pointer to a 'struct spi_nor'.
988 int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_sr_and_check() argument
990 if (nor->flags & SNOR_F_HAS_16BIT_SR) in spi_nor_write_sr_and_check()
991 return spi_nor_write_16bit_sr_and_check(nor, sr1); in spi_nor_write_sr_and_check()
993 return spi_nor_write_sr1_and_check(nor, sr1); in spi_nor_write_sr_and_check()
999 * @nor: pointer to 'struct spi_nor'.
1004 static int spi_nor_write_sr2(struct spi_nor *nor, const u8 *sr2) in spi_nor_write_sr2() argument
1008 ret = spi_nor_write_enable(nor); in spi_nor_write_sr2()
1012 if (nor->spimem) { in spi_nor_write_sr2()
1015 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_sr2()
1017 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_sr2()
1019 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR2, in spi_nor_write_sr2()
1024 dev_dbg(nor->dev, "error %d writing SR2\n", ret); in spi_nor_write_sr2()
1028 return spi_nor_wait_till_ready(nor); in spi_nor_write_sr2()
1034 * @nor: pointer to 'struct spi_nor'.
1040 static int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2) in spi_nor_read_sr2() argument
1044 if (nor->spimem) { in spi_nor_read_sr2()
1047 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_sr2()
1049 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_sr2()
1051 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR2, sr2, in spi_nor_read_sr2()
1056 dev_dbg(nor->dev, "error %d reading SR2\n", ret); in spi_nor_read_sr2()
1063 * @nor: pointer to 'struct spi_nor'.
1069 static int spi_nor_erase_die(struct spi_nor *nor, loff_t addr, size_t die_size) in spi_nor_erase_die() argument
1071 bool multi_die = nor->mtd.size != die_size; in spi_nor_erase_die()
1074 dev_dbg(nor->dev, " %lldKiB\n", (long long)(die_size >> 10)); in spi_nor_erase_die()
1076 if (nor->spimem) { in spi_nor_erase_die()
1078 SPI_NOR_DIE_ERASE_OP(nor->params->die_erase_opcode, in spi_nor_erase_die()
1079 nor->addr_nbytes, addr, multi_die); in spi_nor_erase_die()
1081 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_erase_die()
1083 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_erase_die()
1088 ret = spi_nor_controller_ops_write_reg(nor, in spi_nor_erase_die()
1094 dev_dbg(nor->dev, "error %d erasing chip\n", ret); in spi_nor_erase_die()
1158 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor) in spi_nor_has_uniform_erase() argument
1160 return !!nor->params->erase_map.uniform_region.erase_mask; in spi_nor_has_uniform_erase()
1163 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) in spi_nor_set_4byte_opcodes() argument
1165 nor->read_opcode = spi_nor_convert_3to4_read(nor->read_opcode); in spi_nor_set_4byte_opcodes()
1166 nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode); in spi_nor_set_4byte_opcodes()
1167 nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode); in spi_nor_set_4byte_opcodes()
1169 if (!spi_nor_has_uniform_erase(nor)) { in spi_nor_set_4byte_opcodes()
1170 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_set_4byte_opcodes()
1182 static int spi_nor_prep(struct spi_nor *nor) in spi_nor_prep() argument
1186 if (nor->controller_ops && nor->controller_ops->prepare) in spi_nor_prep()
1187 ret = nor->controller_ops->prepare(nor); in spi_nor_prep()
1192 static void spi_nor_unprep(struct spi_nor *nor) in spi_nor_unprep() argument
1194 if (nor->controller_ops && nor->controller_ops->unprepare) in spi_nor_unprep()
1195 nor->controller_ops->unprepare(nor); in spi_nor_unprep()
1207 static bool spi_nor_rww_start_io(struct spi_nor *nor) in spi_nor_rww_start_io() argument
1209 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_io()
1211 guard(mutex)(&nor->lock); in spi_nor_rww_start_io()
1221 static void spi_nor_rww_end_io(struct spi_nor *nor) in spi_nor_rww_end_io() argument
1223 guard(mutex)(&nor->lock); in spi_nor_rww_end_io()
1224 nor->rww.ongoing_io = false; in spi_nor_rww_end_io()
1227 static int spi_nor_lock_device(struct spi_nor *nor) in spi_nor_lock_device() argument
1229 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_lock_device()
1232 return wait_event_killable(nor->rww.wait, spi_nor_rww_start_io(nor)); in spi_nor_lock_device()
1235 static void spi_nor_unlock_device(struct spi_nor *nor) in spi_nor_unlock_device() argument
1237 if (spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_device()
1238 spi_nor_rww_end_io(nor); in spi_nor_unlock_device()
1239 wake_up(&nor->rww.wait); in spi_nor_unlock_device()
1244 static bool spi_nor_rww_start_exclusive(struct spi_nor *nor) in spi_nor_rww_start_exclusive() argument
1246 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_exclusive()
1248 mutex_lock(&nor->lock); in spi_nor_rww_start_exclusive()
1260 static void spi_nor_rww_end_exclusive(struct spi_nor *nor) in spi_nor_rww_end_exclusive() argument
1262 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_exclusive()
1264 guard(mutex)(&nor->lock); in spi_nor_rww_end_exclusive()
1270 int spi_nor_prep_and_lock(struct spi_nor *nor) in spi_nor_prep_and_lock() argument
1274 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock()
1278 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock()
1279 mutex_lock(&nor->lock); in spi_nor_prep_and_lock()
1281 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock()
1282 spi_nor_rww_start_exclusive(nor)); in spi_nor_prep_and_lock()
1287 void spi_nor_unlock_and_unprep(struct spi_nor *nor) in spi_nor_unlock_and_unprep() argument
1289 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep()
1290 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep()
1292 spi_nor_rww_end_exclusive(nor); in spi_nor_unlock_and_unprep()
1293 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep()
1296 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep()
1300 static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_start_pe() argument
1302 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_pe()
1307 guard(mutex)(&nor->lock); in spi_nor_rww_start_pe()
1312 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_start_pe()
1326 static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_end_pe() argument
1328 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_pe()
1332 guard(mutex)(&nor->lock); in spi_nor_rww_end_pe()
1334 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_end_pe()
1341 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
1345 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock_pe()
1349 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock_pe()
1350 mutex_lock(&nor->lock); in spi_nor_prep_and_lock_pe()
1352 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock_pe()
1353 spi_nor_rww_start_pe(nor, start, len)); in spi_nor_prep_and_lock_pe()
1358 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
1360 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep_pe()
1361 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep_pe()
1363 spi_nor_rww_end_pe(nor, start, len); in spi_nor_unlock_and_unprep_pe()
1364 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep_pe()
1367 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep_pe()
1371 static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_start_rd() argument
1373 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_rd()
1378 guard(mutex)(&nor->lock); in spi_nor_rww_start_rd()
1383 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_start_rd()
1398 static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_end_rd() argument
1400 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_rd()
1404 guard(mutex)(&nor->lock); in spi_nor_rww_end_rd()
1406 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_end_rd()
1408 nor->rww.used_banks &= ~BIT(bank); in spi_nor_rww_end_rd()
1414 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
1418 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock_rd()
1422 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock_rd()
1423 mutex_lock(&nor->lock); in spi_nor_prep_and_lock_rd()
1425 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock_rd()
1426 spi_nor_rww_start_rd(nor, start, len)); in spi_nor_prep_and_lock_rd()
1431 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
1433 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep_rd()
1434 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep_rd()
1436 spi_nor_rww_end_rd(nor, start, len); in spi_nor_unlock_and_unprep_rd()
1437 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep_rd()
1440 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep_rd()
1446 int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) in spi_nor_erase_sector() argument
1450 if (nor->spimem) { in spi_nor_erase_sector()
1452 SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode, in spi_nor_erase_sector()
1453 nor->addr_nbytes, addr); in spi_nor_erase_sector()
1455 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_erase_sector()
1457 return spi_mem_exec_op(nor->spimem, &op); in spi_nor_erase_sector()
1458 } else if (nor->controller_ops->erase) { in spi_nor_erase_sector()
1459 return spi_nor_controller_ops_erase(nor, addr); in spi_nor_erase_sector()
1466 for (i = nor->addr_nbytes - 1; i >= 0; i--) { in spi_nor_erase_sector()
1467 nor->bouncebuf[i] = addr & 0xff; in spi_nor_erase_sector()
1471 return spi_nor_controller_ops_write_reg(nor, nor->erase_opcode, in spi_nor_erase_sector()
1472 nor->bouncebuf, nor->addr_nbytes); in spi_nor_erase_sector()
1477 * @erase: pointer to a structure that describes a SPI NOR erase type
1497 * @map: the erase map of the SPI NOR
1498 * @region: pointer to a structure that describes a SPI NOR erase region
1544 * @region: pointer to a structure that describes a SPI NOR erase region
1545 * @erase: pointer to a structure that describes a SPI NOR erase type
1588 * @nor: pointer to a 'struct spi_nor'
1599 static int spi_nor_init_erase_cmd_list(struct spi_nor *nor, in spi_nor_init_erase_cmd_list() argument
1603 const struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_init_erase_cmd_list()
1649 * @nor: pointer to a 'struct spi_nor'
1658 static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len) in spi_nor_erase_multi_sectors() argument
1664 ret = spi_nor_init_erase_cmd_list(nor, &erase_list, addr, len); in spi_nor_erase_multi_sectors()
1669 nor->erase_opcode = cmd->opcode; in spi_nor_erase_multi_sectors()
1671 …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()
1674 ret = spi_nor_lock_device(nor); in spi_nor_erase_multi_sectors()
1678 ret = spi_nor_write_enable(nor); in spi_nor_erase_multi_sectors()
1680 spi_nor_unlock_device(nor); in spi_nor_erase_multi_sectors()
1684 ret = spi_nor_erase_sector(nor, addr); in spi_nor_erase_multi_sectors()
1685 spi_nor_unlock_device(nor); in spi_nor_erase_multi_sectors()
1689 ret = spi_nor_wait_till_ready(nor); in spi_nor_erase_multi_sectors()
1707 static int spi_nor_erase_dice(struct spi_nor *nor, loff_t addr, in spi_nor_erase_dice() argument
1721 (unsigned long)(nor->mtd.size / SZ_2M)); in spi_nor_erase_dice()
1724 ret = spi_nor_lock_device(nor); in spi_nor_erase_dice()
1728 ret = spi_nor_write_enable(nor); in spi_nor_erase_dice()
1730 spi_nor_unlock_device(nor); in spi_nor_erase_dice()
1734 ret = spi_nor_erase_die(nor, addr, die_size); in spi_nor_erase_dice()
1736 spi_nor_unlock_device(nor); in spi_nor_erase_dice()
1740 ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); in spi_nor_erase_dice()
1753 * Erase an address range on the nor chip. The address range may extend
1758 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_erase() local
1759 u8 n_dice = nor->params->n_dice; in spi_nor_erase()
1765 dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr, in spi_nor_erase()
1768 if (spi_nor_has_uniform_erase(nor)) { in spi_nor_erase()
1785 ret = spi_nor_prep_and_lock_pe(nor, instr->addr, instr->len); in spi_nor_erase()
1790 if ((len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) || in spi_nor_erase()
1792 ret = spi_nor_erase_dice(nor, addr, len, die_size); in spi_nor_erase()
1802 } else if (spi_nor_has_uniform_erase(nor)) { in spi_nor_erase()
1804 ret = spi_nor_lock_device(nor); in spi_nor_erase()
1808 ret = spi_nor_write_enable(nor); in spi_nor_erase()
1810 spi_nor_unlock_device(nor); in spi_nor_erase()
1814 ret = spi_nor_erase_sector(nor, addr); in spi_nor_erase()
1815 spi_nor_unlock_device(nor); in spi_nor_erase()
1819 ret = spi_nor_wait_till_ready(nor); in spi_nor_erase()
1829 ret = spi_nor_erase_multi_sectors(nor, addr, len); in spi_nor_erase()
1834 ret = spi_nor_write_disable(nor); in spi_nor_erase()
1837 spi_nor_unlock_and_unprep_pe(nor, instr->addr, instr->len); in spi_nor_erase()
1845 * @nor: pointer to a 'struct spi_nor'
1851 int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor) in spi_nor_sr1_bit6_quad_enable() argument
1855 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr1_bit6_quad_enable()
1859 if (nor->bouncebuf[0] & SR1_QUAD_EN_BIT6) in spi_nor_sr1_bit6_quad_enable()
1862 nor->bouncebuf[0] |= SR1_QUAD_EN_BIT6; in spi_nor_sr1_bit6_quad_enable()
1864 return spi_nor_write_sr1_and_check(nor, nor->bouncebuf[0]); in spi_nor_sr1_bit6_quad_enable()
1870 * @nor: pointer to a 'struct spi_nor'.
1876 int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor) in spi_nor_sr2_bit1_quad_enable() argument
1880 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_sr2_bit1_quad_enable()
1881 return spi_nor_write_16bit_cr_and_check(nor, SR2_QUAD_EN_BIT1); in spi_nor_sr2_bit1_quad_enable()
1883 ret = spi_nor_read_cr(nor, nor->bouncebuf); in spi_nor_sr2_bit1_quad_enable()
1887 if (nor->bouncebuf[0] & SR2_QUAD_EN_BIT1) in spi_nor_sr2_bit1_quad_enable()
1890 nor->bouncebuf[0] |= SR2_QUAD_EN_BIT1; in spi_nor_sr2_bit1_quad_enable()
1892 return spi_nor_write_16bit_cr_and_check(nor, nor->bouncebuf[0]); in spi_nor_sr2_bit1_quad_enable()
1897 * @nor: pointer to a 'struct spi_nor'
1907 int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor) in spi_nor_sr2_bit7_quad_enable() argument
1909 u8 *sr2 = nor->bouncebuf; in spi_nor_sr2_bit7_quad_enable()
1914 ret = spi_nor_read_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1923 ret = spi_nor_write_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1930 ret = spi_nor_read_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1935 dev_dbg(nor->dev, "SR2: Read back test failed\n"); in spi_nor_sr2_bit7_quad_enable()
1960 .name = "spi-nor-generic",
1963 static const struct flash_info *spi_nor_match_id(struct spi_nor *nor, in spi_nor_match_id() argument
1974 nor->manufacturer = manufacturers[i]; in spi_nor_match_id()
1983 static const struct flash_info *spi_nor_detect(struct spi_nor *nor) in spi_nor_detect() argument
1986 u8 *id = nor->bouncebuf; in spi_nor_detect()
1989 ret = spi_nor_read_id(nor, 0, 0, id, nor->reg_proto); in spi_nor_detect()
1991 dev_dbg(nor->dev, "error %d reading JEDEC ID\n", ret); in spi_nor_detect()
1996 nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL); in spi_nor_detect()
1997 if (!nor->id) in spi_nor_detect()
2000 info = spi_nor_match_id(nor, id); in spi_nor_detect()
2004 ret = spi_nor_check_sfdp_signature(nor); in spi_nor_detect()
2010 dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", in spi_nor_detect()
2020 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_read() local
2025 dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len); in spi_nor_read()
2027 ret = spi_nor_prep_and_lock_rd(nor, from_lock, len_lock); in spi_nor_read()
2034 ret = spi_nor_read_data(nor, addr, len, buf); in spi_nor_read()
2052 spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock); in spi_nor_read()
2058 * Write an address range to the nor chip. Data must be written in
2065 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_write() local
2068 u32 page_size = nor->params->page_size; in spi_nor_write()
2070 dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); in spi_nor_write()
2072 ret = spi_nor_prep_and_lock_pe(nor, to, len); in spi_nor_write()
2083 ret = spi_nor_lock_device(nor); in spi_nor_write()
2087 ret = spi_nor_write_enable(nor); in spi_nor_write()
2089 spi_nor_unlock_device(nor); in spi_nor_write()
2093 ret = spi_nor_write_data(nor, addr, page_remain, buf + i); in spi_nor_write()
2094 spi_nor_unlock_device(nor); in spi_nor_write()
2099 ret = spi_nor_wait_till_ready(nor); in spi_nor_write()
2107 spi_nor_unlock_and_unprep_pe(nor, to, len); in spi_nor_write()
2112 static int spi_nor_check(struct spi_nor *nor) in spi_nor_check() argument
2114 if (!nor->dev || in spi_nor_check()
2115 (!nor->spimem && !nor->controller_ops) || in spi_nor_check()
2116 (!nor->spimem && nor->controller_ops && in spi_nor_check()
2117 (!nor->controller_ops->read || in spi_nor_check()
2118 !nor->controller_ops->write || in spi_nor_check()
2119 !nor->controller_ops->read_reg || in spi_nor_check()
2120 !nor->controller_ops->write_reg))) { in spi_nor_check()
2121 pr_err("spi-nor: please fill all the necessary fields!\n"); in spi_nor_check()
2125 if (nor->spimem && nor->controller_ops) { in spi_nor_check()
2126 …dev_err(nor->dev, "nor->spimem and nor->controller_ops are mutually exclusive, please set just one… in spi_nor_check()
2209 *@nor: pointer to a 'struct spi_nor'
2214 static int spi_nor_spimem_check_op(struct spi_nor *nor, in spi_nor_spimem_check_op() argument
2224 if (!spi_mem_supports_op(nor->spimem, op)) { in spi_nor_spimem_check_op()
2225 if (nor->params->size > SZ_16M) in spi_nor_spimem_check_op()
2230 if (!spi_mem_supports_op(nor->spimem, op)) in spi_nor_spimem_check_op()
2240 *@nor: pointer to a 'struct spi_nor'
2245 static int spi_nor_spimem_check_readop(struct spi_nor *nor, in spi_nor_spimem_check_readop() argument
2250 spi_nor_spimem_setup_op(nor, &op, read->proto); in spi_nor_spimem_check_readop()
2255 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_spimem_check_readop()
2258 return spi_nor_spimem_check_op(nor, &op); in spi_nor_spimem_check_readop()
2264 *@nor: pointer to a 'struct spi_nor'
2269 static int spi_nor_spimem_check_pp(struct spi_nor *nor, in spi_nor_spimem_check_pp() argument
2274 spi_nor_spimem_setup_op(nor, &op, pp->proto); in spi_nor_spimem_check_pp()
2276 return spi_nor_spimem_check_op(nor, &op); in spi_nor_spimem_check_pp()
2282 * @nor: pointer to a 'struct spi_nor'
2287 spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps) in spi_nor_spimem_adjust_hwcaps() argument
2289 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_spimem_adjust_hwcaps()
2299 if (nor->flags & SNOR_F_BROKEN_RESET) in spi_nor_spimem_adjust_hwcaps()
2310 spi_nor_spimem_check_readop(nor, ¶ms->reads[rdidx])) in spi_nor_spimem_adjust_hwcaps()
2317 if (spi_nor_spimem_check_pp(nor, in spi_nor_spimem_adjust_hwcaps()
2324 * spi_nor_set_erase_type() - set a SPI NOR erase type
2325 * @erase: pointer to a structure that describes a SPI NOR erase type
2340 * spi_nor_mask_erase_type() - mask out a SPI NOR erase type
2341 * @erase: pointer to a structure that describes a SPI NOR erase type
2350 * @map: the erase map of the SPI NOR
2353 * @flash_size: the spi nor flash memory size
2365 int spi_nor_post_bfpt_fixups(struct spi_nor *nor, in spi_nor_post_bfpt_fixups() argument
2371 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_post_bfpt_fixups()
2372 nor->manufacturer->fixups->post_bfpt) { in spi_nor_post_bfpt_fixups()
2373 ret = nor->manufacturer->fixups->post_bfpt(nor, bfpt_header, in spi_nor_post_bfpt_fixups()
2379 if (nor->info->fixups && nor->info->fixups->post_bfpt) in spi_nor_post_bfpt_fixups()
2380 return nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt); in spi_nor_post_bfpt_fixups()
2385 static int spi_nor_select_read(struct spi_nor *nor, in spi_nor_select_read() argument
2398 read = &nor->params->reads[cmd]; in spi_nor_select_read()
2399 nor->read_opcode = read->opcode; in spi_nor_select_read()
2400 nor->read_proto = read->proto; in spi_nor_select_read()
2403 * In the SPI NOR framework, we don't need to make the difference in spi_nor_select_read()
2412 nor->read_dummy = read->num_mode_clocks + read->num_wait_states; in spi_nor_select_read()
2416 static int spi_nor_select_pp(struct spi_nor *nor, in spi_nor_select_pp() argument
2429 pp = &nor->params->page_programs[cmd]; in spi_nor_select_pp()
2430 nor->program_opcode = pp->opcode; in spi_nor_select_pp()
2431 nor->write_proto = pp->proto; in spi_nor_select_pp()
2437 * @map: the erase map of the SPI NOR
2492 static int spi_nor_select_erase(struct spi_nor *nor) in spi_nor_select_erase() argument
2494 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_select_erase()
2496 struct mtd_info *mtd = &nor->mtd; in spi_nor_select_erase()
2507 if (spi_nor_has_uniform_erase(nor)) { in spi_nor_select_erase()
2511 nor->erase_opcode = erase->opcode; in spi_nor_select_erase()
2518 * maximum erase sector size. No need to set nor->erase_opcode. in spi_nor_select_erase()
2534 static int spi_nor_set_addr_nbytes(struct spi_nor *nor) in spi_nor_set_addr_nbytes() argument
2536 if (nor->params->addr_nbytes) { in spi_nor_set_addr_nbytes()
2537 nor->addr_nbytes = nor->params->addr_nbytes; in spi_nor_set_addr_nbytes()
2538 } else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) { in spi_nor_set_addr_nbytes()
2551 nor->addr_nbytes = 4; in spi_nor_set_addr_nbytes()
2552 } else if (nor->info->addr_nbytes) { in spi_nor_set_addr_nbytes()
2553 nor->addr_nbytes = nor->info->addr_nbytes; in spi_nor_set_addr_nbytes()
2555 nor->addr_nbytes = 3; in spi_nor_set_addr_nbytes()
2558 if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) { in spi_nor_set_addr_nbytes()
2560 nor->addr_nbytes = 4; in spi_nor_set_addr_nbytes()
2563 if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) { in spi_nor_set_addr_nbytes()
2564 dev_dbg(nor->dev, "The number of address bytes is too large: %u\n", in spi_nor_set_addr_nbytes()
2565 nor->addr_nbytes); in spi_nor_set_addr_nbytes()
2570 if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES && in spi_nor_set_addr_nbytes()
2571 !(nor->flags & SNOR_F_HAS_4BAIT)) in spi_nor_set_addr_nbytes()
2572 spi_nor_set_4byte_opcodes(nor); in spi_nor_set_addr_nbytes()
2577 static int spi_nor_setup(struct spi_nor *nor, in spi_nor_setup() argument
2580 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_setup()
2590 if (nor->spimem) { in spi_nor_setup()
2596 spi_nor_spimem_adjust_hwcaps(nor, &shared_mask); in spi_nor_setup()
2605 dev_dbg(nor->dev, in spi_nor_setup()
2612 err = spi_nor_select_read(nor, shared_mask); in spi_nor_setup()
2614 dev_dbg(nor->dev, in spi_nor_setup()
2620 err = spi_nor_select_pp(nor, shared_mask); in spi_nor_setup()
2622 dev_dbg(nor->dev, in spi_nor_setup()
2628 err = spi_nor_select_erase(nor); in spi_nor_setup()
2630 dev_dbg(nor->dev, in spi_nor_setup()
2635 return spi_nor_set_addr_nbytes(nor); in spi_nor_setup()
2641 * @nor: pointer to a 'struct spi_nor'.
2643 static void spi_nor_manufacturer_init_params(struct spi_nor *nor) in spi_nor_manufacturer_init_params() argument
2645 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_manufacturer_init_params()
2646 nor->manufacturer->fixups->default_init) in spi_nor_manufacturer_init_params()
2647 nor->manufacturer->fixups->default_init(nor); in spi_nor_manufacturer_init_params()
2649 if (nor->info->fixups && nor->info->fixups->default_init) in spi_nor_manufacturer_init_params()
2650 nor->info->fixups->default_init(nor); in spi_nor_manufacturer_init_params()
2655 * settings based on nor->info->sfdp_flags. This method should be called only by
2660 * @nor: pointer to a 'struct spi_nor'.
2662 static void spi_nor_no_sfdp_init_params(struct spi_nor *nor) in spi_nor_no_sfdp_init_params() argument
2664 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_no_sfdp_init_params()
2666 const struct flash_info *info = nor->info; in spi_nor_no_sfdp_init_params()
2728 * spi_nor_init_flags() - Initialize NOR flags for settings that are not defined
2730 * @nor: pointer to a 'struct spi_nor'
2732 static void spi_nor_init_flags(struct spi_nor *nor) in spi_nor_init_flags() argument
2734 struct device_node *np = spi_nor_get_flash_node(nor); in spi_nor_init_flags()
2735 const u16 flags = nor->info->flags; in spi_nor_init_flags()
2738 nor->flags |= SNOR_F_BROKEN_RESET; in spi_nor_init_flags()
2741 nor->flags |= SNOR_F_NO_WP; in spi_nor_init_flags()
2744 nor->flags |= SNOR_F_SWP_IS_VOLATILE; in spi_nor_init_flags()
2747 nor->flags |= SNOR_F_HAS_LOCK; in spi_nor_init_flags()
2750 nor->flags |= SNOR_F_HAS_SR_TB; in spi_nor_init_flags()
2752 nor->flags |= SNOR_F_HAS_SR_TB_BIT6; in spi_nor_init_flags()
2756 nor->flags |= SNOR_F_HAS_4BIT_BP; in spi_nor_init_flags()
2758 nor->flags |= SNOR_F_HAS_SR_BP3_BIT6; in spi_nor_init_flags()
2761 if (flags & SPI_NOR_RWW && nor->params->n_banks > 1 && in spi_nor_init_flags()
2762 !nor->controller_ops) in spi_nor_init_flags()
2763 nor->flags |= SNOR_F_RWW; in spi_nor_init_flags()
2767 * spi_nor_init_fixup_flags() - Initialize NOR flags for settings that can not
2772 * @nor: pointer to a 'struct spi_nor'
2774 static void spi_nor_init_fixup_flags(struct spi_nor *nor) in spi_nor_init_fixup_flags() argument
2776 const u8 fixup_flags = nor->info->fixup_flags; in spi_nor_init_fixup_flags()
2779 nor->flags |= SNOR_F_4B_OPCODES; in spi_nor_init_fixup_flags()
2782 nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE; in spi_nor_init_fixup_flags()
2787 * @nor: pointer to a 'struct spi_nor'
2793 static int spi_nor_late_init_params(struct spi_nor *nor) in spi_nor_late_init_params() argument
2795 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_late_init_params()
2798 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_late_init_params()
2799 nor->manufacturer->fixups->late_init) { in spi_nor_late_init_params()
2800 ret = nor->manufacturer->fixups->late_init(nor); in spi_nor_late_init_params()
2806 spi_nor_init_flags(nor); in spi_nor_late_init_params()
2808 if (nor->info->fixups && nor->info->fixups->late_init) { in spi_nor_late_init_params()
2809 ret = nor->info->fixups->late_init(nor); in spi_nor_late_init_params()
2814 if (!nor->params->die_erase_opcode) in spi_nor_late_init_params()
2815 nor->params->die_erase_opcode = SPINOR_OP_CHIP_ERASE; in spi_nor_late_init_params()
2821 spi_nor_init_fixup_flags(nor); in spi_nor_late_init_params()
2824 * NOR protection support. When locking_ops are not provided, we pick in spi_nor_late_init_params()
2827 if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops) in spi_nor_late_init_params()
2828 spi_nor_init_default_locking_ops(nor); in spi_nor_late_init_params()
2839 * @nor: pointer to a 'struct spi_nor'.
2844 static void spi_nor_sfdp_init_params_deprecated(struct spi_nor *nor) in spi_nor_sfdp_init_params_deprecated() argument
2848 memcpy(&sfdp_params, nor->params, sizeof(sfdp_params)); in spi_nor_sfdp_init_params_deprecated()
2850 if (spi_nor_parse_sfdp(nor)) { in spi_nor_sfdp_init_params_deprecated()
2851 memcpy(nor->params, &sfdp_params, sizeof(*nor->params)); in spi_nor_sfdp_init_params_deprecated()
2852 nor->flags &= ~SNOR_F_4B_OPCODES; in spi_nor_sfdp_init_params_deprecated()
2859 * @nor: pointer to a 'struct spi_nor'.
2865 static void spi_nor_init_params_deprecated(struct spi_nor *nor) in spi_nor_init_params_deprecated() argument
2867 spi_nor_no_sfdp_init_params(nor); in spi_nor_init_params_deprecated()
2869 spi_nor_manufacturer_init_params(nor); in spi_nor_init_params_deprecated()
2871 if (nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ | in spi_nor_init_params_deprecated()
2875 spi_nor_sfdp_init_params_deprecated(nor); in spi_nor_init_params_deprecated()
2882 * @nor: pointer to a 'struct spi_nor'.
2884 static void spi_nor_init_default_params(struct spi_nor *nor) in spi_nor_init_default_params() argument
2886 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_init_default_params()
2887 const struct flash_info *info = nor->info; in spi_nor_init_default_params()
2888 struct device_node *np = spi_nor_get_flash_node(nor); in spi_nor_init_default_params()
2894 nor->flags |= SNOR_F_HAS_16BIT_SR; in spi_nor_init_default_params()
2896 /* Set SPI NOR sizes. */ in spi_nor_init_default_params()
2931 * @nor: pointer to a 'struct spi_nor'.
2937 * based on nor->info data:
2966 static int spi_nor_init_params(struct spi_nor *nor) in spi_nor_init_params() argument
2970 nor->params = devm_kzalloc(nor->dev, sizeof(*nor->params), GFP_KERNEL); in spi_nor_init_params()
2971 if (!nor->params) in spi_nor_init_params()
2974 spi_nor_init_default_params(nor); in spi_nor_init_params()
2976 if (spi_nor_needs_sfdp(nor)) { in spi_nor_init_params()
2977 ret = spi_nor_parse_sfdp(nor); in spi_nor_init_params()
2979 …dev_err(nor->dev, "BFPT parsing failed. Please consider using SPI_NOR_SKIP_SFDP when declaring the… in spi_nor_init_params()
2982 } else if (nor->info->no_sfdp_flags & SPI_NOR_SKIP_SFDP) { in spi_nor_init_params()
2983 spi_nor_no_sfdp_init_params(nor); in spi_nor_init_params()
2985 spi_nor_init_params_deprecated(nor); in spi_nor_init_params()
2988 ret = spi_nor_late_init_params(nor); in spi_nor_init_params()
2992 if (WARN_ON(!is_power_of_2(nor->params->page_size))) in spi_nor_init_params()
2999 * @nor: pointer to a 'struct spi_nor'
3004 static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) in spi_nor_set_octal_dtr() argument
3008 if (!nor->params->set_octal_dtr) in spi_nor_set_octal_dtr()
3011 if (!(nor->read_proto == SNOR_PROTO_8_8_8_DTR && in spi_nor_set_octal_dtr()
3012 nor->write_proto == SNOR_PROTO_8_8_8_DTR)) in spi_nor_set_octal_dtr()
3015 if (!(nor->flags & SNOR_F_IO_MODE_EN_VOLATILE)) in spi_nor_set_octal_dtr()
3018 ret = nor->params->set_octal_dtr(nor, enable); in spi_nor_set_octal_dtr()
3023 nor->reg_proto = SNOR_PROTO_8_8_8_DTR; in spi_nor_set_octal_dtr()
3025 nor->reg_proto = SNOR_PROTO_1_1_1; in spi_nor_set_octal_dtr()
3032 * @nor: pointer to a 'struct spi_nor'
3036 static int spi_nor_quad_enable(struct spi_nor *nor) in spi_nor_quad_enable() argument
3038 if (!nor->params->quad_enable) in spi_nor_quad_enable()
3041 if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || in spi_nor_quad_enable()
3042 spi_nor_get_protocol_width(nor->write_proto) == 4)) in spi_nor_quad_enable()
3045 return nor->params->quad_enable(nor); in spi_nor_quad_enable()
3050 * @nor: pointer to a 'struct spi_nor'.
3055 int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode() argument
3057 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_set_4byte_addr_mode()
3068 WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET, in spi_nor_set_4byte_addr_mode()
3072 ret = params->set_4byte_addr_mode(nor, enable); in spi_nor_set_4byte_addr_mode()
3087 static int spi_nor_init(struct spi_nor *nor) in spi_nor_init() argument
3091 err = spi_nor_set_octal_dtr(nor, true); in spi_nor_init()
3093 dev_dbg(nor->dev, "octal mode not supported\n"); in spi_nor_init()
3097 err = spi_nor_quad_enable(nor); in spi_nor_init()
3099 dev_dbg(nor->dev, "quad mode not supported\n"); in spi_nor_init()
3104 * Some SPI NOR flashes are write protected by default after a power-on in spi_nor_init()
3115 nor->flags & SNOR_F_SWP_IS_VOLATILE)) in spi_nor_init()
3116 spi_nor_try_unlock_all(nor); in spi_nor_init()
3118 if (nor->addr_nbytes == 4 && in spi_nor_init()
3119 nor->read_proto != SNOR_PROTO_8_8_8_DTR && in spi_nor_init()
3120 !(nor->flags & SNOR_F_4B_OPCODES)) in spi_nor_init()
3121 return spi_nor_set_4byte_addr_mode(nor, true); in spi_nor_init()
3128 * @nor: pointer to 'struct spi_nor'
3141 static void spi_nor_soft_reset(struct spi_nor *nor) in spi_nor_soft_reset() argument
3148 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_soft_reset()
3150 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_soft_reset()
3153 dev_warn(nor->dev, "Software reset failed: %d\n", ret); in spi_nor_soft_reset()
3159 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_soft_reset()
3161 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_soft_reset()
3163 dev_warn(nor->dev, "Software reset failed: %d\n", ret); in spi_nor_soft_reset()
3178 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_suspend() local
3182 ret = spi_nor_set_octal_dtr(nor, false); in spi_nor_suspend()
3184 dev_err(nor->dev, "suspend() failed\n"); in spi_nor_suspend()
3192 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_resume() local
3193 struct device *dev = nor->dev; in spi_nor_resume()
3196 /* re-initialize the nor chip */ in spi_nor_resume()
3197 ret = spi_nor_init(nor); in spi_nor_resume()
3205 struct spi_nor *nor = mtd_to_spi_nor(master); in spi_nor_get_device() local
3208 if (nor->spimem) in spi_nor_get_device()
3209 dev = nor->spimem->spi->controller->dev.parent; in spi_nor_get_device()
3211 dev = nor->dev; in spi_nor_get_device()
3222 struct spi_nor *nor = mtd_to_spi_nor(master); in spi_nor_put_device() local
3225 if (nor->spimem) in spi_nor_put_device()
3226 dev = nor->spimem->spi->controller->dev.parent; in spi_nor_put_device()
3228 dev = nor->dev; in spi_nor_put_device()
3233 static void spi_nor_restore(struct spi_nor *nor) in spi_nor_restore() argument
3238 if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && in spi_nor_restore()
3239 nor->flags & SNOR_F_BROKEN_RESET) { in spi_nor_restore()
3240 ret = spi_nor_set_4byte_addr_mode(nor, false); in spi_nor_restore()
3247 dev_err(nor->dev, "Failed to exit 4-byte address mode, err = %d\n", ret); in spi_nor_restore()
3250 if (nor->flags & SNOR_F_SOFT_RESET) in spi_nor_restore()
3251 spi_nor_soft_reset(nor); in spi_nor_restore()
3254 static const struct flash_info *spi_nor_match_name(struct spi_nor *nor, in spi_nor_match_name() argument
3263 nor->manufacturer = manufacturers[i]; in spi_nor_match_name()
3272 static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, in spi_nor_get_flash_info() argument
3278 info = spi_nor_match_name(nor, name); in spi_nor_get_flash_info()
3287 jinfo = spi_nor_detect(nor); in spi_nor_get_flash_info()
3296 dev_warn(nor->dev, "found %s, expected %s\n", in spi_nor_get_flash_info()
3323 static int spi_nor_set_mtd_eraseregions(struct spi_nor *nor) in spi_nor_set_mtd_eraseregions() argument
3325 const struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_set_mtd_eraseregions()
3328 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_eraseregions()
3331 mtd_region = devm_kcalloc(nor->dev, map->n_regions, sizeof(*mtd_region), in spi_nor_set_mtd_eraseregions()
3353 static int spi_nor_set_mtd_info(struct spi_nor *nor) in spi_nor_set_mtd_info() argument
3355 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_info()
3356 struct device *dev = nor->dev; in spi_nor_set_mtd_info()
3358 spi_nor_set_mtd_locking_ops(nor); in spi_nor_set_mtd_info()
3359 spi_nor_set_mtd_otp_ops(nor); in spi_nor_set_mtd_info()
3366 /* Unset BIT_WRITEABLE to enable JFFS2 write buffer for ECC'd NOR */ in spi_nor_set_mtd_info()
3367 if (nor->flags & SNOR_F_ECC) in spi_nor_set_mtd_info()
3369 if (nor->info->flags & SPI_NOR_NO_ERASE) in spi_nor_set_mtd_info()
3373 mtd->writesize = nor->params->writesize; in spi_nor_set_mtd_info()
3374 mtd->writebufsize = nor->params->page_size; in spi_nor_set_mtd_info()
3375 mtd->size = nor->params->size; in spi_nor_set_mtd_info()
3385 if (!spi_nor_has_uniform_erase(nor)) in spi_nor_set_mtd_info()
3386 return spi_nor_set_mtd_eraseregions(nor); in spi_nor_set_mtd_info()
3391 static int spi_nor_hw_reset(struct spi_nor *nor) in spi_nor_hw_reset() argument
3395 reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW); in spi_nor_hw_reset()
3412 int spi_nor_scan(struct spi_nor *nor, const char *name, in spi_nor_scan() argument
3416 struct device *dev = nor->dev; in spi_nor_scan()
3419 ret = spi_nor_check(nor); in spi_nor_scan()
3424 nor->reg_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3425 nor->read_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3426 nor->write_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3432 * nor->params->page_size turns out to be greater than PAGE_SIZE (which in spi_nor_scan()
3433 * shouldn't happen before long since NOR pages are usually less in spi_nor_scan()
3436 nor->bouncebuf_size = PAGE_SIZE; in spi_nor_scan()
3437 nor->bouncebuf = devm_kmalloc(dev, nor->bouncebuf_size, in spi_nor_scan()
3439 if (!nor->bouncebuf) in spi_nor_scan()
3442 ret = spi_nor_hw_reset(nor); in spi_nor_scan()
3446 info = spi_nor_get_flash_info(nor, name); in spi_nor_scan()
3450 nor->info = info; in spi_nor_scan()
3452 mutex_init(&nor->lock); in spi_nor_scan()
3455 ret = spi_nor_init_params(nor); in spi_nor_scan()
3459 if (spi_nor_use_parallel_locking(nor)) in spi_nor_scan()
3460 init_waitqueue_head(&nor->rww.wait); in spi_nor_scan()
3469 ret = spi_nor_setup(nor, hwcaps); in spi_nor_scan()
3474 ret = spi_nor_init(nor); in spi_nor_scan()
3479 ret = spi_nor_set_mtd_info(nor); in spi_nor_scan()
3484 SPI_NOR_MAX_ID_LEN, nor->id); in spi_nor_scan()
3490 static int spi_nor_create_read_dirmap(struct spi_nor *nor) in spi_nor_create_read_dirmap() argument
3493 .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), in spi_nor_create_read_dirmap()
3494 SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), in spi_nor_create_read_dirmap()
3495 SPI_MEM_OP_DUMMY(nor->read_dummy, 0), in spi_nor_create_read_dirmap()
3498 .length = nor->params->size, in spi_nor_create_read_dirmap()
3502 spi_nor_spimem_setup_op(nor, op, nor->read_proto); in spi_nor_create_read_dirmap()
3505 op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8; in spi_nor_create_read_dirmap()
3506 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_create_read_dirmap()
3514 op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); in spi_nor_create_read_dirmap()
3516 nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, in spi_nor_create_read_dirmap()
3518 return PTR_ERR_OR_ZERO(nor->dirmap.rdesc); in spi_nor_create_read_dirmap()
3521 static int spi_nor_create_write_dirmap(struct spi_nor *nor) in spi_nor_create_write_dirmap() argument
3524 .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), in spi_nor_create_write_dirmap()
3525 SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), in spi_nor_create_write_dirmap()
3529 .length = nor->params->size, in spi_nor_create_write_dirmap()
3533 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in spi_nor_create_write_dirmap()
3536 spi_nor_spimem_setup_op(nor, op, nor->write_proto); in spi_nor_create_write_dirmap()
3543 op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto); in spi_nor_create_write_dirmap()
3545 nor->dirmap.wdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, in spi_nor_create_write_dirmap()
3547 return PTR_ERR_OR_ZERO(nor->dirmap.wdesc); in spi_nor_create_write_dirmap()
3555 struct spi_nor *nor; in spi_nor_probe() local
3568 nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL); in spi_nor_probe()
3569 if (!nor) in spi_nor_probe()
3572 nor->spimem = spimem; in spi_nor_probe()
3573 nor->dev = dev; in spi_nor_probe()
3574 spi_nor_set_flash_node(nor, dev->of_node); in spi_nor_probe()
3576 spi_mem_set_drvdata(spimem, nor); in spi_nor_probe()
3579 nor->mtd.name = data->name; in spi_nor_probe()
3581 if (!nor->mtd.name) in spi_nor_probe()
3582 nor->mtd.name = spi_mem_get_name(spimem); in spi_nor_probe()
3592 else if (!strcmp(spi->modalias, "spi-nor")) in spi_nor_probe()
3597 ret = spi_nor_scan(nor, flash_name, &hwcaps); in spi_nor_probe()
3601 spi_nor_debugfs_register(nor); in spi_nor_probe()
3606 * a NOR we don't end up with buffer overflows. in spi_nor_probe()
3608 if (nor->params->page_size > PAGE_SIZE) { in spi_nor_probe()
3609 nor->bouncebuf_size = nor->params->page_size; in spi_nor_probe()
3610 devm_kfree(dev, nor->bouncebuf); in spi_nor_probe()
3611 nor->bouncebuf = devm_kmalloc(dev, nor->bouncebuf_size, in spi_nor_probe()
3613 if (!nor->bouncebuf) in spi_nor_probe()
3617 ret = spi_nor_create_read_dirmap(nor); in spi_nor_probe()
3621 ret = spi_nor_create_write_dirmap(nor); in spi_nor_probe()
3625 return mtd_device_register(&nor->mtd, data ? data->parts : NULL, in spi_nor_probe()
3631 struct spi_nor *nor = spi_mem_get_drvdata(spimem); in spi_nor_remove() local
3633 spi_nor_restore(nor); in spi_nor_remove()
3636 return mtd_device_unregister(&nor->mtd); in spi_nor_remove()
3641 struct spi_nor *nor = spi_mem_get_drvdata(spimem); in spi_nor_shutdown() local
3643 spi_nor_restore(nor); in spi_nor_shutdown()
3652 * encourage new users to add support to the spi-nor library, and simply bind
3653 * against a generic string here (e.g., "jedec,spi-nor").
3660 * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
3664 {"spi-nor"},
3668 * them with "spi-nor" in platform data.
3673 * Entries that were used in DTs without "jedec,spi-nor" fallback and
3705 * Generic compatibility for SPI NOR that can be identified by the
3708 { .compatible = "jedec,spi-nor" },
3721 .name = "spi-nor",
3748 MODULE_DESCRIPTION("framework for SPI NOR");