onenand.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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/spinlock.h>
  14. #include <linux/completion.h>
  15. #include <linux/mtd/onenand_regs.h>
  16. #include <linux/mtd/bbm.h>
  17. #define MAX_BUFFERRAM 2
  18. /* Scan and identify a OneNAND device */
  19. extern int onenand_scan(struct mtd_info *mtd, int max_chips);
  20. /* Free resources held by the OneNAND device */
  21. extern void onenand_release(struct mtd_info *mtd);
  22. /*
  23. * onenand_state_t - chip states
  24. * Enumeration for OneNAND flash chip state
  25. */
  26. typedef enum {
  27. FL_READY,
  28. FL_READING,
  29. FL_WRITING,
  30. FL_ERASING,
  31. FL_SYNCING,
  32. FL_LOCKING,
  33. FL_RESETING,
  34. FL_OTPING,
  35. FL_PM_SUSPENDED,
  36. } onenand_state_t;
  37. /**
  38. * struct onenand_bufferram - OneNAND BufferRAM Data
  39. * @blockpage: block & page address in BufferRAM
  40. */
  41. struct onenand_bufferram {
  42. int blockpage;
  43. };
  44. /**
  45. * struct onenand_chip - OneNAND Private Flash Chip Data
  46. * @base: [BOARDSPECIFIC] address to access OneNAND
  47. * @chipsize: [INTERN] the size of one chip for multichip arrays
  48. * @device_id: [INTERN] device ID
  49. * @density_mask: chip density, used for DDP devices
  50. * @verstion_id: [INTERN] version ID
  51. * @options: [BOARDSPECIFIC] various chip options. They can
  52. * partly be set to inform onenand_scan about
  53. * @erase_shift: [INTERN] number of address bits in a block
  54. * @page_shift: [INTERN] number of address bits in a page
  55. * @page_mask: [INTERN] a page per block mask
  56. * @bufferram_index: [INTERN] BufferRAM index
  57. * @bufferram: [INTERN] BufferRAM info
  58. * @readw: [REPLACEABLE] hardware specific function for read short
  59. * @writew: [REPLACEABLE] hardware specific function for write short
  60. * @command: [REPLACEABLE] hardware specific function for writing
  61. * commands to the chip
  62. * @wait: [REPLACEABLE] hardware specific function for wait on ready
  63. * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
  64. * @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
  65. * @read_word: [REPLACEABLE] hardware specific function for read
  66. * register of OneNAND
  67. * @write_word: [REPLACEABLE] hardware specific function for write
  68. * register of OneNAND
  69. * @mmcontrol: sync burst read function
  70. * @block_markbad: function to mark a block as bad
  71. * @scan_bbt: [REPLACEALBE] hardware specific function for scanning
  72. * Bad block Table
  73. * @chip_lock: [INTERN] spinlock used to protect access to this
  74. * structure and the chip
  75. * @wq: [INTERN] wait queue to sleep on if a OneNAND
  76. * operation is in progress
  77. * @state: [INTERN] the current state of the OneNAND device
  78. * @page_buf: [INTERN] page main data buffer
  79. * @oob_buf: [INTERN] page oob data buffer
  80. * @subpagesize: [INTERN] holds the subpagesize
  81. * @ecclayout: [REPLACEABLE] the default ecc placement scheme
  82. * @bbm: [REPLACEABLE] pointer to Bad Block Management
  83. * @priv: [OPTIONAL] pointer to private chip date
  84. */
  85. struct onenand_chip {
  86. void __iomem *base;
  87. unsigned int chipsize;
  88. unsigned int device_id;
  89. unsigned int version_id;
  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 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 (*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 (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
  107. int (*scan_bbt)(struct mtd_info *mtd);
  108. struct completion complete;
  109. int irq;
  110. spinlock_t chip_lock;
  111. wait_queue_head_t wq;
  112. onenand_state_t state;
  113. unsigned char *page_buf;
  114. unsigned char *oob_buf;
  115. int subpagesize;
  116. struct nand_ecclayout *ecclayout;
  117. void *bbm;
  118. void *priv;
  119. };
  120. /*
  121. * Helper macros
  122. */
  123. #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
  124. #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
  125. #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
  126. #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
  127. #define ONENAND_GET_SYS_CFG1(this) \
  128. (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
  129. #define ONENAND_SET_SYS_CFG1(v, this) \
  130. (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
  131. #define ONENAND_IS_DDP(this) \
  132. (this->device_id & ONENAND_DEVICE_IS_DDP)
  133. /* Check byte access in OneNAND */
  134. #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
  135. /*
  136. * Options bits
  137. */
  138. #define ONENAND_HAS_CONT_LOCK (0x0001)
  139. #define ONENAND_HAS_UNLOCK_ALL (0x0002)
  140. #define ONENAND_PAGEBUF_ALLOC (0x1000)
  141. #define ONENAND_OOBBUF_ALLOC (0x2000)
  142. /*
  143. * OneNAND Flash Manufacturer ID Codes
  144. */
  145. #define ONENAND_MFR_SAMSUNG 0xec
  146. /**
  147. * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
  148. * @name: Manufacturer name
  149. * @id: manufacturer ID code of device.
  150. */
  151. struct onenand_manufacturers {
  152. int id;
  153. char *name;
  154. };
  155. #endif /* __LINUX_MTD_ONENAND_H */