You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

208 lines
7.1 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2007 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * partially based on *
  6. * linux/include/linux/mtd/nand.h *
  7. * *
  8. * Copyright (c) 2000 David Woodhouse <dwmw2@mvhi.com> *
  9. * Steven J. Hill <sjhill@realitydiluted.com> *
  10. * Thomas Gleixner <tglx@linutronix.de> *
  11. * *
  12. * This program is free software; you can redistribute it and/or modify *
  13. * it under the terms of the GNU General Public License as published by *
  14. * the Free Software Foundation; either version 2 of the License, or *
  15. * (at your option) any later version. *
  16. * *
  17. * This program is distributed in the hope that it will be useful, *
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  20. * GNU General Public License for more details. *
  21. * *
  22. * You should have received a copy of the GNU General Public License *
  23. * along with this program; if not, write to the *
  24. * Free Software Foundation, Inc., *
  25. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  26. ***************************************************************************/
  27. #ifndef NAND_H
  28. #define NAND_H
  29. #include "flash.h"
  30. struct nand_device_s;
  31. typedef struct nand_flash_controller_s
  32. {
  33. char *name;
  34. int (*nand_device_command)(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct nand_device_s *device);
  35. int (*register_commands)(struct command_context_s *cmd_ctx);
  36. int (*init)(struct nand_device_s *device);
  37. int (*reset)(struct nand_device_s *device);
  38. int (*command)(struct nand_device_s *device, u8 command);
  39. int (*address)(struct nand_device_s *device, u8 address);
  40. int (*write_data)(struct nand_device_s *device, u16 data);
  41. int (*read_data)(struct nand_device_s *device, void *data);
  42. int (*write_page)(struct nand_device_s *device, u32 page, u8 *data, u32 data_size, u8 *oob, u32 oob_size);
  43. int (*read_page)(struct nand_device_s *device, u32 page, u8 *data, u32 data_size, u8 *oob, u32 oob_size);
  44. int (*controller_ready)(struct nand_device_s *device, int timeout);
  45. int (*nand_ready)(struct nand_device_s *device, int timeout);
  46. } nand_flash_controller_t;
  47. typedef struct nand_block_s
  48. {
  49. u32 offset;
  50. u32 size;
  51. int is_erased;
  52. int is_bad;
  53. } nand_block_t;
  54. typedef struct nand_device_s
  55. {
  56. nand_flash_controller_t *controller;
  57. void *controller_priv;
  58. struct nand_manufacturer_s *manufacturer;
  59. struct nand_info_s *device;
  60. int bus_width;
  61. int address_cycles;
  62. int page_size;
  63. int erase_size;
  64. int use_raw;
  65. int num_blocks;
  66. nand_block_t *blocks;
  67. struct nand_device_s *next;
  68. } nand_device_t;
  69. /* NAND Flash Manufacturer ID Codes
  70. */
  71. enum
  72. {
  73. NAND_MFR_TOSHIBA = 0x98,
  74. NAND_MFR_SAMSUNG = 0xec,
  75. NAND_MFR_FUJITSU = 0x04,
  76. NAND_MFR_NATIONAL = 0x8f,
  77. NAND_MFR_RENESAS = 0x07,
  78. NAND_MFR_STMICRO = 0x20,
  79. NAND_MFR_HYNIX = 0xad,
  80. };
  81. typedef struct nand_manufacturer_s
  82. {
  83. int id;
  84. char *name;
  85. } nand_manufacturer_t;
  86. typedef struct nand_info_s
  87. {
  88. char *name;
  89. int id;
  90. int page_size;
  91. int chip_size;
  92. int erase_size;
  93. int options;
  94. } nand_info_t;
  95. /* Option constants for bizarre disfunctionality and real features
  96. */
  97. enum {
  98. /* Chip can not auto increment pages */
  99. NAND_NO_AUTOINCR = 0x00000001,
  100. /* Buswitdh is 16 bit */
  101. NAND_BUSWIDTH_16 = 0x00000002,
  102. /* Device supports partial programming without padding */
  103. NAND_NO_PADDING = 0x00000004,
  104. /* Chip has cache program function */
  105. NAND_CACHEPRG = 0x00000008,
  106. /* Chip has copy back function */
  107. NAND_COPYBACK = 0x00000010,
  108. /* AND Chip which has 4 banks and a confusing page / block
  109. * assignment. See Renesas datasheet for further information */
  110. NAND_IS_AND = 0x00000020,
  111. /* Chip has a array of 4 pages which can be read without
  112. * additional ready /busy waits */
  113. NAND_4PAGE_ARRAY = 0x00000040,
  114. /* Chip requires that BBT is periodically rewritten to prevent
  115. * bits from adjacent blocks from 'leaking' in altering data.
  116. * This happens with the Renesas AG-AND chips, possibly others. */
  117. BBT_AUTO_REFRESH = 0x00000080,
  118. /* Chip does not require ready check on read. True
  119. * for all large page devices, as they do not support
  120. * autoincrement.*/
  121. NAND_NO_READRDY = 0x00000100,
  122. /* Options valid for Samsung large page devices */
  123. NAND_SAMSUNG_LP_OPTIONS = (NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK),
  124. /* Options for new chips with large page size. The pagesize and the
  125. * erasesize is determined from the extended id bytes
  126. */
  127. LP_OPTIONS = (NAND_SAMSUNG_LP_OPTIONS | NAND_NO_READRDY | NAND_NO_AUTOINCR),
  128. LP_OPTIONS16 = (LP_OPTIONS | NAND_BUSWIDTH_16),
  129. };
  130. enum
  131. {
  132. /* Standard NAND flash commands */
  133. NAND_CMD_READ0 = 0x0,
  134. NAND_CMD_READ1 = 0x1,
  135. NAND_CMD_RNDOUT = 0x5,
  136. NAND_CMD_PAGEPROG = 0x10,
  137. NAND_CMD_READOOB = 0x50,
  138. NAND_CMD_ERASE1 = 0x60,
  139. NAND_CMD_STATUS = 0x70,
  140. NAND_CMD_STATUS_MULTI = 0x71,
  141. NAND_CMD_SEQIN = 0x80,
  142. NAND_CMD_RNDIN = 0x85,
  143. NAND_CMD_READID = 0x90,
  144. NAND_CMD_ERASE2 = 0xd0,
  145. NAND_CMD_RESET = 0xff,
  146. /* Extended commands for large page devices */
  147. NAND_CMD_READSTART = 0x30,
  148. NAND_CMD_RNDOUTSTART = 0xE0,
  149. NAND_CMD_CACHEDPROG = 0x15,
  150. };
  151. /* Status bits */
  152. enum
  153. {
  154. NAND_STATUS_FAIL = 0x01,
  155. NAND_STATUS_FAIL_N1 = 0x02,
  156. NAND_STATUS_TRUE_READY = 0x20,
  157. NAND_STATUS_READY = 0x40,
  158. NAND_STATUS_WP = 0x80,
  159. };
  160. /* OOB (spare) data formats */
  161. enum oob_formats
  162. {
  163. NAND_OOB_NONE = 0x0, /* no OOB data at all */
  164. NAND_OOB_RAW = 0x1, /* raw OOB data (16 bytes for 512b page sizes, 64 bytes for 2048b page sizes) */
  165. NAND_OOB_ONLY = 0x2, /* only OOB data */
  166. NAND_OOB_SW_ECC = 0x10, /* when writing, use SW ECC (as opposed to no ECC) */
  167. NAND_OOB_HW_ECC = 0x20, /* when writing, use HW ECC (as opposed to no ECC) */
  168. NAND_OOB_JFFS2 = 0x100, /* when writing, use JFFS2 OOB layout */
  169. NAND_OOB_YAFFS2 = 0x100,/* when writing, use YAFFS2 OOB layout */
  170. };
  171. /* Function prototypes */
  172. extern nand_device_t *get_nand_device_by_num(int num);
  173. extern int nand_read_page_raw(struct nand_device_s *device, u32 page, u8 *data, u32 data_size, u8 *oob, u32 oob_size);
  174. extern int nand_write_page_raw(struct nand_device_s *device, u32 page, u8 *data, u32 data_size, u8 *oob, u32 oob_size);
  175. #define ERROR_NAND_DEVICE_INVALID (-1100)
  176. #define ERROR_NAND_OPERATION_FAILED (-1101)
  177. #define ERROR_NAND_OPERATION_TIMEOUT (-1102)
  178. #define ERROR_NAND_OPERATION_NOT_SUPPORTED (-1103)
  179. #define ERROR_NAND_DEVICE_NOT_PROBED (-1104)
  180. #define ERROR_NAND_ERROR_CORRECTION_FAILED (-1105)
  181. #endif /* NAND_H */