Lines Matching full:nor
17 #include <linux/mtd/spi-nor.h>
50 * @nor: pointer to a 'struct spi_nor'
58 static u8 spi_nor_get_cmd_ext(const struct spi_nor *nor, in spi_nor_get_cmd_ext() argument
61 switch (nor->cmd_ext_type) { in spi_nor_get_cmd_ext()
69 dev_err(nor->dev, "Unknown command extension type\n"); in spi_nor_get_cmd_ext()
76 * @nor: pointer to a 'struct spi_nor'
81 void spi_nor_spimem_setup_op(const struct spi_nor *nor, in spi_nor_spimem_setup_op() argument
102 * something like 4S-4D-4D, but SPI NOR can't. So, set all 4 in spi_nor_spimem_setup_op()
113 ext = spi_nor_get_cmd_ext(nor, op); in spi_nor_spimem_setup_op()
118 if (proto == SNOR_PROTO_8_8_8_DTR && nor->flags & SNOR_F_SWAP16) in spi_nor_spimem_setup_op()
125 * @nor: pointer to 'struct spi_nor'
132 static bool spi_nor_spimem_bounce(struct spi_nor *nor, struct spi_mem_op *op) in spi_nor_spimem_bounce() argument
137 if (op->data.nbytes > nor->bouncebuf_size) in spi_nor_spimem_bounce()
138 op->data.nbytes = nor->bouncebuf_size; in spi_nor_spimem_bounce()
139 op->data.buf.in = nor->bouncebuf; in spi_nor_spimem_bounce()
148 * @nor: pointer to 'struct spi_nor'
153 static int spi_nor_spimem_exec_op(struct spi_nor *nor, struct spi_mem_op *op) in spi_nor_spimem_exec_op() argument
157 error = spi_mem_adjust_op_size(nor->spimem, op); in spi_nor_spimem_exec_op()
161 return spi_mem_exec_op(nor->spimem, op); in spi_nor_spimem_exec_op()
164 int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode, in spi_nor_controller_ops_read_reg() argument
167 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_read_reg()
170 return nor->controller_ops->read_reg(nor, opcode, buf, len); in spi_nor_controller_ops_read_reg()
173 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode, in spi_nor_controller_ops_write_reg() argument
176 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_write_reg()
179 return nor->controller_ops->write_reg(nor, opcode, buf, len); in spi_nor_controller_ops_write_reg()
182 static int spi_nor_controller_ops_erase(struct spi_nor *nor, loff_t offs) in spi_nor_controller_ops_erase() argument
184 if (spi_nor_protocol_is_dtr(nor->reg_proto)) in spi_nor_controller_ops_erase()
187 return nor->controller_ops->erase(nor, offs); in spi_nor_controller_ops_erase()
193 * @nor: pointer to 'struct spi_nor'
200 static ssize_t spi_nor_spimem_read_data(struct spi_nor *nor, loff_t from, in spi_nor_spimem_read_data() argument
204 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), in spi_nor_spimem_read_data()
205 SPI_MEM_OP_ADDR(nor->addr_nbytes, from, 0), in spi_nor_spimem_read_data()
206 SPI_MEM_OP_DUMMY(nor->read_dummy, 0), in spi_nor_spimem_read_data()
212 spi_nor_spimem_setup_op(nor, &op, nor->read_proto); in spi_nor_spimem_read_data()
215 op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8; in spi_nor_spimem_read_data()
216 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_spimem_read_data()
219 usebouncebuf = spi_nor_spimem_bounce(nor, &op); in spi_nor_spimem_read_data()
221 if (nor->dirmap.rdesc) { in spi_nor_spimem_read_data()
222 nbytes = spi_mem_dirmap_read(nor->dirmap.rdesc, op.addr.val, in spi_nor_spimem_read_data()
225 error = spi_nor_spimem_exec_op(nor, &op); in spi_nor_spimem_read_data()
239 * @nor: pointer to 'struct spi_nor'
246 ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len, u8 *buf) in spi_nor_read_data() argument
248 if (nor->spimem) in spi_nor_read_data()
249 return spi_nor_spimem_read_data(nor, from, len, buf); in spi_nor_read_data()
251 return nor->controller_ops->read(nor, from, len, buf); in spi_nor_read_data()
257 * @nor: pointer to 'struct spi_nor'
264 static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to, in spi_nor_spimem_write_data() argument
268 SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), in spi_nor_spimem_write_data()
269 SPI_MEM_OP_ADDR(nor->addr_nbytes, to, 0), in spi_nor_spimem_write_data()
275 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in spi_nor_spimem_write_data()
278 spi_nor_spimem_setup_op(nor, &op, nor->write_proto); in spi_nor_spimem_write_data()
280 if (spi_nor_spimem_bounce(nor, &op)) in spi_nor_spimem_write_data()
281 memcpy(nor->bouncebuf, buf, op.data.nbytes); in spi_nor_spimem_write_data()
283 if (nor->dirmap.wdesc) { in spi_nor_spimem_write_data()
284 nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc, op.addr.val, in spi_nor_spimem_write_data()
287 error = spi_nor_spimem_exec_op(nor, &op); in spi_nor_spimem_write_data()
298 * @nor: pointer to 'struct spi_nor'
305 ssize_t spi_nor_write_data(struct spi_nor *nor, loff_t to, size_t len, in spi_nor_write_data() argument
308 if (nor->spimem) in spi_nor_write_data()
309 return spi_nor_spimem_write_data(nor, to, len, buf); in spi_nor_write_data()
311 return nor->controller_ops->write(nor, to, len, buf); in spi_nor_write_data()
317 * @nor: pointer to 'struct spi_nor'.
323 int spi_nor_read_any_reg(struct spi_nor *nor, struct spi_mem_op *op, in spi_nor_read_any_reg() argument
326 if (!nor->spimem) in spi_nor_read_any_reg()
329 spi_nor_spimem_setup_op(nor, op, proto); in spi_nor_read_any_reg()
330 return spi_nor_spimem_exec_op(nor, op); in spi_nor_read_any_reg()
336 * @nor: pointer to 'struct spi_nor'
345 int spi_nor_write_any_volatile_reg(struct spi_nor *nor, struct spi_mem_op *op, in spi_nor_write_any_volatile_reg() argument
350 if (!nor->spimem) in spi_nor_write_any_volatile_reg()
353 ret = spi_nor_write_enable(nor); in spi_nor_write_any_volatile_reg()
356 spi_nor_spimem_setup_op(nor, op, proto); in spi_nor_write_any_volatile_reg()
357 return spi_nor_spimem_exec_op(nor, op); in spi_nor_write_any_volatile_reg()
362 * @nor: pointer to 'struct spi_nor'.
366 int spi_nor_write_enable(struct spi_nor *nor) in spi_nor_write_enable() argument
370 if (nor->spimem) { in spi_nor_write_enable()
373 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_enable()
375 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_enable()
377 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WREN, in spi_nor_write_enable()
382 dev_dbg(nor->dev, "error %d on Write Enable\n", ret); in spi_nor_write_enable()
389 * @nor: pointer to 'struct spi_nor'.
393 int spi_nor_write_disable(struct spi_nor *nor) in spi_nor_write_disable() argument
397 if (nor->spimem) { in spi_nor_write_disable()
400 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_disable()
402 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_disable()
404 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRDI, in spi_nor_write_disable()
409 dev_dbg(nor->dev, "error %d on Write Disable\n", ret); in spi_nor_write_disable()
416 * @nor: pointer to 'struct spi_nor'.
427 int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 ndummy, u8 *id, in spi_nor_read_id() argument
432 if (nor->spimem) { in spi_nor_read_id()
436 spi_nor_spimem_setup_op(nor, &op, proto); in spi_nor_read_id()
437 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_id()
439 ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id, in spi_nor_read_id()
447 * @nor: pointer to 'struct spi_nor'.
453 int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) in spi_nor_read_sr() argument
457 if (nor->spimem) { in spi_nor_read_sr()
460 if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) { in spi_nor_read_sr()
461 op.addr.nbytes = nor->params->rdsr_addr_nbytes; in spi_nor_read_sr()
462 op.dummy.nbytes = nor->params->rdsr_dummy; in spi_nor_read_sr()
470 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_sr()
472 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_sr()
474 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr, in spi_nor_read_sr()
479 dev_dbg(nor->dev, "error %d reading SR\n", ret); in spi_nor_read_sr()
487 * @nor: pointer to 'struct spi_nor'
493 int spi_nor_read_cr(struct spi_nor *nor, u8 *cr) in spi_nor_read_cr() argument
497 if (nor->spimem) { in spi_nor_read_cr()
500 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_cr()
502 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_cr()
504 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDCR, cr, in spi_nor_read_cr()
509 dev_dbg(nor->dev, "error %d reading CR\n", ret); in spi_nor_read_cr()
518 * @nor: pointer to 'struct spi_nor'.
524 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
528 if (nor->spimem) { in spi_nor_set_4byte_addr_mode_en4b_ex4b()
531 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
533 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
535 ret = spi_nor_controller_ops_write_reg(nor, in spi_nor_set_4byte_addr_mode_en4b_ex4b()
542 dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); in spi_nor_set_4byte_addr_mode_en4b_ex4b()
551 * @nor: pointer to 'struct spi_nor'.
557 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
561 ret = spi_nor_write_enable(nor); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
565 ret = spi_nor_set_4byte_addr_mode_en4b_ex4b(nor, enable); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
569 return spi_nor_write_disable(nor); in spi_nor_set_4byte_addr_mode_wren_en4b_ex4b()
575 * @nor: pointer to 'struct spi_nor'.
586 int spi_nor_set_4byte_addr_mode_brwr(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode_brwr() argument
590 nor->bouncebuf[0] = enable << 7; in spi_nor_set_4byte_addr_mode_brwr()
592 if (nor->spimem) { in spi_nor_set_4byte_addr_mode_brwr()
593 struct spi_mem_op op = SPI_NOR_BRWR_OP(nor->bouncebuf); in spi_nor_set_4byte_addr_mode_brwr()
595 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_set_4byte_addr_mode_brwr()
597 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_set_4byte_addr_mode_brwr()
599 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_BRWR, in spi_nor_set_4byte_addr_mode_brwr()
600 nor->bouncebuf, 1); in spi_nor_set_4byte_addr_mode_brwr()
604 dev_dbg(nor->dev, "error %d setting 4-byte mode\n", ret); in spi_nor_set_4byte_addr_mode_brwr()
612 * @nor: pointer to 'struct spi_nor'.
616 int spi_nor_sr_ready(struct spi_nor *nor) in spi_nor_sr_ready() argument
620 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr_ready()
624 return !(nor->bouncebuf[0] & SR_WIP); in spi_nor_sr_ready()
629 * @nor: pointer to 'struct spi_nor'.
633 static bool spi_nor_use_parallel_locking(struct spi_nor *nor) in spi_nor_use_parallel_locking() argument
635 return nor->flags & SNOR_F_RWW; in spi_nor_use_parallel_locking()
639 static int spi_nor_rww_start_rdst(struct spi_nor *nor) in spi_nor_rww_start_rdst() argument
641 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_rdst()
644 mutex_lock(&nor->lock); in spi_nor_rww_start_rdst()
654 mutex_unlock(&nor->lock); in spi_nor_rww_start_rdst()
658 static void spi_nor_rww_end_rdst(struct spi_nor *nor) in spi_nor_rww_end_rdst() argument
660 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_rdst()
662 mutex_lock(&nor->lock); in spi_nor_rww_end_rdst()
667 mutex_unlock(&nor->lock); in spi_nor_rww_end_rdst()
670 static int spi_nor_lock_rdst(struct spi_nor *nor) in spi_nor_lock_rdst() argument
672 if (spi_nor_use_parallel_locking(nor)) in spi_nor_lock_rdst()
673 return spi_nor_rww_start_rdst(nor); in spi_nor_lock_rdst()
678 static void spi_nor_unlock_rdst(struct spi_nor *nor) in spi_nor_unlock_rdst() argument
680 if (spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_rdst()
681 spi_nor_rww_end_rdst(nor); in spi_nor_unlock_rdst()
682 wake_up(&nor->rww.wait); in spi_nor_unlock_rdst()
688 * @nor: pointer to 'struct spi_nor'.
692 static int spi_nor_ready(struct spi_nor *nor) in spi_nor_ready() argument
696 ret = spi_nor_lock_rdst(nor); in spi_nor_ready()
701 if (nor->params->ready) in spi_nor_ready()
702 ret = nor->params->ready(nor); in spi_nor_ready()
704 ret = spi_nor_sr_ready(nor); in spi_nor_ready()
706 spi_nor_unlock_rdst(nor); in spi_nor_ready()
714 * @nor: pointer to "struct spi_nor".
719 static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor, in spi_nor_wait_till_ready_with_timeout() argument
731 ret = spi_nor_ready(nor); in spi_nor_wait_till_ready_with_timeout()
740 dev_dbg(nor->dev, "flash operation timed out\n"); in spi_nor_wait_till_ready_with_timeout()
748 * @nor: pointer to "struct spi_nor".
752 int spi_nor_wait_till_ready(struct spi_nor *nor) in spi_nor_wait_till_ready() argument
754 return spi_nor_wait_till_ready_with_timeout(nor, in spi_nor_wait_till_ready()
760 * @nor: pointer to 'struct spi_nor'.
764 int spi_nor_global_block_unlock(struct spi_nor *nor) in spi_nor_global_block_unlock() argument
768 ret = spi_nor_write_enable(nor); in spi_nor_global_block_unlock()
772 if (nor->spimem) { in spi_nor_global_block_unlock()
775 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_global_block_unlock()
777 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_global_block_unlock()
779 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_GBULK, in spi_nor_global_block_unlock()
784 dev_dbg(nor->dev, "error %d on Global Block Unlock\n", ret); in spi_nor_global_block_unlock()
788 return spi_nor_wait_till_ready(nor); in spi_nor_global_block_unlock()
793 * @nor: pointer to 'struct spi_nor'.
799 int spi_nor_write_sr(struct spi_nor *nor, const u8 *sr, size_t len) in spi_nor_write_sr() argument
803 ret = spi_nor_write_enable(nor); in spi_nor_write_sr()
807 if (nor->spimem) { in spi_nor_write_sr()
810 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_sr()
812 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_sr()
814 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR, sr, in spi_nor_write_sr()
819 dev_dbg(nor->dev, "error %d writing SR\n", ret); in spi_nor_write_sr()
823 return spi_nor_wait_till_ready(nor); in spi_nor_write_sr()
829 * @nor: pointer to a 'struct spi_nor'.
834 static int spi_nor_write_sr1_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_sr1_and_check() argument
838 nor->bouncebuf[0] = sr1; in spi_nor_write_sr1_and_check()
840 ret = spi_nor_write_sr(nor, nor->bouncebuf, 1); in spi_nor_write_sr1_and_check()
844 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_write_sr1_and_check()
848 if (nor->bouncebuf[0] != sr1) { in spi_nor_write_sr1_and_check()
849 dev_dbg(nor->dev, "SR1: read back test failed\n"); in spi_nor_write_sr1_and_check()
861 * @nor: pointer to a 'struct spi_nor'.
866 static int spi_nor_write_16bit_sr_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_16bit_sr_and_check() argument
869 u8 *sr_cr = nor->bouncebuf; in spi_nor_write_16bit_sr_and_check()
873 if (!(nor->flags & SNOR_F_NO_READ_CR)) { in spi_nor_write_16bit_sr_and_check()
874 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_sr_and_check()
877 } else if (spi_nor_get_protocol_width(nor->read_proto) == 4 && in spi_nor_write_16bit_sr_and_check()
878 spi_nor_get_protocol_width(nor->write_proto) == 4 && in spi_nor_write_16bit_sr_and_check()
879 nor->params->quad_enable) { in spi_nor_write_16bit_sr_and_check()
887 * consequence of the nor->params->quad_enable() call. in spi_nor_write_16bit_sr_and_check()
901 ret = spi_nor_write_sr(nor, sr_cr, 2); in spi_nor_write_16bit_sr_and_check()
905 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_sr_and_check()
910 dev_dbg(nor->dev, "SR: Read back test failed\n"); in spi_nor_write_16bit_sr_and_check()
914 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_write_16bit_sr_and_check()
919 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_sr_and_check()
924 dev_dbg(nor->dev, "CR: read back test failed\n"); in spi_nor_write_16bit_sr_and_check()
936 * @nor: pointer to a 'struct spi_nor'.
941 int spi_nor_write_16bit_cr_and_check(struct spi_nor *nor, u8 cr) in spi_nor_write_16bit_cr_and_check() argument
944 u8 *sr_cr = nor->bouncebuf; in spi_nor_write_16bit_cr_and_check()
948 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_cr_and_check()
954 ret = spi_nor_write_sr(nor, sr_cr, 2); in spi_nor_write_16bit_cr_and_check()
960 ret = spi_nor_read_sr(nor, sr_cr); in spi_nor_write_16bit_cr_and_check()
965 dev_dbg(nor->dev, "SR: Read back test failed\n"); in spi_nor_write_16bit_cr_and_check()
969 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_write_16bit_cr_and_check()
972 ret = spi_nor_read_cr(nor, &sr_cr[1]); in spi_nor_write_16bit_cr_and_check()
977 dev_dbg(nor->dev, "CR: read back test failed\n"); in spi_nor_write_16bit_cr_and_check()
988 * @nor: pointer to a 'struct spi_nor'.
993 int spi_nor_write_sr_and_check(struct spi_nor *nor, u8 sr1) in spi_nor_write_sr_and_check() argument
995 if (nor->flags & SNOR_F_HAS_16BIT_SR) in spi_nor_write_sr_and_check()
996 return spi_nor_write_16bit_sr_and_check(nor, sr1); in spi_nor_write_sr_and_check()
998 return spi_nor_write_sr1_and_check(nor, sr1); in spi_nor_write_sr_and_check()
1004 * @nor: pointer to 'struct spi_nor'.
1009 static int spi_nor_write_sr2(struct spi_nor *nor, const u8 *sr2) in spi_nor_write_sr2() argument
1013 ret = spi_nor_write_enable(nor); in spi_nor_write_sr2()
1017 if (nor->spimem) { in spi_nor_write_sr2()
1020 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_write_sr2()
1022 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_write_sr2()
1024 ret = spi_nor_controller_ops_write_reg(nor, SPINOR_OP_WRSR2, in spi_nor_write_sr2()
1029 dev_dbg(nor->dev, "error %d writing SR2\n", ret); in spi_nor_write_sr2()
1033 return spi_nor_wait_till_ready(nor); in spi_nor_write_sr2()
1039 * @nor: pointer to 'struct spi_nor'.
1045 static int spi_nor_read_sr2(struct spi_nor *nor, u8 *sr2) in spi_nor_read_sr2() argument
1049 if (nor->spimem) { in spi_nor_read_sr2()
1052 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_read_sr2()
1054 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_read_sr2()
1056 ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR2, sr2, in spi_nor_read_sr2()
1061 dev_dbg(nor->dev, "error %d reading SR2\n", ret); in spi_nor_read_sr2()
1068 * @nor: pointer to 'struct spi_nor'.
1074 static int spi_nor_erase_die(struct spi_nor *nor, loff_t addr, size_t die_size) in spi_nor_erase_die() argument
1076 bool multi_die = nor->mtd.size != die_size; in spi_nor_erase_die()
1079 dev_dbg(nor->dev, " %lldKiB\n", (long long)(die_size >> 10)); in spi_nor_erase_die()
1081 if (nor->spimem) { in spi_nor_erase_die()
1083 SPI_NOR_DIE_ERASE_OP(nor->params->die_erase_opcode, in spi_nor_erase_die()
1084 nor->addr_nbytes, addr, multi_die); in spi_nor_erase_die()
1086 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_erase_die()
1088 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_erase_die()
1093 ret = spi_nor_controller_ops_write_reg(nor, in spi_nor_erase_die()
1099 dev_dbg(nor->dev, "error %d erasing chip\n", ret); in spi_nor_erase_die()
1163 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor) in spi_nor_has_uniform_erase() argument
1165 return !!nor->params->erase_map.uniform_region.erase_mask; in spi_nor_has_uniform_erase()
1168 static void spi_nor_set_4byte_opcodes(struct spi_nor *nor) in spi_nor_set_4byte_opcodes() argument
1170 nor->read_opcode = spi_nor_convert_3to4_read(nor->read_opcode); in spi_nor_set_4byte_opcodes()
1171 nor->program_opcode = spi_nor_convert_3to4_program(nor->program_opcode); in spi_nor_set_4byte_opcodes()
1172 nor->erase_opcode = spi_nor_convert_3to4_erase(nor->erase_opcode); in spi_nor_set_4byte_opcodes()
1174 if (!spi_nor_has_uniform_erase(nor)) { in spi_nor_set_4byte_opcodes()
1175 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_set_4byte_opcodes()
1187 static int spi_nor_prep(struct spi_nor *nor) in spi_nor_prep() argument
1191 if (nor->controller_ops && nor->controller_ops->prepare) in spi_nor_prep()
1192 ret = nor->controller_ops->prepare(nor); in spi_nor_prep()
1197 static void spi_nor_unprep(struct spi_nor *nor) in spi_nor_unprep() argument
1199 if (nor->controller_ops && nor->controller_ops->unprepare) in spi_nor_unprep()
1200 nor->controller_ops->unprepare(nor); in spi_nor_unprep()
1212 static bool spi_nor_rww_start_io(struct spi_nor *nor) in spi_nor_rww_start_io() argument
1214 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_io()
1217 mutex_lock(&nor->lock); in spi_nor_rww_start_io()
1226 mutex_unlock(&nor->lock); in spi_nor_rww_start_io()
1230 static void spi_nor_rww_end_io(struct spi_nor *nor) in spi_nor_rww_end_io() argument
1232 mutex_lock(&nor->lock); in spi_nor_rww_end_io()
1233 nor->rww.ongoing_io = false; in spi_nor_rww_end_io()
1234 mutex_unlock(&nor->lock); in spi_nor_rww_end_io()
1237 static int spi_nor_lock_device(struct spi_nor *nor) in spi_nor_lock_device() argument
1239 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_lock_device()
1242 return wait_event_killable(nor->rww.wait, spi_nor_rww_start_io(nor)); in spi_nor_lock_device()
1245 static void spi_nor_unlock_device(struct spi_nor *nor) in spi_nor_unlock_device() argument
1247 if (spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_device()
1248 spi_nor_rww_end_io(nor); in spi_nor_unlock_device()
1249 wake_up(&nor->rww.wait); in spi_nor_unlock_device()
1254 static bool spi_nor_rww_start_exclusive(struct spi_nor *nor) in spi_nor_rww_start_exclusive() argument
1256 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_exclusive()
1259 mutex_lock(&nor->lock); in spi_nor_rww_start_exclusive()
1270 mutex_unlock(&nor->lock); in spi_nor_rww_start_exclusive()
1274 static void spi_nor_rww_end_exclusive(struct spi_nor *nor) in spi_nor_rww_end_exclusive() argument
1276 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_exclusive()
1278 mutex_lock(&nor->lock); in spi_nor_rww_end_exclusive()
1282 mutex_unlock(&nor->lock); in spi_nor_rww_end_exclusive()
1285 int spi_nor_prep_and_lock(struct spi_nor *nor) in spi_nor_prep_and_lock() argument
1289 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock()
1293 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock()
1294 mutex_lock(&nor->lock); in spi_nor_prep_and_lock()
1296 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock()
1297 spi_nor_rww_start_exclusive(nor)); in spi_nor_prep_and_lock()
1302 void spi_nor_unlock_and_unprep(struct spi_nor *nor) in spi_nor_unlock_and_unprep() argument
1304 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep()
1305 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep()
1307 spi_nor_rww_end_exclusive(nor); in spi_nor_unlock_and_unprep()
1308 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep()
1311 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep()
1315 static bool spi_nor_rww_start_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_start_pe() argument
1317 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_pe()
1323 mutex_lock(&nor->lock); in spi_nor_rww_start_pe()
1328 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_start_pe()
1341 mutex_unlock(&nor->lock); in spi_nor_rww_start_pe()
1345 static void spi_nor_rww_end_pe(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_end_pe() argument
1347 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_pe()
1351 mutex_lock(&nor->lock); in spi_nor_rww_end_pe()
1353 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_end_pe()
1359 mutex_unlock(&nor->lock); in spi_nor_rww_end_pe()
1362 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
1366 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock_pe()
1370 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock_pe()
1371 mutex_lock(&nor->lock); in spi_nor_prep_and_lock_pe()
1373 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock_pe()
1374 spi_nor_rww_start_pe(nor, start, len)); in spi_nor_prep_and_lock_pe()
1379 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
1381 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep_pe()
1382 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep_pe()
1384 spi_nor_rww_end_pe(nor, start, len); in spi_nor_unlock_and_unprep_pe()
1385 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep_pe()
1388 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep_pe()
1392 static bool spi_nor_rww_start_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_start_rd() argument
1394 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_start_rd()
1400 mutex_lock(&nor->lock); in spi_nor_rww_start_rd()
1405 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_start_rd()
1419 mutex_unlock(&nor->lock); in spi_nor_rww_start_rd()
1423 static void spi_nor_rww_end_rd(struct spi_nor *nor, loff_t start, size_t len) in spi_nor_rww_end_rd() argument
1425 struct spi_nor_rww *rww = &nor->rww; in spi_nor_rww_end_rd()
1429 mutex_lock(&nor->lock); in spi_nor_rww_end_rd()
1431 spi_nor_offset_to_banks(nor->params->bank_size, start, len, &first, &last); in spi_nor_rww_end_rd()
1433 nor->rww.used_banks &= ~BIT(bank); in spi_nor_rww_end_rd()
1438 mutex_unlock(&nor->lock); in spi_nor_rww_end_rd()
1441 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
1445 ret = spi_nor_prep(nor); in spi_nor_prep_and_lock_rd()
1449 if (!spi_nor_use_parallel_locking(nor)) in spi_nor_prep_and_lock_rd()
1450 mutex_lock(&nor->lock); in spi_nor_prep_and_lock_rd()
1452 ret = wait_event_killable(nor->rww.wait, in spi_nor_prep_and_lock_rd()
1453 spi_nor_rww_start_rd(nor, start, len)); in spi_nor_prep_and_lock_rd()
1458 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
1460 if (!spi_nor_use_parallel_locking(nor)) { in spi_nor_unlock_and_unprep_rd()
1461 mutex_unlock(&nor->lock); in spi_nor_unlock_and_unprep_rd()
1463 spi_nor_rww_end_rd(nor, start, len); in spi_nor_unlock_and_unprep_rd()
1464 wake_up(&nor->rww.wait); in spi_nor_unlock_and_unprep_rd()
1467 spi_nor_unprep(nor); in spi_nor_unlock_and_unprep_rd()
1473 int spi_nor_erase_sector(struct spi_nor *nor, u32 addr) in spi_nor_erase_sector() argument
1477 if (nor->spimem) { in spi_nor_erase_sector()
1479 SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode, in spi_nor_erase_sector()
1480 nor->addr_nbytes, addr); in spi_nor_erase_sector()
1482 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_erase_sector()
1484 return spi_mem_exec_op(nor->spimem, &op); in spi_nor_erase_sector()
1485 } else if (nor->controller_ops->erase) { in spi_nor_erase_sector()
1486 return spi_nor_controller_ops_erase(nor, addr); in spi_nor_erase_sector()
1493 for (i = nor->addr_nbytes - 1; i >= 0; i--) { in spi_nor_erase_sector()
1494 nor->bouncebuf[i] = addr & 0xff; in spi_nor_erase_sector()
1498 return spi_nor_controller_ops_write_reg(nor, nor->erase_opcode, in spi_nor_erase_sector()
1499 nor->bouncebuf, nor->addr_nbytes); in spi_nor_erase_sector()
1504 * @erase: pointer to a structure that describes a SPI NOR erase type
1524 * @map: the erase map of the SPI NOR
1525 * @region: pointer to a structure that describes a SPI NOR erase region
1571 * @region: pointer to a structure that describes a SPI NOR erase region
1572 * @erase: pointer to a structure that describes a SPI NOR erase type
1615 * @nor: pointer to a 'struct spi_nor'
1626 static int spi_nor_init_erase_cmd_list(struct spi_nor *nor, in spi_nor_init_erase_cmd_list() argument
1630 const struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_init_erase_cmd_list()
1676 * @nor: pointer to a 'struct spi_nor'
1685 static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len) in spi_nor_erase_multi_sectors() argument
1691 ret = spi_nor_init_erase_cmd_list(nor, &erase_list, addr, len); in spi_nor_erase_multi_sectors()
1696 nor->erase_opcode = cmd->opcode; in spi_nor_erase_multi_sectors()
1698 …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()
1701 ret = spi_nor_lock_device(nor); in spi_nor_erase_multi_sectors()
1705 ret = spi_nor_write_enable(nor); in spi_nor_erase_multi_sectors()
1707 spi_nor_unlock_device(nor); in spi_nor_erase_multi_sectors()
1711 ret = spi_nor_erase_sector(nor, addr); in spi_nor_erase_multi_sectors()
1712 spi_nor_unlock_device(nor); in spi_nor_erase_multi_sectors()
1716 ret = spi_nor_wait_till_ready(nor); in spi_nor_erase_multi_sectors()
1734 static int spi_nor_erase_dice(struct spi_nor *nor, loff_t addr, in spi_nor_erase_dice() argument
1748 (unsigned long)(nor->mtd.size / SZ_2M)); in spi_nor_erase_dice()
1751 ret = spi_nor_lock_device(nor); in spi_nor_erase_dice()
1755 ret = spi_nor_write_enable(nor); in spi_nor_erase_dice()
1757 spi_nor_unlock_device(nor); in spi_nor_erase_dice()
1761 ret = spi_nor_erase_die(nor, addr, die_size); in spi_nor_erase_dice()
1763 spi_nor_unlock_device(nor); in spi_nor_erase_dice()
1767 ret = spi_nor_wait_till_ready_with_timeout(nor, timeout); in spi_nor_erase_dice()
1780 * Erase an address range on the nor chip. The address range may extend
1785 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_erase() local
1786 u8 n_dice = nor->params->n_dice; in spi_nor_erase()
1792 dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr, in spi_nor_erase()
1795 if (spi_nor_has_uniform_erase(nor)) { in spi_nor_erase()
1812 ret = spi_nor_prep_and_lock_pe(nor, instr->addr, instr->len); in spi_nor_erase()
1817 if ((len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) || in spi_nor_erase()
1819 ret = spi_nor_erase_dice(nor, addr, len, die_size); in spi_nor_erase()
1829 } else if (spi_nor_has_uniform_erase(nor)) { in spi_nor_erase()
1831 ret = spi_nor_lock_device(nor); in spi_nor_erase()
1835 ret = spi_nor_write_enable(nor); in spi_nor_erase()
1837 spi_nor_unlock_device(nor); in spi_nor_erase()
1841 ret = spi_nor_erase_sector(nor, addr); in spi_nor_erase()
1842 spi_nor_unlock_device(nor); in spi_nor_erase()
1846 ret = spi_nor_wait_till_ready(nor); in spi_nor_erase()
1856 ret = spi_nor_erase_multi_sectors(nor, addr, len); in spi_nor_erase()
1861 ret = spi_nor_write_disable(nor); in spi_nor_erase()
1864 spi_nor_unlock_and_unprep_pe(nor, instr->addr, instr->len); in spi_nor_erase()
1872 * @nor: pointer to a 'struct spi_nor'
1878 int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor) in spi_nor_sr1_bit6_quad_enable() argument
1882 ret = spi_nor_read_sr(nor, nor->bouncebuf); in spi_nor_sr1_bit6_quad_enable()
1886 if (nor->bouncebuf[0] & SR1_QUAD_EN_BIT6) in spi_nor_sr1_bit6_quad_enable()
1889 nor->bouncebuf[0] |= SR1_QUAD_EN_BIT6; in spi_nor_sr1_bit6_quad_enable()
1891 return spi_nor_write_sr1_and_check(nor, nor->bouncebuf[0]); in spi_nor_sr1_bit6_quad_enable()
1897 * @nor: pointer to a 'struct spi_nor'.
1903 int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor) in spi_nor_sr2_bit1_quad_enable() argument
1907 if (nor->flags & SNOR_F_NO_READ_CR) in spi_nor_sr2_bit1_quad_enable()
1908 return spi_nor_write_16bit_cr_and_check(nor, SR2_QUAD_EN_BIT1); in spi_nor_sr2_bit1_quad_enable()
1910 ret = spi_nor_read_cr(nor, nor->bouncebuf); in spi_nor_sr2_bit1_quad_enable()
1914 if (nor->bouncebuf[0] & SR2_QUAD_EN_BIT1) in spi_nor_sr2_bit1_quad_enable()
1917 nor->bouncebuf[0] |= SR2_QUAD_EN_BIT1; in spi_nor_sr2_bit1_quad_enable()
1919 return spi_nor_write_16bit_cr_and_check(nor, nor->bouncebuf[0]); in spi_nor_sr2_bit1_quad_enable()
1924 * @nor: pointer to a 'struct spi_nor'
1934 int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor) in spi_nor_sr2_bit7_quad_enable() argument
1936 u8 *sr2 = nor->bouncebuf; in spi_nor_sr2_bit7_quad_enable()
1941 ret = spi_nor_read_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1950 ret = spi_nor_write_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1957 ret = spi_nor_read_sr2(nor, sr2); in spi_nor_sr2_bit7_quad_enable()
1962 dev_dbg(nor->dev, "SR2: Read back test failed\n"); in spi_nor_sr2_bit7_quad_enable()
1987 .name = "spi-nor-generic",
1990 static const struct flash_info *spi_nor_match_id(struct spi_nor *nor, in spi_nor_match_id() argument
2001 nor->manufacturer = manufacturers[i]; in spi_nor_match_id()
2010 static const struct flash_info *spi_nor_detect(struct spi_nor *nor) in spi_nor_detect() argument
2013 u8 *id = nor->bouncebuf; in spi_nor_detect()
2016 ret = spi_nor_read_id(nor, 0, 0, id, nor->reg_proto); in spi_nor_detect()
2018 dev_dbg(nor->dev, "error %d reading JEDEC ID\n", ret); in spi_nor_detect()
2023 nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL); in spi_nor_detect()
2024 if (!nor->id) in spi_nor_detect()
2027 info = spi_nor_match_id(nor, id); in spi_nor_detect()
2031 ret = spi_nor_check_sfdp_signature(nor); in spi_nor_detect()
2037 dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", in spi_nor_detect()
2047 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_read() local
2052 dev_dbg(nor->dev, "from 0x%08x, len %zd\n", (u32)from, len); in spi_nor_read()
2054 ret = spi_nor_prep_and_lock_rd(nor, from_lock, len_lock); in spi_nor_read()
2061 ret = spi_nor_read_data(nor, addr, len, buf); in spi_nor_read()
2079 spi_nor_unlock_and_unprep_rd(nor, from_lock, len_lock); in spi_nor_read()
2085 * Write an address range to the nor chip. Data must be written in
2092 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_write() local
2095 u32 page_size = nor->params->page_size; in spi_nor_write()
2097 dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); in spi_nor_write()
2099 ret = spi_nor_prep_and_lock_pe(nor, to, len); in spi_nor_write()
2110 ret = spi_nor_lock_device(nor); in spi_nor_write()
2114 ret = spi_nor_write_enable(nor); in spi_nor_write()
2116 spi_nor_unlock_device(nor); in spi_nor_write()
2120 ret = spi_nor_write_data(nor, addr, page_remain, buf + i); in spi_nor_write()
2121 spi_nor_unlock_device(nor); in spi_nor_write()
2126 ret = spi_nor_wait_till_ready(nor); in spi_nor_write()
2134 spi_nor_unlock_and_unprep_pe(nor, to, len); in spi_nor_write()
2139 static int spi_nor_check(struct spi_nor *nor) in spi_nor_check() argument
2141 if (!nor->dev || in spi_nor_check()
2142 (!nor->spimem && !nor->controller_ops) || in spi_nor_check()
2143 (!nor->spimem && nor->controller_ops && in spi_nor_check()
2144 (!nor->controller_ops->read || in spi_nor_check()
2145 !nor->controller_ops->write || in spi_nor_check()
2146 !nor->controller_ops->read_reg || in spi_nor_check()
2147 !nor->controller_ops->write_reg))) { in spi_nor_check()
2148 pr_err("spi-nor: please fill all the necessary fields!\n"); in spi_nor_check()
2152 if (nor->spimem && nor->controller_ops) { in spi_nor_check()
2153 …dev_err(nor->dev, "nor->spimem and nor->controller_ops are mutually exclusive, please set just one… in spi_nor_check()
2236 *@nor: pointer to a 'struct spi_nor'
2241 static int spi_nor_spimem_check_op(struct spi_nor *nor, in spi_nor_spimem_check_op() argument
2251 if (!spi_mem_supports_op(nor->spimem, op)) { in spi_nor_spimem_check_op()
2252 if (nor->params->size > SZ_16M) in spi_nor_spimem_check_op()
2257 if (!spi_mem_supports_op(nor->spimem, op)) in spi_nor_spimem_check_op()
2267 *@nor: pointer to a 'struct spi_nor'
2272 static int spi_nor_spimem_check_readop(struct spi_nor *nor, in spi_nor_spimem_check_readop() argument
2277 spi_nor_spimem_setup_op(nor, &op, read->proto); in spi_nor_spimem_check_readop()
2282 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_spimem_check_readop()
2285 return spi_nor_spimem_check_op(nor, &op); in spi_nor_spimem_check_readop()
2291 *@nor: pointer to a 'struct spi_nor'
2296 static int spi_nor_spimem_check_pp(struct spi_nor *nor, in spi_nor_spimem_check_pp() argument
2301 spi_nor_spimem_setup_op(nor, &op, pp->proto); in spi_nor_spimem_check_pp()
2303 return spi_nor_spimem_check_op(nor, &op); in spi_nor_spimem_check_pp()
2309 * @nor: pointer to a 'struct spi_nor'
2314 spi_nor_spimem_adjust_hwcaps(struct spi_nor *nor, u32 *hwcaps) in spi_nor_spimem_adjust_hwcaps() argument
2316 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_spimem_adjust_hwcaps()
2326 if (nor->flags & SNOR_F_BROKEN_RESET) in spi_nor_spimem_adjust_hwcaps()
2337 spi_nor_spimem_check_readop(nor, ¶ms->reads[rdidx])) in spi_nor_spimem_adjust_hwcaps()
2344 if (spi_nor_spimem_check_pp(nor, in spi_nor_spimem_adjust_hwcaps()
2351 * spi_nor_set_erase_type() - set a SPI NOR erase type
2352 * @erase: pointer to a structure that describes a SPI NOR erase type
2367 * spi_nor_mask_erase_type() - mask out a SPI NOR erase type
2368 * @erase: pointer to a structure that describes a SPI NOR erase type
2377 * @map: the erase map of the SPI NOR
2380 * @flash_size: the spi nor flash memory size
2392 int spi_nor_post_bfpt_fixups(struct spi_nor *nor, in spi_nor_post_bfpt_fixups() argument
2398 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_post_bfpt_fixups()
2399 nor->manufacturer->fixups->post_bfpt) { in spi_nor_post_bfpt_fixups()
2400 ret = nor->manufacturer->fixups->post_bfpt(nor, bfpt_header, in spi_nor_post_bfpt_fixups()
2406 if (nor->info->fixups && nor->info->fixups->post_bfpt) in spi_nor_post_bfpt_fixups()
2407 return nor->info->fixups->post_bfpt(nor, bfpt_header, bfpt); in spi_nor_post_bfpt_fixups()
2412 static int spi_nor_select_read(struct spi_nor *nor, in spi_nor_select_read() argument
2425 read = &nor->params->reads[cmd]; in spi_nor_select_read()
2426 nor->read_opcode = read->opcode; in spi_nor_select_read()
2427 nor->read_proto = read->proto; in spi_nor_select_read()
2430 * In the SPI NOR framework, we don't need to make the difference in spi_nor_select_read()
2439 nor->read_dummy = read->num_mode_clocks + read->num_wait_states; in spi_nor_select_read()
2443 static int spi_nor_select_pp(struct spi_nor *nor, in spi_nor_select_pp() argument
2456 pp = &nor->params->page_programs[cmd]; in spi_nor_select_pp()
2457 nor->program_opcode = pp->opcode; in spi_nor_select_pp()
2458 nor->write_proto = pp->proto; in spi_nor_select_pp()
2464 * @map: the erase map of the SPI NOR
2519 static int spi_nor_select_erase(struct spi_nor *nor) in spi_nor_select_erase() argument
2521 struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_select_erase()
2523 struct mtd_info *mtd = &nor->mtd; in spi_nor_select_erase()
2534 if (spi_nor_has_uniform_erase(nor)) { in spi_nor_select_erase()
2538 nor->erase_opcode = erase->opcode; in spi_nor_select_erase()
2545 * maximum erase sector size. No need to set nor->erase_opcode. in spi_nor_select_erase()
2561 static int spi_nor_set_addr_nbytes(struct spi_nor *nor) in spi_nor_set_addr_nbytes() argument
2563 if (nor->params->addr_nbytes) { in spi_nor_set_addr_nbytes()
2564 nor->addr_nbytes = nor->params->addr_nbytes; in spi_nor_set_addr_nbytes()
2565 } else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) { in spi_nor_set_addr_nbytes()
2578 nor->addr_nbytes = 4; in spi_nor_set_addr_nbytes()
2579 } else if (nor->info->addr_nbytes) { in spi_nor_set_addr_nbytes()
2580 nor->addr_nbytes = nor->info->addr_nbytes; in spi_nor_set_addr_nbytes()
2582 nor->addr_nbytes = 3; in spi_nor_set_addr_nbytes()
2585 if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) { in spi_nor_set_addr_nbytes()
2587 nor->addr_nbytes = 4; in spi_nor_set_addr_nbytes()
2590 if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) { in spi_nor_set_addr_nbytes()
2591 dev_dbg(nor->dev, "The number of address bytes is too large: %u\n", in spi_nor_set_addr_nbytes()
2592 nor->addr_nbytes); in spi_nor_set_addr_nbytes()
2597 if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES && in spi_nor_set_addr_nbytes()
2598 !(nor->flags & SNOR_F_HAS_4BAIT)) in spi_nor_set_addr_nbytes()
2599 spi_nor_set_4byte_opcodes(nor); in spi_nor_set_addr_nbytes()
2604 static int spi_nor_setup(struct spi_nor *nor, in spi_nor_setup() argument
2607 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_setup()
2617 if (nor->spimem) { in spi_nor_setup()
2623 spi_nor_spimem_adjust_hwcaps(nor, &shared_mask); in spi_nor_setup()
2632 dev_dbg(nor->dev, in spi_nor_setup()
2639 err = spi_nor_select_read(nor, shared_mask); in spi_nor_setup()
2641 dev_dbg(nor->dev, in spi_nor_setup()
2647 err = spi_nor_select_pp(nor, shared_mask); in spi_nor_setup()
2649 dev_dbg(nor->dev, in spi_nor_setup()
2655 err = spi_nor_select_erase(nor); in spi_nor_setup()
2657 dev_dbg(nor->dev, in spi_nor_setup()
2662 return spi_nor_set_addr_nbytes(nor); in spi_nor_setup()
2668 * @nor: pointer to a 'struct spi_nor'.
2670 static void spi_nor_manufacturer_init_params(struct spi_nor *nor) in spi_nor_manufacturer_init_params() argument
2672 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_manufacturer_init_params()
2673 nor->manufacturer->fixups->default_init) in spi_nor_manufacturer_init_params()
2674 nor->manufacturer->fixups->default_init(nor); in spi_nor_manufacturer_init_params()
2676 if (nor->info->fixups && nor->info->fixups->default_init) in spi_nor_manufacturer_init_params()
2677 nor->info->fixups->default_init(nor); in spi_nor_manufacturer_init_params()
2682 * settings based on nor->info->sfdp_flags. This method should be called only by
2687 * @nor: pointer to a 'struct spi_nor'.
2689 static void spi_nor_no_sfdp_init_params(struct spi_nor *nor) in spi_nor_no_sfdp_init_params() argument
2691 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_no_sfdp_init_params()
2693 const struct flash_info *info = nor->info; in spi_nor_no_sfdp_init_params()
2755 * spi_nor_init_flags() - Initialize NOR flags for settings that are not defined
2757 * @nor: pointer to a 'struct spi_nor'
2759 static void spi_nor_init_flags(struct spi_nor *nor) in spi_nor_init_flags() argument
2761 struct device_node *np = spi_nor_get_flash_node(nor); in spi_nor_init_flags()
2762 const u16 flags = nor->info->flags; in spi_nor_init_flags()
2765 nor->flags |= SNOR_F_BROKEN_RESET; in spi_nor_init_flags()
2768 nor->flags |= SNOR_F_NO_WP; in spi_nor_init_flags()
2771 nor->flags |= SNOR_F_SWP_IS_VOLATILE; in spi_nor_init_flags()
2774 nor->flags |= SNOR_F_HAS_LOCK; in spi_nor_init_flags()
2777 nor->flags |= SNOR_F_HAS_SR_TB; in spi_nor_init_flags()
2779 nor->flags |= SNOR_F_HAS_SR_TB_BIT6; in spi_nor_init_flags()
2783 nor->flags |= SNOR_F_HAS_4BIT_BP; in spi_nor_init_flags()
2785 nor->flags |= SNOR_F_HAS_SR_BP3_BIT6; in spi_nor_init_flags()
2788 if (flags & SPI_NOR_RWW && nor->params->n_banks > 1 && in spi_nor_init_flags()
2789 !nor->controller_ops) in spi_nor_init_flags()
2790 nor->flags |= SNOR_F_RWW; in spi_nor_init_flags()
2794 * spi_nor_init_fixup_flags() - Initialize NOR flags for settings that can not
2799 * @nor: pointer to a 'struct spi_nor'
2801 static void spi_nor_init_fixup_flags(struct spi_nor *nor) in spi_nor_init_fixup_flags() argument
2803 const u8 fixup_flags = nor->info->fixup_flags; in spi_nor_init_fixup_flags()
2806 nor->flags |= SNOR_F_4B_OPCODES; in spi_nor_init_fixup_flags()
2809 nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE; in spi_nor_init_fixup_flags()
2814 * @nor: pointer to a 'struct spi_nor'
2820 static int spi_nor_late_init_params(struct spi_nor *nor) in spi_nor_late_init_params() argument
2822 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_late_init_params()
2825 if (nor->manufacturer && nor->manufacturer->fixups && in spi_nor_late_init_params()
2826 nor->manufacturer->fixups->late_init) { in spi_nor_late_init_params()
2827 ret = nor->manufacturer->fixups->late_init(nor); in spi_nor_late_init_params()
2833 spi_nor_init_flags(nor); in spi_nor_late_init_params()
2835 if (nor->info->fixups && nor->info->fixups->late_init) { in spi_nor_late_init_params()
2836 ret = nor->info->fixups->late_init(nor); in spi_nor_late_init_params()
2841 if (!nor->params->die_erase_opcode) in spi_nor_late_init_params()
2842 nor->params->die_erase_opcode = SPINOR_OP_CHIP_ERASE; in spi_nor_late_init_params()
2848 spi_nor_init_fixup_flags(nor); in spi_nor_late_init_params()
2851 * NOR protection support. When locking_ops are not provided, we pick in spi_nor_late_init_params()
2854 if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops) in spi_nor_late_init_params()
2855 spi_nor_init_default_locking_ops(nor); in spi_nor_late_init_params()
2866 * @nor: pointer to a 'struct spi_nor'.
2871 static void spi_nor_sfdp_init_params_deprecated(struct spi_nor *nor) in spi_nor_sfdp_init_params_deprecated() argument
2875 memcpy(&sfdp_params, nor->params, sizeof(sfdp_params)); in spi_nor_sfdp_init_params_deprecated()
2877 if (spi_nor_parse_sfdp(nor)) { in spi_nor_sfdp_init_params_deprecated()
2878 memcpy(nor->params, &sfdp_params, sizeof(*nor->params)); in spi_nor_sfdp_init_params_deprecated()
2879 nor->flags &= ~SNOR_F_4B_OPCODES; in spi_nor_sfdp_init_params_deprecated()
2886 * @nor: pointer to a 'struct spi_nor'.
2892 static void spi_nor_init_params_deprecated(struct spi_nor *nor) in spi_nor_init_params_deprecated() argument
2894 spi_nor_no_sfdp_init_params(nor); in spi_nor_init_params_deprecated()
2896 spi_nor_manufacturer_init_params(nor); in spi_nor_init_params_deprecated()
2898 if (nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ | in spi_nor_init_params_deprecated()
2902 spi_nor_sfdp_init_params_deprecated(nor); in spi_nor_init_params_deprecated()
2909 * @nor: pointer to a 'struct spi_nor'.
2911 static void spi_nor_init_default_params(struct spi_nor *nor) in spi_nor_init_default_params() argument
2913 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_init_default_params()
2914 const struct flash_info *info = nor->info; in spi_nor_init_default_params()
2915 struct device_node *np = spi_nor_get_flash_node(nor); in spi_nor_init_default_params()
2921 nor->flags |= SNOR_F_HAS_16BIT_SR; in spi_nor_init_default_params()
2923 /* Set SPI NOR sizes. */ in spi_nor_init_default_params()
2958 * @nor: pointer to a 'struct spi_nor'.
2964 * based on nor->info data:
2993 static int spi_nor_init_params(struct spi_nor *nor) in spi_nor_init_params() argument
2997 nor->params = devm_kzalloc(nor->dev, sizeof(*nor->params), GFP_KERNEL); in spi_nor_init_params()
2998 if (!nor->params) in spi_nor_init_params()
3001 spi_nor_init_default_params(nor); in spi_nor_init_params()
3003 if (spi_nor_needs_sfdp(nor)) { in spi_nor_init_params()
3004 ret = spi_nor_parse_sfdp(nor); in spi_nor_init_params()
3006 …dev_err(nor->dev, "BFPT parsing failed. Please consider using SPI_NOR_SKIP_SFDP when declaring the… in spi_nor_init_params()
3009 } else if (nor->info->no_sfdp_flags & SPI_NOR_SKIP_SFDP) { in spi_nor_init_params()
3010 spi_nor_no_sfdp_init_params(nor); in spi_nor_init_params()
3012 spi_nor_init_params_deprecated(nor); in spi_nor_init_params()
3015 ret = spi_nor_late_init_params(nor); in spi_nor_init_params()
3019 if (WARN_ON(!is_power_of_2(nor->params->page_size))) in spi_nor_init_params()
3026 * @nor: pointer to a 'struct spi_nor'
3031 static int spi_nor_set_octal_dtr(struct spi_nor *nor, bool enable) in spi_nor_set_octal_dtr() argument
3035 if (!nor->params->set_octal_dtr) in spi_nor_set_octal_dtr()
3038 if (!(nor->read_proto == SNOR_PROTO_8_8_8_DTR && in spi_nor_set_octal_dtr()
3039 nor->write_proto == SNOR_PROTO_8_8_8_DTR)) in spi_nor_set_octal_dtr()
3042 if (!(nor->flags & SNOR_F_IO_MODE_EN_VOLATILE)) in spi_nor_set_octal_dtr()
3045 ret = nor->params->set_octal_dtr(nor, enable); in spi_nor_set_octal_dtr()
3050 nor->reg_proto = SNOR_PROTO_8_8_8_DTR; in spi_nor_set_octal_dtr()
3052 nor->reg_proto = SNOR_PROTO_1_1_1; in spi_nor_set_octal_dtr()
3059 * @nor: pointer to a 'struct spi_nor'
3063 static int spi_nor_quad_enable(struct spi_nor *nor) in spi_nor_quad_enable() argument
3065 if (!nor->params->quad_enable) in spi_nor_quad_enable()
3068 if (!(spi_nor_get_protocol_width(nor->read_proto) == 4 || in spi_nor_quad_enable()
3069 spi_nor_get_protocol_width(nor->write_proto) == 4)) in spi_nor_quad_enable()
3072 return nor->params->quad_enable(nor); in spi_nor_quad_enable()
3077 * @nor: pointer to a 'struct spi_nor'.
3082 int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable) in spi_nor_set_4byte_addr_mode() argument
3084 struct spi_nor_flash_parameter *params = nor->params; in spi_nor_set_4byte_addr_mode()
3095 WARN_ONCE(nor->flags & SNOR_F_BROKEN_RESET, in spi_nor_set_4byte_addr_mode()
3099 ret = params->set_4byte_addr_mode(nor, enable); in spi_nor_set_4byte_addr_mode()
3114 static int spi_nor_init(struct spi_nor *nor) in spi_nor_init() argument
3118 err = spi_nor_set_octal_dtr(nor, true); in spi_nor_init()
3120 dev_dbg(nor->dev, "octal mode not supported\n"); in spi_nor_init()
3124 err = spi_nor_quad_enable(nor); in spi_nor_init()
3126 dev_dbg(nor->dev, "quad mode not supported\n"); in spi_nor_init()
3131 * Some SPI NOR flashes are write protected by default after a power-on in spi_nor_init()
3142 nor->flags & SNOR_F_SWP_IS_VOLATILE)) in spi_nor_init()
3143 spi_nor_try_unlock_all(nor); in spi_nor_init()
3145 if (nor->addr_nbytes == 4 && in spi_nor_init()
3146 nor->read_proto != SNOR_PROTO_8_8_8_DTR && in spi_nor_init()
3147 !(nor->flags & SNOR_F_4B_OPCODES)) in spi_nor_init()
3148 return spi_nor_set_4byte_addr_mode(nor, true); in spi_nor_init()
3155 * @nor: pointer to 'struct spi_nor'
3168 static void spi_nor_soft_reset(struct spi_nor *nor) in spi_nor_soft_reset() argument
3175 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_soft_reset()
3177 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_soft_reset()
3180 dev_warn(nor->dev, "Software reset failed: %d\n", ret); in spi_nor_soft_reset()
3186 spi_nor_spimem_setup_op(nor, &op, nor->reg_proto); in spi_nor_soft_reset()
3188 ret = spi_mem_exec_op(nor->spimem, &op); in spi_nor_soft_reset()
3190 dev_warn(nor->dev, "Software reset failed: %d\n", ret); in spi_nor_soft_reset()
3205 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_suspend() local
3209 ret = spi_nor_set_octal_dtr(nor, false); in spi_nor_suspend()
3211 dev_err(nor->dev, "suspend() failed\n"); in spi_nor_suspend()
3219 struct spi_nor *nor = mtd_to_spi_nor(mtd); in spi_nor_resume() local
3220 struct device *dev = nor->dev; in spi_nor_resume()
3223 /* re-initialize the nor chip */ in spi_nor_resume()
3224 ret = spi_nor_init(nor); in spi_nor_resume()
3232 struct spi_nor *nor = mtd_to_spi_nor(master); in spi_nor_get_device() local
3235 if (nor->spimem) in spi_nor_get_device()
3236 dev = nor->spimem->spi->controller->dev.parent; in spi_nor_get_device()
3238 dev = nor->dev; in spi_nor_get_device()
3249 struct spi_nor *nor = mtd_to_spi_nor(master); in spi_nor_put_device() local
3252 if (nor->spimem) in spi_nor_put_device()
3253 dev = nor->spimem->spi->controller->dev.parent; in spi_nor_put_device()
3255 dev = nor->dev; in spi_nor_put_device()
3260 static void spi_nor_restore(struct spi_nor *nor) in spi_nor_restore() argument
3265 if (nor->addr_nbytes == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && in spi_nor_restore()
3266 nor->flags & SNOR_F_BROKEN_RESET) { in spi_nor_restore()
3267 ret = spi_nor_set_4byte_addr_mode(nor, false); in spi_nor_restore()
3274 dev_err(nor->dev, "Failed to exit 4-byte address mode, err = %d\n", ret); in spi_nor_restore()
3277 if (nor->flags & SNOR_F_SOFT_RESET) in spi_nor_restore()
3278 spi_nor_soft_reset(nor); in spi_nor_restore()
3281 static const struct flash_info *spi_nor_match_name(struct spi_nor *nor, in spi_nor_match_name() argument
3290 nor->manufacturer = manufacturers[i]; in spi_nor_match_name()
3299 static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, in spi_nor_get_flash_info() argument
3305 info = spi_nor_match_name(nor, name); in spi_nor_get_flash_info()
3314 jinfo = spi_nor_detect(nor); in spi_nor_get_flash_info()
3323 dev_warn(nor->dev, "found %s, expected %s\n", in spi_nor_get_flash_info()
3350 static int spi_nor_set_mtd_eraseregions(struct spi_nor *nor) in spi_nor_set_mtd_eraseregions() argument
3352 const struct spi_nor_erase_map *map = &nor->params->erase_map; in spi_nor_set_mtd_eraseregions()
3355 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_eraseregions()
3358 mtd_region = devm_kcalloc(nor->dev, map->n_regions, sizeof(*mtd_region), in spi_nor_set_mtd_eraseregions()
3380 static int spi_nor_set_mtd_info(struct spi_nor *nor) in spi_nor_set_mtd_info() argument
3382 struct mtd_info *mtd = &nor->mtd; in spi_nor_set_mtd_info()
3383 struct device *dev = nor->dev; in spi_nor_set_mtd_info()
3385 spi_nor_set_mtd_locking_ops(nor); in spi_nor_set_mtd_info()
3386 spi_nor_set_mtd_otp_ops(nor); in spi_nor_set_mtd_info()
3393 /* Unset BIT_WRITEABLE to enable JFFS2 write buffer for ECC'd NOR */ in spi_nor_set_mtd_info()
3394 if (nor->flags & SNOR_F_ECC) in spi_nor_set_mtd_info()
3396 if (nor->info->flags & SPI_NOR_NO_ERASE) in spi_nor_set_mtd_info()
3400 mtd->writesize = nor->params->writesize; in spi_nor_set_mtd_info()
3401 mtd->writebufsize = nor->params->page_size; in spi_nor_set_mtd_info()
3402 mtd->size = nor->params->size; in spi_nor_set_mtd_info()
3412 if (!spi_nor_has_uniform_erase(nor)) in spi_nor_set_mtd_info()
3413 return spi_nor_set_mtd_eraseregions(nor); in spi_nor_set_mtd_info()
3418 static int spi_nor_hw_reset(struct spi_nor *nor) in spi_nor_hw_reset() argument
3422 reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW); in spi_nor_hw_reset()
3439 int spi_nor_scan(struct spi_nor *nor, const char *name, in spi_nor_scan() argument
3443 struct device *dev = nor->dev; in spi_nor_scan()
3446 ret = spi_nor_check(nor); in spi_nor_scan()
3451 nor->reg_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3452 nor->read_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3453 nor->write_proto = SNOR_PROTO_1_1_1; in spi_nor_scan()
3459 * nor->params->page_size turns out to be greater than PAGE_SIZE (which in spi_nor_scan()
3460 * shouldn't happen before long since NOR pages are usually less in spi_nor_scan()
3463 nor->bouncebuf_size = PAGE_SIZE; in spi_nor_scan()
3464 nor->bouncebuf = devm_kmalloc(dev, nor->bouncebuf_size, in spi_nor_scan()
3466 if (!nor->bouncebuf) in spi_nor_scan()
3469 ret = spi_nor_hw_reset(nor); in spi_nor_scan()
3473 info = spi_nor_get_flash_info(nor, name); in spi_nor_scan()
3477 nor->info = info; in spi_nor_scan()
3479 mutex_init(&nor->lock); in spi_nor_scan()
3482 ret = spi_nor_init_params(nor); in spi_nor_scan()
3486 if (spi_nor_use_parallel_locking(nor)) in spi_nor_scan()
3487 init_waitqueue_head(&nor->rww.wait); in spi_nor_scan()
3496 ret = spi_nor_setup(nor, hwcaps); in spi_nor_scan()
3501 ret = spi_nor_init(nor); in spi_nor_scan()
3506 ret = spi_nor_set_mtd_info(nor); in spi_nor_scan()
3511 SPI_NOR_MAX_ID_LEN, nor->id); in spi_nor_scan()
3517 static int spi_nor_create_read_dirmap(struct spi_nor *nor) in spi_nor_create_read_dirmap() argument
3520 .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), in spi_nor_create_read_dirmap()
3521 SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), in spi_nor_create_read_dirmap()
3522 SPI_MEM_OP_DUMMY(nor->read_dummy, 0), in spi_nor_create_read_dirmap()
3525 .length = nor->params->size, in spi_nor_create_read_dirmap()
3529 spi_nor_spimem_setup_op(nor, op, nor->read_proto); in spi_nor_create_read_dirmap()
3532 op->dummy.nbytes = (nor->read_dummy * op->dummy.buswidth) / 8; in spi_nor_create_read_dirmap()
3533 if (spi_nor_protocol_is_dtr(nor->read_proto)) in spi_nor_create_read_dirmap()
3541 op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->read_proto); in spi_nor_create_read_dirmap()
3543 nor->dirmap.rdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, in spi_nor_create_read_dirmap()
3545 return PTR_ERR_OR_ZERO(nor->dirmap.rdesc); in spi_nor_create_read_dirmap()
3548 static int spi_nor_create_write_dirmap(struct spi_nor *nor) in spi_nor_create_write_dirmap() argument
3551 .op_tmpl = SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), in spi_nor_create_write_dirmap()
3552 SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), in spi_nor_create_write_dirmap()
3556 .length = nor->params->size, in spi_nor_create_write_dirmap()
3560 if (nor->program_opcode == SPINOR_OP_AAI_WP && nor->sst_write_second) in spi_nor_create_write_dirmap()
3563 spi_nor_spimem_setup_op(nor, op, nor->write_proto); in spi_nor_create_write_dirmap()
3570 op->data.buswidth = spi_nor_get_protocol_data_nbits(nor->write_proto); in spi_nor_create_write_dirmap()
3572 nor->dirmap.wdesc = devm_spi_mem_dirmap_create(nor->dev, nor->spimem, in spi_nor_create_write_dirmap()
3574 return PTR_ERR_OR_ZERO(nor->dirmap.wdesc); in spi_nor_create_write_dirmap()
3582 struct spi_nor *nor; in spi_nor_probe() local
3595 nor = devm_kzalloc(dev, sizeof(*nor), GFP_KERNEL); in spi_nor_probe()
3596 if (!nor) in spi_nor_probe()
3599 nor->spimem = spimem; in spi_nor_probe()
3600 nor->dev = dev; in spi_nor_probe()
3601 spi_nor_set_flash_node(nor, dev->of_node); in spi_nor_probe()
3603 spi_mem_set_drvdata(spimem, nor); in spi_nor_probe()
3606 nor->mtd.name = data->name; in spi_nor_probe()
3608 if (!nor->mtd.name) in spi_nor_probe()
3609 nor->mtd.name = spi_mem_get_name(spimem); in spi_nor_probe()
3619 else if (!strcmp(spi->modalias, "spi-nor")) in spi_nor_probe()
3624 ret = spi_nor_scan(nor, flash_name, &hwcaps); in spi_nor_probe()
3628 spi_nor_debugfs_register(nor); in spi_nor_probe()
3633 * a NOR we don't end up with buffer overflows. in spi_nor_probe()
3635 if (nor->params->page_size > PAGE_SIZE) { in spi_nor_probe()
3636 nor->bouncebuf_size = nor->params->page_size; in spi_nor_probe()
3637 devm_kfree(dev, nor->bouncebuf); in spi_nor_probe()
3638 nor->bouncebuf = devm_kmalloc(dev, nor->bouncebuf_size, in spi_nor_probe()
3640 if (!nor->bouncebuf) in spi_nor_probe()
3644 ret = spi_nor_create_read_dirmap(nor); in spi_nor_probe()
3648 ret = spi_nor_create_write_dirmap(nor); in spi_nor_probe()
3652 return mtd_device_register(&nor->mtd, data ? data->parts : NULL, in spi_nor_probe()
3658 struct spi_nor *nor = spi_mem_get_drvdata(spimem); in spi_nor_remove() local
3660 spi_nor_restore(nor); in spi_nor_remove()
3663 return mtd_device_unregister(&nor->mtd); in spi_nor_remove()
3668 struct spi_nor *nor = spi_mem_get_drvdata(spimem); in spi_nor_shutdown() local
3670 spi_nor_restore(nor); in spi_nor_shutdown()
3679 * encourage new users to add support to the spi-nor library, and simply bind
3680 * against a generic string here (e.g., "jedec,spi-nor").
3687 * Allow non-DT platform devices to bind to the "spi-nor" modalias, and
3691 {"spi-nor"},
3695 * them with "spi-nor" in platform data.
3700 * Entries that were used in DTs without "jedec,spi-nor" fallback and
3732 * Generic compatibility for SPI NOR that can be identified by the
3735 { .compatible = "jedec,spi-nor" },
3748 .name = "spi-nor",
3775 MODULE_DESCRIPTION("framework for SPI NOR");