onenand.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. * @block_markbad: function to mark a block as bad
  66. * @scan_bbt: [REPLACEALBE] hardware specific function for scanning
  67. * Bad block Table
  68. * @chip_lock: [INTERN] spinlock used to protect access to this
  69. * structure and the chip
  70. * @wq: [INTERN] wait queue to sleep on if a OneNAND
  71. * operation is in progress
  72. * @state: [INTERN] the current state of the OneNAND device
  73. * @page_buf: [INTERN] page main data buffer
  74. * @oob_buf: [INTERN] page oob data buffer
  75. * @subpagesize: [INTERN] holds the subpagesize
  76. * @ecclayout: [REPLACEABLE] the default ecc placement scheme
  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 (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  109. int (*scan_bbt)(struct mtd_info *mtd);
  110. struct completion complete;
  111. int irq;
  112. spinlock_t chip_lock;
  113. wait_queue_head_t wq;
  114. flstate_t state;
  115. unsigned char *page_buf;
  116. unsigned char *oob_buf;
  117. int subpagesize;
  118. struct nand_ecclayout *ecclayout;
  119. void *bbm;
  120. void *priv;
  121. };
  122. /*
  123. * Helper macros
  124. */
  125. #define ONENAND_PAGES_PER_BLOCK (1<<6)
  126. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  127. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  128. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  129. #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
  130. #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
  131. #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
  132. #define FLEXONENAND(this) \
  133. (this->device_id & DEVICE_IS_FLEXONENAND)
  134. #define ONENAND_GET_SYS_CFG1(this) \
  135. (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
  136. #define ONENAND_SET_SYS_CFG1(v, this) \
  137. (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
  138. #define ONENAND_IS_DDP(this) \
  139. (this->device_id & ONENAND_DEVICE_IS_DDP)
  140. #define ONENAND_IS_MLC(this) \
  141. (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
  142. #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
  143. #define ONENAND_IS_2PLANE(this) \
  144. (this->options & ONENAND_HAS_2PLANE)
  145. #else
  146. #define ONENAND_IS_2PLANE(this) (0)
  147. #endif
  148. /* Check byte access in OneNAND */
  149. #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
  150. /*
  151. * Options bits
  152. */
  153. #define ONENAND_HAS_CONT_LOCK (0x0001)
  154. #define ONENAND_HAS_UNLOCK_ALL (0x0002)
  155. #define ONENAND_HAS_2PLANE (0x0004)
  156. #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
  157. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  158. #define ONENAND_OOBBUF_ALLOC (0x2000)
  159. /*
  160. * OneNAND Flash Manufacturer ID Codes
  161. */
  162. #define ONENAND_MFR_SAMSUNG 0xec
  163. #define ONENAND_MFR_NUMONYX 0x20
  164. /**
  165. * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
  166. * @name: Manufacturer name
  167. * @id: manufacturer ID code of device.
  168. */
  169. struct onenand_manufacturers {
  170. int id;
  171. char *name;
  172. };
  173. int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
  174. struct mtd_oob_ops *ops);
  175. unsigned onenand_block(struct onenand_chip *this, loff_t addr);
  176. loff_t onenand_addr(struct onenand_chip *this, int block);
  177. int flexonenand_region(struct mtd_info *mtd, loff_t addr);
  178. struct mtd_partition;
  179. struct onenand_platform_data {
  180. void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
  181. struct mtd_partition *parts;
  182. unsigned int nr_parts;
  183. };
  184. #endif /* __LINUX_MTD_ONENAND_H */