mtd_nand.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-12-05 Bernard the first version
  9. * 2011-04-02 prife add mark_badblock and check_block
  10. */
  11. /*
  12. * COPYRIGHT (C) 2012, Shanghai Real Thread
  13. */
  14. #ifndef __MTD_NAND_H__
  15. #define __MTD_NAND_H__
  16. #include <rtthread.h>
  17. struct rt_mtd_nand_driver_ops;
  18. #define RT_MTD_NAND_DEVICE(device) ((struct rt_mtd_nand_device*)(device))
  19. #define RT_MTD_EOK 0 /* NO error */
  20. #define RT_MTD_EECC 101 /* ECC error */
  21. #define RT_MTD_EBUSY 102 /* hardware busy */
  22. #define RT_MTD_EIO 103 /* generic IO issue */
  23. #define RT_MTD_ENOMEM 104 /* out of memory */
  24. #define RT_MTD_ESRC 105 /* source issue */
  25. #define RT_MTD_EECC_CORRECT 106 /* ECC error but correct */
  26. struct rt_mtd_nand_device
  27. {
  28. struct rt_device parent;
  29. rt_uint16_t page_size; /* The Page size in the flash */
  30. rt_uint16_t oob_size; /* Out of bank size */
  31. rt_uint16_t oob_free; /* the free area in oob that flash driver not use */
  32. rt_uint16_t plane_num; /* the number of plane in the NAND Flash */
  33. rt_uint32_t pages_per_block; /* The number of page a block */
  34. rt_uint16_t block_total;
  35. /* Only be touched by driver */
  36. rt_uint32_t block_start; /* The start of available block*/
  37. rt_uint32_t block_end; /* The end of available block */
  38. /* operations interface */
  39. const struct rt_mtd_nand_driver_ops *ops;
  40. void *priv;
  41. };
  42. typedef struct rt_mtd_nand_device* rt_mtd_nand_t;
  43. struct rt_mtd_nand_driver_ops
  44. {
  45. rt_err_t (*read_id)(struct rt_mtd_nand_device *device);
  46. rt_err_t (*read_page)(struct rt_mtd_nand_device *device,
  47. rt_off_t page,
  48. rt_uint8_t *data, rt_uint32_t data_len,
  49. rt_uint8_t *spare, rt_uint32_t spare_len);
  50. rt_err_t (*write_page)(struct rt_mtd_nand_device *device,
  51. rt_off_t page,
  52. const rt_uint8_t *data, rt_uint32_t data_len,
  53. const rt_uint8_t *spare, rt_uint32_t spare_len);
  54. rt_err_t (*move_page)(struct rt_mtd_nand_device *device, rt_off_t src_page, rt_off_t dst_page);
  55. rt_err_t (*erase_block)(struct rt_mtd_nand_device *device, rt_uint32_t block);
  56. rt_err_t (*check_block)(struct rt_mtd_nand_device *device, rt_uint32_t block);
  57. rt_err_t (*mark_badblock)(struct rt_mtd_nand_device *device, rt_uint32_t block);
  58. };
  59. rt_err_t rt_mtd_nand_register_device(const char *name, struct rt_mtd_nand_device *device);
  60. rt_uint32_t rt_mtd_nand_read_id(struct rt_mtd_nand_device *device);
  61. rt_err_t rt_mtd_nand_read(
  62. struct rt_mtd_nand_device *device,
  63. rt_off_t page,
  64. rt_uint8_t *data, rt_uint32_t data_len,
  65. rt_uint8_t *spare, rt_uint32_t spare_len);
  66. rt_err_t rt_mtd_nand_write(
  67. struct rt_mtd_nand_device *device,
  68. rt_off_t page,
  69. const rt_uint8_t *data, rt_uint32_t data_len,
  70. const rt_uint8_t *spare, rt_uint32_t spare_len);
  71. rt_err_t rt_mtd_nand_move_page(struct rt_mtd_nand_device *device,
  72. rt_off_t src_page, rt_off_t dst_page);
  73. rt_err_t rt_mtd_nand_erase_block(struct rt_mtd_nand_device *device, rt_uint32_t block);
  74. rt_err_t rt_mtd_nand_check_block(struct rt_mtd_nand_device *device, rt_uint32_t block);
  75. rt_err_t rt_mtd_nand_mark_badblock(struct rt_mtd_nand_device *device, rt_uint32_t block);
  76. #endif /* MTD_NAND_H_ */