nand.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * (C) Copyright 2005
  4. * 2N Telekomunikace, a.s. <www.2n.cz>
  5. * Ladislav Michl <michl@2n.cz>
  6. */
  7. #ifndef _NAND_H_
  8. #define _NAND_H_
  9. #include <config.h>
  10. extern void nand_init(void);
  11. unsigned long nand_size(void);
  12. #include <linux/compat.h>
  13. #include <linux/mtd/mtd.h>
  14. int nand_mtd_to_devnum(struct mtd_info *mtd);
  15. #if CONFIG_IS_ENABLED(SYS_NAND_SELF_INIT)
  16. void board_nand_init(void);
  17. int nand_register(int devnum, struct mtd_info *mtd);
  18. #else
  19. struct nand_chip;
  20. extern int board_nand_init(struct nand_chip *nand);
  21. #endif
  22. extern int nand_curr_device;
  23. static inline int nand_read(struct mtd_info *info, loff_t ofs, size_t *len,
  24. u_char *buf)
  25. {
  26. return mtd_read(info, ofs, *len, (size_t *)len, buf);
  27. }
  28. static inline int nand_write(struct mtd_info *info, loff_t ofs, size_t *len,
  29. u_char *buf)
  30. {
  31. return mtd_write(info, ofs, *len, (size_t *)len, buf);
  32. }
  33. static inline int nand_block_isbad(struct mtd_info *info, loff_t ofs)
  34. {
  35. return mtd_block_isbad(info, ofs);
  36. }
  37. static inline int nand_erase(struct mtd_info *info, loff_t off, size_t size)
  38. {
  39. struct erase_info instr;
  40. instr.mtd = info;
  41. instr.addr = off;
  42. instr.len = size;
  43. return mtd_erase(info, &instr);
  44. }
  45. /*****************************************************************************
  46. * declarations from nand_util.c
  47. ****************************************************************************/
  48. typedef struct mtd_oob_ops mtd_oob_ops_t;
  49. struct nand_erase_options {
  50. loff_t length; /* number of bytes to erase */
  51. loff_t offset; /* first address in NAND to erase */
  52. int quiet; /* don't display progress messages */
  53. int jffs2; /* if true: format for jffs2 usage
  54. * (write appropriate cleanmarker blocks) */
  55. int scrub; /* if true, really clean NAND by erasing
  56. * bad blocks (UNSAFE) */
  57. /* Don't include skipped bad blocks in size to be erased */
  58. int spread;
  59. /* maximum size that actual may be in order to not exceed the buf */
  60. loff_t lim;
  61. };
  62. typedef struct nand_erase_options nand_erase_options_t;
  63. int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
  64. size_t *actual, loff_t lim, u_char *buffer);
  65. #define WITH_DROP_FFS (1 << 0) /* drop trailing all-0xff pages */
  66. #define WITH_WR_VERIFY (1 << 1) /* verify data was written correctly */
  67. int nand_write_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
  68. size_t *actual, loff_t lim, u_char *buffer, int flags);
  69. int nand_erase_opts(struct mtd_info *mtd,
  70. const nand_erase_options_t *opts);
  71. int nand_torture(struct mtd_info *mtd, loff_t offset);
  72. int nand_verify_page_oob(struct mtd_info *mtd, struct mtd_oob_ops *ops,
  73. loff_t ofs);
  74. int nand_verify(struct mtd_info *mtd, loff_t ofs, size_t len, u_char *buf);
  75. #define NAND_LOCK_STATUS_TIGHT 0x01
  76. #define NAND_LOCK_STATUS_UNLOCK 0x04
  77. int nand_lock(struct mtd_info *mtd, int tight);
  78. int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,
  79. int allexcept);
  80. int nand_get_lock_status(struct mtd_info *mtd, loff_t offset);
  81. u32 nand_spl_adjust_offset(u32 sector, u32 offs);
  82. int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
  83. int nand_spl_read_block(int block, int offset, int len, void *dst);
  84. void nand_deselect(void);
  85. #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
  86. void board_nand_select_device(struct nand_chip *nand, int chip);
  87. #endif
  88. __attribute__((noreturn)) void nand_boot(void);
  89. #ifdef CONFIG_ENV_OFFSET_OOB
  90. #define ENV_OOB_MARKER 0x30425645 /*"EVB0" in little-endian -- offset is stored
  91. as block number*/
  92. #define ENV_OOB_MARKER_OLD 0x30564e45 /*"ENV0" in little-endian -- offset is
  93. stored as byte number */
  94. #define ENV_OFFSET_SIZE 8
  95. int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result);
  96. #endif
  97. int spl_nand_erase_one(int block, int page);
  98. /* platform specific init functions */
  99. void sunxi_nand_init(void);
  100. /*
  101. * get_nand_dev_by_index - Get the nand info based in index.
  102. *
  103. * @dev - index to the nand device.
  104. *
  105. * returns pointer to the nand device info structure or NULL on failure.
  106. */
  107. struct mtd_info *get_nand_dev_by_index(int dev);
  108. #endif /* _NAND_H_ */