nand.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2019-2022, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DRIVERS_NAND_H
  7. #define DRIVERS_NAND_H
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. #include <lib/utils_def.h>
  11. #define PSEC_TO_MSEC(x) div_round_up((x), 1000000000ULL)
  12. struct ecc {
  13. unsigned int mode; /* ECC mode NAND_ECC_MODE_{NONE|HW|ONDIE} */
  14. unsigned int size; /* Data byte per ECC step */
  15. unsigned int bytes; /* ECC bytes per step */
  16. unsigned int max_bit_corr; /* Max correctible bits per ECC steps */
  17. };
  18. struct nand_device {
  19. unsigned int block_size;
  20. unsigned int page_size;
  21. unsigned long long size;
  22. unsigned int nb_planes;
  23. unsigned int buswidth;
  24. struct ecc ecc;
  25. int (*mtd_block_is_bad)(unsigned int block);
  26. int (*mtd_read_page)(struct nand_device *nand, unsigned int page,
  27. uintptr_t buffer);
  28. };
  29. void plat_get_scratch_buffer(void **buffer_addr, size_t *buf_size);
  30. /*
  31. * Read bytes from NAND device
  32. *
  33. * @offset: Byte offset to read from in device
  34. * @buffer: [out] Bytes read from device
  35. * @length: Number of bytes to read
  36. * @length_read: [out] Number of bytes read from device
  37. * Return: 0 on success, a negative errno on failure
  38. */
  39. int nand_read(unsigned int offset, uintptr_t buffer, size_t length,
  40. size_t *length_read);
  41. /*
  42. * Look for an extra offset to be added in case of bad blocks
  43. *
  44. * @base: Base address of the area
  45. * @offset: Byte offset to read from in device
  46. * @extra_offset: [out] Extra offset to be added if bad blocks are found
  47. * Return: 0 on success, a negative errno on failure
  48. */
  49. int nand_seek_bb(uintptr_t base, unsigned int offset, size_t *extra_offset);
  50. /*
  51. * Get NAND device instance
  52. *
  53. * Return: NAND device instance reference
  54. */
  55. struct nand_device *get_nand_device(void);
  56. #endif /* DRIVERS_NAND_H */