onenand.h 8.0 KB

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