onenand.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. * @bbm: [REPLACEABLE] pointer to Bad Block Management
  78. * @priv: [OPTIONAL] pointer to private chip date
  79. */
  80. struct onenand_chip {
  81. void __iomem *base;
  82. unsigned dies;
  83. unsigned boundary[MAX_DIES];
  84. loff_t diesize[MAX_DIES];
  85. unsigned int chipsize;
  86. unsigned int device_id;
  87. unsigned int version_id;
  88. unsigned int technology;
  89. unsigned int density_mask;
  90. unsigned int options;
  91. unsigned int erase_shift;
  92. unsigned int page_shift;
  93. unsigned int page_mask;
  94. unsigned int writesize;
  95. unsigned int bufferram_index;
  96. struct onenand_bufferram bufferram[MAX_BUFFERRAM];
  97. int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
  98. int (*wait)(struct mtd_info *mtd, int state);
  99. int (*bbt_wait)(struct mtd_info *mtd, int state);
  100. void (*unlock_all)(struct mtd_info *mtd);
  101. int (*read_bufferram)(struct mtd_info *mtd, int area,
  102. unsigned char *buffer, int offset, size_t count);
  103. int (*write_bufferram)(struct mtd_info *mtd, int area,
  104. const unsigned char *buffer, int offset, size_t count);
  105. unsigned short (*read_word)(void __iomem *addr);
  106. void (*write_word)(unsigned short value, void __iomem *addr);
  107. void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
  108. int (*chip_probe)(struct mtd_info *mtd);
  109. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  110. int (*scan_bbt)(struct mtd_info *mtd);
  111. int (*enable)(struct mtd_info *mtd);
  112. int (*disable)(struct mtd_info *mtd);
  113. struct completion complete;
  114. int irq;
  115. spinlock_t chip_lock;
  116. wait_queue_head_t wq;
  117. flstate_t state;
  118. unsigned char *page_buf;
  119. unsigned char *oob_buf;
  120. #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
  121. unsigned char *verify_buf;
  122. #endif
  123. int subpagesize;
  124. void *bbm;
  125. void *priv;
  126. /*
  127. * Shows that the current operation is composed
  128. * of sequence of commands. For example, cache program.
  129. * Such command status OnGo bit is checked at the end of
  130. * sequence.
  131. */
  132. unsigned int ongoing;
  133. };
  134. /*
  135. * Helper macros
  136. */
  137. #define ONENAND_PAGES_PER_BLOCK (1<<6)
  138. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  139. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  140. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  141. #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
  142. #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
  143. #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
  144. #define FLEXONENAND(this) \
  145. (this->device_id & DEVICE_IS_FLEXONENAND)
  146. #define ONENAND_GET_SYS_CFG1(this) \
  147. (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
  148. #define ONENAND_SET_SYS_CFG1(v, this) \
  149. (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
  150. #define ONENAND_IS_DDP(this) \
  151. (this->device_id & ONENAND_DEVICE_IS_DDP)
  152. #define ONENAND_IS_MLC(this) \
  153. (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
  154. #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
  155. #define ONENAND_IS_2PLANE(this) \
  156. (this->options & ONENAND_HAS_2PLANE)
  157. #else
  158. #define ONENAND_IS_2PLANE(this) (0)
  159. #endif
  160. #define ONENAND_IS_CACHE_PROGRAM(this) \
  161. (this->options & ONENAND_HAS_CACHE_PROGRAM)
  162. #define ONENAND_IS_NOP_1(this) \
  163. (this->options & ONENAND_HAS_NOP_1)
  164. /* Check byte access in OneNAND */
  165. #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
  166. /*
  167. * Options bits
  168. */
  169. #define ONENAND_HAS_CONT_LOCK (0x0001)
  170. #define ONENAND_HAS_UNLOCK_ALL (0x0002)
  171. #define ONENAND_HAS_2PLANE (0x0004)
  172. #define ONENAND_HAS_4KB_PAGE (0x0008)
  173. #define ONENAND_HAS_CACHE_PROGRAM (0x0010)
  174. #define ONENAND_HAS_NOP_1 (0x0020)
  175. #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
  176. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  177. #define ONENAND_OOBBUF_ALLOC (0x2000)
  178. #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000)
  179. #define ONENAND_IS_4KB_PAGE(this) \
  180. (this->options & ONENAND_HAS_4KB_PAGE)
  181. /*
  182. * OneNAND Flash Manufacturer ID Codes
  183. */
  184. #define ONENAND_MFR_SAMSUNG 0xec
  185. #define ONENAND_MFR_NUMONYX 0x20
  186. /**
  187. * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
  188. * @name: Manufacturer name
  189. * @id: manufacturer ID code of device.
  190. */
  191. struct onenand_manufacturers {
  192. int id;
  193. char *name;
  194. };
  195. int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
  196. struct mtd_oob_ops *ops);
  197. unsigned onenand_block(struct onenand_chip *this, loff_t addr);
  198. loff_t onenand_addr(struct onenand_chip *this, int block);
  199. int flexonenand_region(struct mtd_info *mtd, loff_t addr);
  200. struct mtd_partition;
  201. struct onenand_platform_data {
  202. void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
  203. int (*read_bufferram)(struct mtd_info *mtd, int area,
  204. unsigned char *buffer, int offset, size_t count);
  205. struct mtd_partition *parts;
  206. unsigned int nr_parts;
  207. };
  208. #endif /* __LINUX_MTD_ONENAND_H */