onenand.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/include/linux/mtd/onenand.h
  4. *
  5. * Copyright © 2005-2009 Samsung Electronics
  6. * Kyungmin Park <[email protected]>
  7. */
  8. #ifndef __LINUX_MTD_ONENAND_H
  9. #define __LINUX_MTD_ONENAND_H
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/mtd/flashchip.h>
  13. #include <linux/mtd/onenand_regs.h>
  14. #include <linux/mtd/bbm.h>
  15. #define MAX_DIES 2
  16. #define MAX_BUFFERRAM 2
  17. /* Scan and identify a OneNAND device */
  18. extern int onenand_scan(struct mtd_info *mtd, int max_chips);
  19. /* Free resources held by the OneNAND device */
  20. extern void onenand_release(struct mtd_info *mtd);
  21. /**
  22. * struct onenand_bufferram - OneNAND BufferRAM Data
  23. * @blockpage: block & page address in BufferRAM
  24. */
  25. struct onenand_bufferram {
  26. int blockpage;
  27. };
  28. /**
  29. * struct onenand_chip - OneNAND Private Flash Chip Data
  30. * @base: [BOARDSPECIFIC] address to access OneNAND
  31. * @dies: [INTERN][FLEX-ONENAND] number of dies on chip
  32. * @boundary: [INTERN][FLEX-ONENAND] Boundary of the dies
  33. * @diesize: [INTERN][FLEX-ONENAND] Size of the dies
  34. * @chipsize: [INTERN] the size of one chip for multichip arrays
  35. * FIXME For Flex-OneNAND, chipsize holds maximum possible
  36. * device size ie when all blocks are considered MLC
  37. * @device_id: [INTERN] device ID
  38. * @density_mask: chip density, used for DDP devices
  39. * @verstion_id: [INTERN] version ID
  40. * @options: [BOARDSPECIFIC] various chip options. They can
  41. * partly be set to inform onenand_scan about
  42. * @erase_shift: [INTERN] number of address bits in a block
  43. * @page_shift: [INTERN] number of address bits in a page
  44. * @page_mask: [INTERN] a page per block mask
  45. * @writesize: [INTERN] a real page size
  46. * @bufferram_index: [INTERN] BufferRAM index
  47. * @bufferram: [INTERN] BufferRAM info
  48. * @readw: [REPLACEABLE] hardware specific function for read short
  49. * @writew: [REPLACEABLE] hardware specific function for write short
  50. * @command: [REPLACEABLE] hardware specific function for writing
  51. * commands to the chip
  52. * @wait: [REPLACEABLE] hardware specific function for wait on ready
  53. * @bbt_wait: [REPLACEABLE] hardware specific function for bbt wait on ready
  54. * @unlock_all: [REPLACEABLE] hardware specific function for unlock all
  55. * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
  56. * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
  57. * @read_word: [REPLACEABLE] hardware specific function for read
  58. * register of OneNAND
  59. * @write_word: [REPLACEABLE] hardware specific function for write
  60. * register of OneNAND
  61. * @mmcontrol: sync burst read function
  62. * @chip_probe: [REPLACEABLE] hardware specific function for chip probe
  63. * @block_markbad: function to mark a block as bad
  64. * @scan_bbt: [REPLACEALBE] hardware specific function for scanning
  65. * Bad block Table
  66. * @chip_lock: [INTERN] spinlock used to protect access to this
  67. * structure and the chip
  68. * @wq: [INTERN] wait queue to sleep on if a OneNAND
  69. * operation is in progress
  70. * @state: [INTERN] the current state of the OneNAND device
  71. * @page_buf: [INTERN] page main data buffer
  72. * @oob_buf: [INTERN] page oob data buffer
  73. * @subpagesize: [INTERN] holds the subpagesize
  74. * @bbm: [REPLACEABLE] pointer to Bad Block Management
  75. * @priv: [OPTIONAL] pointer to private chip date
  76. */
  77. struct onenand_chip {
  78. void __iomem *base;
  79. unsigned dies;
  80. unsigned boundary[MAX_DIES];
  81. loff_t diesize[MAX_DIES];
  82. unsigned int chipsize;
  83. unsigned int device_id;
  84. unsigned int version_id;
  85. unsigned int technology;
  86. unsigned int density_mask;
  87. unsigned int options;
  88. unsigned int badblockpos;
  89. unsigned int erase_shift;
  90. unsigned int page_shift;
  91. unsigned int page_mask;
  92. unsigned int writesize;
  93. unsigned int bufferram_index;
  94. struct onenand_bufferram bufferram[MAX_BUFFERRAM];
  95. int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
  96. int (*wait)(struct mtd_info *mtd, int state);
  97. int (*bbt_wait)(struct mtd_info *mtd, int state);
  98. void (*unlock_all)(struct mtd_info *mtd);
  99. int (*read_bufferram)(struct mtd_info *mtd, int area,
  100. unsigned char *buffer, int offset, size_t count);
  101. int (*write_bufferram)(struct mtd_info *mtd, int area,
  102. const unsigned char *buffer, int offset, size_t count);
  103. unsigned short (*read_word)(void __iomem *addr);
  104. void (*write_word)(unsigned short value, void __iomem *addr);
  105. void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
  106. int (*chip_probe)(struct mtd_info *mtd);
  107. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  108. int (*scan_bbt)(struct mtd_info *mtd);
  109. int (*enable)(struct mtd_info *mtd);
  110. int (*disable)(struct mtd_info *mtd);
  111. struct completion complete;
  112. int irq;
  113. spinlock_t chip_lock;
  114. wait_queue_head_t wq;
  115. flstate_t state;
  116. unsigned char *page_buf;
  117. unsigned char *oob_buf;
  118. #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
  119. unsigned char *verify_buf;
  120. #endif
  121. int subpagesize;
  122. void *bbm;
  123. void *priv;
  124. /*
  125. * Shows that the current operation is composed
  126. * of sequence of commands. For example, cache program.
  127. * Such command status OnGo bit is checked at the end of
  128. * sequence.
  129. */
  130. unsigned int ongoing;
  131. };
  132. /*
  133. * Helper macros
  134. */
  135. #define ONENAND_PAGES_PER_BLOCK (1<<6)
  136. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  137. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  138. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  139. #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
  140. #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
  141. #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
  142. #define FLEXONENAND(this) \
  143. (this->device_id & DEVICE_IS_FLEXONENAND)
  144. #define ONENAND_GET_SYS_CFG1(this) \
  145. (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
  146. #define ONENAND_SET_SYS_CFG1(v, this) \
  147. (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
  148. #define ONENAND_IS_DDP(this) \
  149. (this->device_id & ONENAND_DEVICE_IS_DDP)
  150. #define ONENAND_IS_MLC(this) \
  151. (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
  152. #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
  153. #define ONENAND_IS_2PLANE(this) \
  154. (this->options & ONENAND_HAS_2PLANE)
  155. #else
  156. #define ONENAND_IS_2PLANE(this) (0)
  157. #endif
  158. #define ONENAND_IS_CACHE_PROGRAM(this) \
  159. (this->options & ONENAND_HAS_CACHE_PROGRAM)
  160. #define ONENAND_IS_NOP_1(this) \
  161. (this->options & ONENAND_HAS_NOP_1)
  162. /* Check byte access in OneNAND */
  163. #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
  164. #define ONENAND_BADBLOCK_POS 0
  165. /*
  166. * Options bits
  167. */
  168. #define ONENAND_HAS_CONT_LOCK (0x0001)
  169. #define ONENAND_HAS_UNLOCK_ALL (0x0002)
  170. #define ONENAND_HAS_2PLANE (0x0004)
  171. #define ONENAND_HAS_4KB_PAGE (0x0008)
  172. #define ONENAND_HAS_CACHE_PROGRAM (0x0010)
  173. #define ONENAND_HAS_NOP_1 (0x0020)
  174. #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
  175. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  176. #define ONENAND_OOBBUF_ALLOC (0x2000)
  177. #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000)
  178. #define ONENAND_IS_4KB_PAGE(this) \
  179. (this->options & ONENAND_HAS_4KB_PAGE)
  180. /*
  181. * OneNAND Flash Manufacturer ID Codes
  182. */
  183. #define ONENAND_MFR_SAMSUNG 0xec
  184. #define ONENAND_MFR_NUMONYX 0x20
  185. /**
  186. * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
  187. * @name: Manufacturer name
  188. * @id: manufacturer ID code of device.
  189. */
  190. struct onenand_manufacturers {
  191. int id;
  192. char *name;
  193. };
  194. int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
  195. struct mtd_oob_ops *ops);
  196. unsigned onenand_block(struct onenand_chip *this, loff_t addr);
  197. loff_t onenand_addr(struct onenand_chip *this, int block);
  198. int flexonenand_region(struct mtd_info *mtd, loff_t addr);
  199. struct mtd_partition;
  200. struct onenand_platform_data {
  201. void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
  202. int (*read_bufferram)(struct mtd_info *mtd, int area,
  203. unsigned char *buffer, int offset, size_t count);
  204. struct mtd_partition *parts;
  205. unsigned int nr_parts;
  206. };
  207. #endif /* __LINUX_MTD_ONENAND_H */