raw_nand.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2019-2020, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef DRIVERS_RAW_NAND_H
  7. #define DRIVERS_RAW_NAND_H
  8. #include <cdefs.h>
  9. #include <stdint.h>
  10. #include <drivers/nand.h>
  11. /* NAND ONFI default value mode 0 in picosecond */
  12. #define NAND_TADL_MIN 400000UL
  13. #define NAND_TALH_MIN 20000UL
  14. #define NAND_TALS_MIN 50000UL
  15. #define NAND_TAR_MIN 25000UL
  16. #define NAND_TCCS_MIN 500000UL
  17. #define NAND_TCEA_MIN 100000UL
  18. #define NAND_TCEH_MIN 20000UL
  19. #define NAND_TCH_MIN 20000UL
  20. #define NAND_TCHZ_MAX 100000UL
  21. #define NAND_TCLH_MIN 20000UL
  22. #define NAND_TCLR_MIN 20000UL
  23. #define NAND_TCLS_MIN 50000UL
  24. #define NAND_TCOH_MIN 0UL
  25. #define NAND_TCS_MIN 70000UL
  26. #define NAND_TDH_MIN 20000UL
  27. #define NAND_TDS_MIN 40000UL
  28. #define NAND_TFEAT_MAX 1000000UL
  29. #define NAND_TIR_MIN 10000UL
  30. #define NAND_TITC_MIN 1000000UL
  31. #define NAND_TR_MAX 200000000UL
  32. #define NAND_TRC_MIN 100000UL
  33. #define NAND_TREA_MAX 40000UL
  34. #define NAND_TREH_MIN 30000UL
  35. #define NAND_TRHOH_MIN 0UL
  36. #define NAND_TRHW_MIN 200000UL
  37. #define NAND_TRHZ_MAX 200000UL
  38. #define NAND_TRLOH_MIN 0UL
  39. #define NAND_TRP_MIN 50000UL
  40. #define NAND_TRR_MIN 40000UL
  41. #define NAND_TRST_MAX 250000000000ULL
  42. #define NAND_TWB_MAX 200000UL
  43. #define NAND_TWC_MIN 100000UL
  44. #define NAND_TWH_MIN 30000UL
  45. #define NAND_TWHR_MIN 120000UL
  46. #define NAND_TWP_MIN 50000UL
  47. #define NAND_TWW_MIN 100000UL
  48. /* NAND request types */
  49. #define NAND_REQ_CMD 0x0000U
  50. #define NAND_REQ_ADDR 0x1000U
  51. #define NAND_REQ_DATAIN 0x2000U
  52. #define NAND_REQ_DATAOUT 0x3000U
  53. #define NAND_REQ_WAIT 0x4000U
  54. #define NAND_REQ_MASK GENMASK(14, 12)
  55. #define NAND_REQ_BUS_WIDTH_8 BIT(15)
  56. #define PARAM_PAGE_SIZE 256
  57. /* NAND ONFI commands */
  58. #define NAND_CMD_READ_1ST 0x00U
  59. #define NAND_CMD_CHANGE_1ST 0x05U
  60. #define NAND_CMD_READID_SIG_ADDR 0x20U
  61. #define NAND_CMD_READ_2ND 0x30U
  62. #define NAND_CMD_STATUS 0x70U
  63. #define NAND_CMD_READID 0x90U
  64. #define NAND_CMD_CHANGE_2ND 0xE0U
  65. #define NAND_CMD_READ_PARAM_PAGE 0xECU
  66. #define NAND_CMD_RESET 0xFFU
  67. #define ONFI_REV_21 BIT(3)
  68. #define ONFI_FEAT_BUS_WIDTH_16 BIT(0)
  69. #define ONFI_FEAT_EXTENDED_PARAM BIT(7)
  70. /* NAND ECC type */
  71. #define NAND_ECC_NONE U(0)
  72. #define NAND_ECC_HW U(1)
  73. #define NAND_ECC_ONDIE U(2)
  74. /* NAND bus width */
  75. #define NAND_BUS_WIDTH_8 U(0)
  76. #define NAND_BUS_WIDTH_16 U(1)
  77. struct nand_req {
  78. struct nand_device *nand;
  79. uint16_t type;
  80. uint8_t *addr;
  81. unsigned int length;
  82. unsigned int delay_ms;
  83. unsigned int inst_delay;
  84. };
  85. struct nand_param_page {
  86. /* Rev information and feature block */
  87. uint32_t page_sig;
  88. uint16_t rev;
  89. uint16_t features;
  90. uint16_t opt_cmd;
  91. uint8_t jtg;
  92. uint8_t train_cmd;
  93. uint16_t ext_param_length;
  94. uint8_t nb_param_pages;
  95. uint8_t reserved1[17];
  96. /* Manufacturer information */
  97. uint8_t manufacturer[12];
  98. uint8_t model[20];
  99. uint8_t manufacturer_id;
  100. uint16_t data_code;
  101. uint8_t reserved2[13];
  102. /* Memory organization */
  103. uint32_t bytes_per_page;
  104. uint16_t spare_per_page;
  105. uint32_t bytes_per_partial;
  106. uint16_t spare_per_partial;
  107. uint32_t num_pages_per_blk;
  108. uint32_t num_blk_in_lun;
  109. uint8_t num_lun;
  110. uint8_t num_addr_cycles;
  111. uint8_t bit_per_cell;
  112. uint16_t max_bb_per_lun;
  113. uint16_t blk_endur;
  114. uint8_t valid_blk_begin;
  115. uint16_t blk_enbur_valid;
  116. uint8_t nb_prog_page;
  117. uint8_t partial_prog_attr;
  118. uint8_t nb_ecc_bits;
  119. uint8_t plane_addr;
  120. uint8_t mplanes_ops;
  121. uint8_t ez_nand;
  122. uint8_t reserved3[12];
  123. /* Electrical parameters */
  124. uint8_t io_pin_cap_max;
  125. uint16_t sdr_timing_mode;
  126. uint16_t sdr_prog_cache_timing;
  127. uint16_t tprog;
  128. uint16_t tbers;
  129. uint16_t tr;
  130. uint16_t tccs;
  131. uint8_t nvddr_timing_mode;
  132. uint8_t nvddr2_timing_mode;
  133. uint8_t nvddr_features;
  134. uint16_t clk_input_cap_typ;
  135. uint16_t io_pin_cap_typ;
  136. uint16_t input_pin_cap_typ;
  137. uint8_t input_pin_cap_max;
  138. uint8_t drv_strength_support;
  139. uint16_t tr_max;
  140. uint16_t tadl;
  141. uint16_t tr_typ;
  142. uint8_t reserved4[6];
  143. /* Vendor block */
  144. uint16_t vendor_revision;
  145. uint8_t vendor[88];
  146. uint16_t crc16;
  147. } __packed;
  148. struct nand_ctrl_ops {
  149. int (*exec)(struct nand_req *req);
  150. void (*setup)(struct nand_device *nand);
  151. };
  152. struct rawnand_device {
  153. struct nand_device *nand_dev;
  154. const struct nand_ctrl_ops *ops;
  155. };
  156. int nand_raw_init(unsigned long long *size, unsigned int *erase_size);
  157. int nand_wait_ready(unsigned int delay_ms);
  158. int nand_read_page_cmd(unsigned int page, unsigned int offset,
  159. uintptr_t buffer, unsigned int len);
  160. int nand_change_read_column_cmd(unsigned int offset, uintptr_t buffer,
  161. unsigned int len);
  162. void nand_raw_ctrl_init(const struct nand_ctrl_ops *ops);
  163. /*
  164. * Platform can implement this to override default raw NAND instance
  165. * configuration.
  166. *
  167. * @device: target raw NAND instance.
  168. * Return 0 on success, negative value otherwise.
  169. */
  170. int plat_get_raw_nand_data(struct rawnand_device *device);
  171. #endif /* DRIVERS_RAW_NAND_H */