onenand.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * linux/include/linux/mtd/onenand.h
  3. *
  4. * Copyright (C) 2005-2007 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/mtd/onenand_regs.h>
  14. /* Note: The header order is impoertant */
  15. #include <onenand_uboot.h>
  16. #include <linux/mtd/compat.h>
  17. #include <linux/mtd/bbm.h>
  18. #define MAX_DIES 2
  19. #define MAX_BUFFERRAM 2
  20. #define MAX_ONENAND_PAGESIZE (4096 + 128)
  21. /* Scan and identify a OneNAND device */
  22. extern int onenand_scan (struct mtd_info *mtd, int max_chips);
  23. /* Free resources held by the OneNAND device */
  24. extern void onenand_release (struct mtd_info *mtd);
  25. /**
  26. * struct onenand_bufferram - OneNAND BufferRAM Data
  27. * @param blockpage block & page address in BufferRAM
  28. */
  29. struct onenand_bufferram {
  30. int blockpage;
  31. };
  32. /**
  33. * struct onenand_chip - OneNAND Private Flash Chip Data
  34. * @param base [BOARDSPECIFIC] address to access OneNAND
  35. * @dies: [INTERN][FLEXONENAND] number of dies on chip
  36. * @boundary: [INTERN][FLEXONENAND] Boundary of the dies
  37. * @diesize: [INTERN][FLEXONENAND] Size of the dies
  38. * @param chipsize [INTERN] the size of one chip for multichip arrays
  39. * @param device_id [INTERN] device ID
  40. * @param verstion_id [INTERN] version ID
  41. * @technology [INTERN] describes the internal NAND array technology such as SLC or MLC.
  42. * @density_mask: [INTERN] chip density, used for DDP devices
  43. * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
  44. * @param erase_shift [INTERN] number of address bits in a block
  45. * @param page_shift [INTERN] number of address bits in a page
  46. * @param ppb_shift [INTERN] number of address bits in a pages per block
  47. * @param page_mask [INTERN] a page per block mask
  48. * @param writesize [INTERN] a real page size
  49. * @param bufferam_index [INTERN] BufferRAM index
  50. * @param bufferam [INTERN] BufferRAM info
  51. * @param readw [REPLACEABLE] hardware specific function for read short
  52. * @param writew [REPLACEABLE] hardware specific function for write short
  53. * @param command [REPLACEABLE] hardware specific function for writing commands to the chip
  54. * @param wait [REPLACEABLE] hardware specific function for wait on ready
  55. * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  56. * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area
  57. * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip
  58. * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress
  59. * @param state [INTERN] the current state of the OneNAND device
  60. * @param autooob [REPLACEABLE] the default (auto)placement scheme
  61. * @param priv [OPTIONAL] pointer to private chip date
  62. */
  63. struct onenand_chip {
  64. void __iomem *base;
  65. unsigned int dies;
  66. unsigned int boundary[MAX_DIES];
  67. unsigned int diesize[MAX_DIES];
  68. unsigned int chipsize;
  69. unsigned int device_id;
  70. unsigned int version_id;
  71. unsigned int technology;
  72. unsigned int density_mask;
  73. unsigned int options;
  74. unsigned int erase_shift;
  75. unsigned int page_shift;
  76. unsigned int ppb_shift; /* Pages per block shift */
  77. unsigned int page_mask;
  78. unsigned int writesize;
  79. unsigned int bufferram_index;
  80. struct onenand_bufferram bufferram[MAX_BUFFERRAM];
  81. int (*command) (struct mtd_info *mtd, int cmd, loff_t address,
  82. size_t len);
  83. int (*wait) (struct mtd_info *mtd, int state);
  84. int (*bbt_wait) (struct mtd_info *mtd, int state);
  85. void (*unlock_all)(struct mtd_info *mtd);
  86. int (*read_bufferram) (struct mtd_info *mtd, loff_t addr, int area,
  87. unsigned char *buffer, int offset, size_t count);
  88. int (*write_bufferram) (struct mtd_info *mtd, loff_t addr, int area,
  89. const unsigned char *buffer, int offset,
  90. size_t count);
  91. unsigned short (*read_word) (void __iomem *addr);
  92. void (*write_word) (unsigned short value, void __iomem *addr);
  93. void (*mmcontrol) (struct mtd_info *mtd, int sync_read);
  94. int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  95. int (*scan_bbt)(struct mtd_info *mtd);
  96. unsigned char *main_buf;
  97. unsigned char *spare_buf;
  98. #ifdef DONT_USE_UBOOT
  99. spinlock_t chip_lock;
  100. wait_queue_head_t wq;
  101. #endif
  102. int state;
  103. unsigned char *page_buf;
  104. unsigned char *oob_buf;
  105. struct nand_oobinfo *autooob;
  106. int subpagesize;
  107. struct nand_ecclayout *ecclayout;
  108. void *bbm;
  109. void *priv;
  110. };
  111. /*
  112. * Helper macros
  113. */
  114. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  115. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  116. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  117. #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
  118. #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
  119. #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
  120. #define FLEXONENAND(this) (this->device_id & DEVICE_IS_FLEXONENAND)
  121. #define ONENAND_IS_MLC(this) (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
  122. #define ONENAND_IS_DDP(this) \
  123. (this->device_id & ONENAND_DEVICE_IS_DDP)
  124. #define ONENAND_IS_2PLANE(this) (0)
  125. /*
  126. * Options bits
  127. */
  128. #define ONENAND_HAS_CONT_LOCK (0x0001)
  129. #define ONENAND_HAS_UNLOCK_ALL (0x0002)
  130. #define ONENAND_HAS_2PLANE (0x0004)
  131. #define ONENAND_RUNTIME_BADBLOCK_CHECK (0x0200)
  132. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  133. #define ONENAND_OOBBUF_ALLOC (0x2000)
  134. /*
  135. * OneNAND Flash Manufacturer ID Codes
  136. */
  137. #define ONENAND_MFR_NUMONYX 0x20
  138. #define ONENAND_MFR_SAMSUNG 0xec
  139. /**
  140. * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
  141. * @param name: Manufacturer name
  142. * @param id: manufacturer ID code of device.
  143. */
  144. struct onenand_manufacturers {
  145. int id;
  146. char *name;
  147. };
  148. int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
  149. struct mtd_oob_ops *ops);
  150. unsigned int onenand_block(struct onenand_chip *this, loff_t addr);
  151. int flexonenand_region(struct mtd_info *mtd, loff_t addr);
  152. #endif /* __LINUX_MTD_ONENAND_H */