onenand.h 5.2 KB

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