internals.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2018 - Bootlin
  4. *
  5. * Author: Boris Brezillon <[email protected]>
  6. *
  7. * Header containing internal definitions to be used only by core files.
  8. * NAND controller drivers should not include this file.
  9. */
  10. #ifndef __LINUX_RAWNAND_INTERNALS
  11. #define __LINUX_RAWNAND_INTERNALS
  12. #include <linux/mtd/rawnand.h>
  13. /*
  14. * NAND Flash Manufacturer ID Codes
  15. */
  16. #define NAND_MFR_AMD 0x01
  17. #define NAND_MFR_ATO 0x9b
  18. #define NAND_MFR_EON 0x92
  19. #define NAND_MFR_ESMT 0xc8
  20. #define NAND_MFR_FUJITSU 0x04
  21. #define NAND_MFR_HYNIX 0xad
  22. #define NAND_MFR_INTEL 0x89
  23. #define NAND_MFR_MACRONIX 0xc2
  24. #define NAND_MFR_MICRON 0x2c
  25. #define NAND_MFR_NATIONAL 0x8f
  26. #define NAND_MFR_RENESAS 0x07
  27. #define NAND_MFR_SAMSUNG 0xec
  28. #define NAND_MFR_SANDISK 0x45
  29. #define NAND_MFR_STMICRO 0x20
  30. /* Kioxia is new name of Toshiba memory. */
  31. #define NAND_MFR_TOSHIBA 0x98
  32. #define NAND_MFR_WINBOND 0xef
  33. /**
  34. * struct nand_manufacturer_ops - NAND Manufacturer operations
  35. * @detect: detect the NAND memory organization and capabilities
  36. * @init: initialize all vendor specific fields (like the ->read_retry()
  37. * implementation) if any.
  38. * @cleanup: the ->init() function may have allocated resources, ->cleanup()
  39. * is here to let vendor specific code release those resources.
  40. * @fixup_onfi_param_page: apply vendor specific fixups to the ONFI parameter
  41. * page. This is called after the checksum is verified.
  42. */
  43. struct nand_manufacturer_ops {
  44. void (*detect)(struct nand_chip *chip);
  45. int (*init)(struct nand_chip *chip);
  46. void (*cleanup)(struct nand_chip *chip);
  47. void (*fixup_onfi_param_page)(struct nand_chip *chip,
  48. struct nand_onfi_params *p);
  49. };
  50. /**
  51. * struct nand_manufacturer_desc - NAND Flash Manufacturer descriptor
  52. * @name: Manufacturer name
  53. * @id: manufacturer ID code of device.
  54. * @ops: manufacturer operations
  55. */
  56. struct nand_manufacturer_desc {
  57. int id;
  58. char *name;
  59. const struct nand_manufacturer_ops *ops;
  60. };
  61. extern struct nand_flash_dev nand_flash_ids[];
  62. extern const struct nand_manufacturer_ops amd_nand_manuf_ops;
  63. extern const struct nand_manufacturer_ops esmt_nand_manuf_ops;
  64. extern const struct nand_manufacturer_ops hynix_nand_manuf_ops;
  65. extern const struct nand_manufacturer_ops macronix_nand_manuf_ops;
  66. extern const struct nand_manufacturer_ops micron_nand_manuf_ops;
  67. extern const struct nand_manufacturer_ops samsung_nand_manuf_ops;
  68. extern const struct nand_manufacturer_ops toshiba_nand_manuf_ops;
  69. /* MLC pairing schemes */
  70. extern const struct mtd_pairing_scheme dist3_pairing_scheme;
  71. /* Core functions */
  72. const struct nand_manufacturer_desc *nand_get_manufacturer_desc(u8 id);
  73. int nand_bbm_get_next_page(struct nand_chip *chip, int page);
  74. int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs);
  75. int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr,
  76. int allowbbt);
  77. void onfi_fill_interface_config(struct nand_chip *chip,
  78. struct nand_interface_config *iface,
  79. enum nand_interface_type type,
  80. unsigned int timing_mode);
  81. unsigned int
  82. onfi_find_closest_sdr_mode(const struct nand_sdr_timings *spec_timings);
  83. unsigned int
  84. onfi_find_closest_nvddr_mode(const struct nand_nvddr_timings *spec_timings);
  85. int nand_choose_best_sdr_timings(struct nand_chip *chip,
  86. struct nand_interface_config *iface,
  87. struct nand_sdr_timings *spec_timings);
  88. int nand_choose_best_nvddr_timings(struct nand_chip *chip,
  89. struct nand_interface_config *iface,
  90. struct nand_nvddr_timings *spec_timings);
  91. const struct nand_interface_config *nand_get_reset_interface_config(void);
  92. int nand_get_features(struct nand_chip *chip, int addr, u8 *subfeature_param);
  93. int nand_set_features(struct nand_chip *chip, int addr, u8 *subfeature_param);
  94. int nand_read_page_raw_notsupp(struct nand_chip *chip, u8 *buf,
  95. int oob_required, int page);
  96. int nand_write_page_raw_notsupp(struct nand_chip *chip, const u8 *buf,
  97. int oob_required, int page);
  98. int nand_exit_status_op(struct nand_chip *chip);
  99. int nand_read_param_page_op(struct nand_chip *chip, u8 page, void *buf,
  100. unsigned int len);
  101. void nand_decode_ext_id(struct nand_chip *chip);
  102. void panic_nand_wait(struct nand_chip *chip, unsigned long timeo);
  103. void sanitize_string(uint8_t *s, size_t len);
  104. static inline bool nand_has_exec_op(struct nand_chip *chip)
  105. {
  106. if (!chip->controller || !chip->controller->ops ||
  107. !chip->controller->ops->exec_op)
  108. return false;
  109. return true;
  110. }
  111. static inline int nand_check_op(struct nand_chip *chip,
  112. const struct nand_operation *op)
  113. {
  114. if (!nand_has_exec_op(chip))
  115. return 0;
  116. return chip->controller->ops->exec_op(chip, op, true);
  117. }
  118. static inline int nand_exec_op(struct nand_chip *chip,
  119. const struct nand_operation *op)
  120. {
  121. if (!nand_has_exec_op(chip))
  122. return -ENOTSUPP;
  123. if (WARN_ON(op->cs >= nanddev_ntargets(&chip->base)))
  124. return -EINVAL;
  125. return chip->controller->ops->exec_op(chip, op, false);
  126. }
  127. static inline bool nand_controller_can_setup_interface(struct nand_chip *chip)
  128. {
  129. if (!chip->controller || !chip->controller->ops ||
  130. !chip->controller->ops->setup_interface)
  131. return false;
  132. if (chip->options & NAND_KEEP_TIMINGS)
  133. return false;
  134. return true;
  135. }
  136. /* BBT functions */
  137. int nand_markbad_bbt(struct nand_chip *chip, loff_t offs);
  138. int nand_isreserved_bbt(struct nand_chip *chip, loff_t offs);
  139. int nand_isbad_bbt(struct nand_chip *chip, loff_t offs, int allowbbt);
  140. /* Legacy */
  141. void nand_legacy_set_defaults(struct nand_chip *chip);
  142. void nand_legacy_adjust_cmdfunc(struct nand_chip *chip);
  143. int nand_legacy_check_hooks(struct nand_chip *chip);
  144. /* ONFI functions */
  145. u16 onfi_crc16(u16 crc, u8 const *p, size_t len);
  146. int nand_onfi_detect(struct nand_chip *chip);
  147. /* JEDEC functions */
  148. int nand_jedec_detect(struct nand_chip *chip);
  149. #endif /* __LINUX_RAWNAND_INTERNALS */