PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/board/cogent/flash.h

https://bitbucket.org/accelecon/u-boot
C Header | 305 lines | 172 code | 50 blank | 83 comment | 0 complexity | 1402934697283d96f25da38c84fb9983 MD5 | raw file
Possible License(s): AGPL-1.0
  1. /**************** DEFINES for Intel 28F008S5 FLASH chip **********************/
  2. /* register addresses, valid only following a I8S5_CMD_RD_ID command */
  3. #define I8S5_ADDR_MAN 0x00000 /* manufacturer's id */
  4. #define I8S5_ADDR_DEV 0x00001 /* device id */
  5. #define I8S5_ADDR_CFGM 0x00003 /* master lock configuration */
  6. #define I8S5_ADDR_CFG(b) (((b)<<16)|2) /* block lock configuration */
  7. /* Commands */
  8. #define I8S5_CMD_RST 0xFF /* reset flash */
  9. #define I8S5_CMD_RD_ID 0x90 /* read the id and lock bits */
  10. #define I8S5_CMD_RD_STAT 0x70 /* read the status register */
  11. #define I8S5_CMD_CLR_STAT 0x50 /* clear the staus register */
  12. #define I8S5_CMD_ERASE1 0x20 /* first word for block erase */
  13. #define I8S5_CMD_ERASE2 0xD0 /* second word for block erase */
  14. #define I8S5_CMD_PROG 0x40 /* program word command */
  15. #define I8S5_CMD_LOCK 0x60 /* first word for all lock commands */
  16. #define I8S5_CMD_SET_LOCK_BLK 0x01 /* 2nd word for set block lock bit */
  17. #define I8S5_CMD_SET_LOCK_MSTR 0xF1 /* 2nd word for set master lock bit */
  18. #define I8S5_CMD_CLR_LOCK_BLK 0xD0 /* 2nd word for clear block lock bit */
  19. /* status register bits */
  20. #define I8S5_STAT_DPS 0x02 /* Device Protect Status */
  21. #define I8S5_STAT_PSS 0x04 /* Program Suspend Status */
  22. #define I8S5_STAT_VPPS 0x08 /* VPP Status */
  23. #define I8S5_STAT_PSLBS 0x10 /* Program and Set Lock Bit Status */
  24. #define I8S5_STAT_ECLBS 0x20 /* Erase and Clear Lock Bit Status */
  25. #define I8S5_STAT_ESS 0x40 /* Erase Suspend Status */
  26. #define I8S5_STAT_RDY 0x80 /* Write State Machine Status, 1=rdy */
  27. #define I8S5_STAT_ERR (I8S5_STAT_VPPS | I8S5_STAT_DPS | \
  28. I8S5_STAT_ECLBS | I8S5_STAT_PSLBS)
  29. /* ID and Lock Configuration */
  30. #define I8S5_RD_ID_LOCK 0x01 /* Bit 0 of each byte */
  31. #define I8S5_RD_ID_MAN 0x89 /* Manufacturer code = 0x89 */
  32. #define I8S5_RD_ID_DEV 0xA6 /* Device code = 0xA6, 28F008S5 */
  33. /* dimensions */
  34. #define I8S5_NBLOCKS 16 /* a 28F008S5 consists of 16 blocks */
  35. #define I8S5_BLKSZ (64*1024) /* of 64Kbyte each */
  36. #define I8S5_SIZE (I8S5_BLKSZ * I8S5_NBLOCKS)
  37. /**************** DEFINES for Intel 28F800B5 FLASH chip **********************/
  38. /* register addresses, valid only following a I8S5_CMD_RD_ID command */
  39. #define I8B5_ADDR_MAN 0x00000 /* manufacturer's id */
  40. #define I8B5_ADDR_DEV 0x00001 /* device id */
  41. /* Commands */
  42. #define I8B5_CMD_RST 0xFF /* reset flash */
  43. #define I8B5_CMD_RD_ID 0x90 /* read the id and lock bits */
  44. #define I8B5_CMD_RD_STAT 0x70 /* read the status register */
  45. #define I8B5_CMD_CLR_STAT 0x50 /* clear the staus register */
  46. #define I8B5_CMD_ERASE1 0x20 /* first word for block erase */
  47. #define I8B5_CMD_ERASE2 0xD0 /* second word for block erase */
  48. #define I8B5_CMD_PROG 0x40 /* program word command */
  49. /* status register bits */
  50. #define I8B5_STAT_VPPS 0x08 /* VPP Status */
  51. #define I8B5_STAT_DWS 0x10 /* Program and Set Lock Bit Status */
  52. #define I8B5_STAT_ES 0x20 /* Erase and Clear Lock Bit Status */
  53. #define I8B5_STAT_ESS 0x40 /* Erase Suspend Status */
  54. #define I8B5_STAT_RDY 0x80 /* Write State Machine Status, 1=rdy */
  55. #define I8B5_STAT_ERR (I8B5_STAT_VPPS | I8B5_STAT_DWS | I8B5_STAT_ES)
  56. /* ID Configuration */
  57. #define I8B5_RD_ID_MAN 0x89 /* Manufacturer code = 0x89 */
  58. #define I8B5_RD_ID_DEV1 0x889D /* Device code = 0x889D, 28F800B5 */
  59. /* dimensions */
  60. #define I8B5_NBLOCKS 8 /* a 28F008S5 consists of 16 blocks */
  61. #define I8B5_BLKSZ (128*1024) /* of 64Kbyte each */
  62. #define I8B5_SIZE (I8B5_BLKSZ * I8B5_NBLOCKS)
  63. /****************** DEFINES for Cogent CMA302 Flash **************************/
  64. /*
  65. * Quoted from the CMA302 manual:
  66. *
  67. * Although the CMA302 supports 64-bit reads, all writes must be done with
  68. * word size only. When programming the CMA302, the FLASH devices appear as 2
  69. * banks of interleaved, 32-bit wide FLASH. Each 32-bit word consists of four
  70. * 28F008S5 devices. The first bank is accessed when the word address is even,
  71. * while the second bank is accessed when the word address is odd. This must
  72. * be taken into account when programming the desired word. Also, when locking
  73. * blocks, software must lock both banks. The CMA302 does not directly support
  74. * byte writing. Programming and/or erasing individual bytes is done with
  75. * selective use of the Write Command. By not placing the Write Command value
  76. * on a particular byte lane, that byte will not be written with the following
  77. * Write Data. Also, remember that within a byte lane (i.e. D0-7), there are
  78. * two 28F008S5 devices, one for each bank or every other word.
  79. *
  80. * End quote.
  81. *
  82. * Each 28F008S5 is 8Mbit, with 8 bit wide data. i.e. each is 1Mbyte. The
  83. * chips are arranged on the CMA302 in multiples of two banks, each bank having
  84. * 4 chips. Each bank must be accessed as a single 32 bit wide device (i.e.
  85. * aligned on a 32 bit boundary), with each byte lane within the 32 bits (0-3)
  86. * going to each of the 4 chips and the word address selecting the bank, even
  87. * being the low bank and odd the high bank. For 64bit reads, both banks are
  88. * read simultaneously with the second bank on byte lanes 4-7. Each 28F008S5
  89. * consists of 16 64Kbyte "block"s. Before programming a byte, the block that
  90. * the byte resides within must be erased. So if you want to program contiguous
  91. * memory locations, you must erase all 8 chips at the same time. i.e. the
  92. * flash on the CMA302 can be viewed as a number of 512Kbyte blocks.
  93. *
  94. * Note: I am going to treat banks as 8 Mbytes (1Meg of 64bit words), whereas
  95. * the example code treats them as a pair of interleaved 1 Mbyte x 32bit banks.
  96. */
  97. typedef unsigned long c302f_word_t; /* 32 or 64 bit unsigned integer */
  98. typedef volatile c302f_word_t *c302f_addr_t;
  99. typedef unsigned long c302f_size_t; /* want this big - at least 32 bit */
  100. /* layout of banks on cma302 board */
  101. #define C302F_BNK_WIDTH 8 /* each bank is 8 chips wide */
  102. #define C302F_BNK_WSHIFT 3 /* log base 2 of C302F_BNK_WIDTH */
  103. #define C302F_BNK_NBLOCKS I8S5_NBLOCKS
  104. #define C302F_BNK_BLKSZ (I8S5_BLKSZ * C302F_BNK_WIDTH)
  105. #define C302F_BNK_SIZE (I8S5_SIZE * C302F_BNK_WIDTH)
  106. #define C302F_MAX_BANKS 2 /* up to 2 banks (8M each) on CMA302 */
  107. /* align addresses and sizes to bank boundaries */
  108. #define C302F_BNK_ADDR_ALIGN(a) ((c302f_addr_t)((c302f_size_t)(a) \
  109. & ~(C302F_BNK_WIDTH - 1)))
  110. #define C302F_BNK_SIZE_ALIGN(s) ((c302f_size_t)C302F_BNK_ADDR_ALIGN( \
  111. (c302f_size_t)(s) + (C302F_BNK_WIDTH - 1)))
  112. /* align addresses and sizes to block boundaries */
  113. #define C302F_BLK_ADDR_ALIGN(a) ((c302f_addr_t)((c302f_size_t)(a) \
  114. & ~(C302F_BNK_BLKSZ - 1)))
  115. #define C302F_BLK_SIZE_ALIGN(s) ((c302f_size_t)C302F_BLK_ADDR_ALIGN( \
  116. (c302f_size_t)(s) + (C302F_BNK_BLKSZ - 1)))
  117. /* add a byte offset to a flash address */
  118. #define C302F_ADDR_ADD_BYTEOFF(a,o) \
  119. (c302f_addr_t)((c302f_size_t)(a) + (o))
  120. /* get base address of bank b, given flash base address a */
  121. #define C302F_BNK_ADDR_BASE(a,b) \
  122. C302F_ADDR_ADD_BYTEOFF((a), \
  123. (c302f_size_t)(b) * C302F_BNK_SIZE)
  124. /* adjust an address a (within a bank) to next word, block or bank */
  125. #define C302F_BNK_ADDR_NEXT_WORD(a) \
  126. C302F_ADDR_ADD_BYTEOFF((a), C302F_BNK_WIDTH)
  127. #define C302F_BNK_ADDR_NEXT_BLK(a) \
  128. C302F_ADDR_ADD_BYTEOFF((a), C302F_BNK_BLKSZ)
  129. #define C302F_BNK_ADDR_NEXT_BNK(a) \
  130. C302F_ADDR_ADD_BYTEOFF((a), C302F_BNK_SIZE)
  131. /* get bank address of chip register r given a bank base address a */
  132. #define C302F_BNK_ADDR_I8S5REG(a,r) \
  133. C302F_ADDR_ADD_BYTEOFF((a), \
  134. (r) << C302F_BNK_WSHIFT)
  135. /* make a bank representation for each chip address */
  136. #define C302F_BNK_ADDR_MAN(a) C302F_BNK_ADDR_I8S5REG((a), I8S5_ADDR_MAN)
  137. #define C302F_BNK_ADDR_DEV(a) C302F_BNK_ADDR_I8S5REG((a), I8S5_ADDR_DEV)
  138. #define C302F_BNK_ADDR_CFGM(a) C302F_BNK_ADDR_I8S5REG((a), I8S5_ADDR_CFGM)
  139. #define C302F_BNK_ADDR_CFG(b,a) C302F_BNK_ADDR_I8S5REG((a), I8S5_ADDR_CFG(b))
  140. /*
  141. * replicate a chip cmd/stat/rd value into each byte position within a word
  142. * so that multiple chips are accessed in a single word i/o operation
  143. *
  144. * this must be as wide as the c302f_word_t type
  145. */
  146. #define C302F_FILL_WORD(o) (((unsigned long)(o) << 24) | \
  147. ((unsigned long)(o) << 16) | \
  148. ((unsigned long)(o) << 8) | \
  149. (unsigned long)(o))
  150. /* make a bank representation for each chip cmd/stat/rd value */
  151. /* Commands */
  152. #define C302F_BNK_CMD_RST C302F_FILL_WORD(I8S5_CMD_RST)
  153. #define C302F_BNK_CMD_RD_ID C302F_FILL_WORD(I8S5_CMD_RD_ID)
  154. #define C302F_BNK_CMD_RD_STAT C302F_FILL_WORD(I8S5_CMD_RD_STAT)
  155. #define C302F_BNK_CMD_CLR_STAT C302F_FILL_WORD(I8S5_CMD_CLR_STAT)
  156. #define C302F_BNK_CMD_ERASE1 C302F_FILL_WORD(I8S5_CMD_ERASE1)
  157. #define C302F_BNK_CMD_ERASE2 C302F_FILL_WORD(I8S5_CMD_ERASE2)
  158. #define C302F_BNK_CMD_PROG C302F_FILL_WORD(I8S5_CMD_PROG)
  159. #define C302F_BNK_CMD_LOCK C302F_FILL_WORD(I8S5_CMD_LOCK)
  160. #define C302F_BNK_CMD_SET_LOCK_BLK C302F_FILL_WORD(I8S5_CMD_SET_LOCK_BLK)
  161. #define C302F_BNK_CMD_SET_LOCK_MSTR C302F_FILL_WORD(I8S5_CMD_SET_LOCK_MSTR)
  162. #define C302F_BNK_CMD_CLR_LOCK_BLK C302F_FILL_WORD(I8S5_CMD_CLR_LOCK_BLK)
  163. /* status register bits */
  164. #define C302F_BNK_STAT_DPS C302F_FILL_WORD(I8S5_STAT_DPS)
  165. #define C302F_BNK_STAT_PSS C302F_FILL_WORD(I8S5_STAT_PSS)
  166. #define C302F_BNK_STAT_VPPS C302F_FILL_WORD(I8S5_STAT_VPPS)
  167. #define C302F_BNK_STAT_PSLBS C302F_FILL_WORD(I8S5_STAT_PSLBS)
  168. #define C302F_BNK_STAT_ECLBS C302F_FILL_WORD(I8S5_STAT_ECLBS)
  169. #define C302F_BNK_STAT_ESS C302F_FILL_WORD(I8S5_STAT_ESS)
  170. #define C302F_BNK_STAT_RDY C302F_FILL_WORD(I8S5_STAT_RDY)
  171. #define C302F_BNK_STAT_ERR C302F_FILL_WORD(I8S5_STAT_ERR)
  172. /* ID and Lock Configuration */
  173. #define C302F_BNK_RD_ID_LOCK C302F_FILL_WORD(I8S5_RD_ID_LOCK)
  174. #define C302F_BNK_RD_ID_MAN C302F_FILL_WORD(I8S5_RD_ID_MAN)
  175. #define C302F_BNK_RD_ID_DEV C302F_FILL_WORD(I8S5_RD_ID_DEV)
  176. /*************** DEFINES for Cogent Motherboard Flash ************************/
  177. typedef unsigned short cmbf_word_t; /* 16 bit unsigned integer */
  178. typedef volatile cmbf_word_t *cmbf_addr_t;
  179. typedef unsigned long cmbf_size_t; /* want this big - at least 32 bit */
  180. /* layout of banks on cogent motherboard - only 1 bank, 16 bit wide */
  181. #define CMBF_BNK_WIDTH 1 /* each bank is one chip wide */
  182. #define CMBF_BNK_WSHIFT 0 /* log base 2 of CMBF_BNK_WIDTH */
  183. #define CMBF_BNK_NBLOCKS I8B5_NBLOCKS
  184. #define CMBF_BNK_BLKSZ (I8B5_BLKSZ * CMBF_BNK_WIDTH)
  185. #define CMBF_BNK_SIZE (I8B5_SIZE * CMBF_BNK_WIDTH)
  186. #define CMBF_MAX_BANKS 1 /* only 1 x 1Mbyte bank on cogent m/b */
  187. /* align addresses and sizes to bank boundaries */
  188. #define CMBF_BNK_ADDR_ALIGN(a) ((c302f_addr_t)((c302f_size_t)(a) \
  189. & ~(CMBF_BNK_WIDTH - 1)))
  190. #define CMBF_BNK_SIZE_ALIGN(s) ((c302f_size_t)CMBF_BNK_ADDR_ALIGN( \
  191. (c302f_size_t)(s) + (CMBF_BNK_WIDTH - 1)))
  192. /* align addresses and sizes to block boundaries */
  193. #define CMBF_BLK_ADDR_ALIGN(a) ((c302f_addr_t)((c302f_size_t)(a) \
  194. & ~(CMBF_BNK_BLKSZ - 1)))
  195. #define CMBF_BLK_SIZE_ALIGN(s) ((c302f_size_t)CMBF_BLK_ADDR_ALIGN( \
  196. (c302f_size_t)(s) + (CMBF_BNK_BLKSZ - 1)))
  197. /* add a byte offset to a flash address */
  198. #define CMBF_ADDR_ADD_BYTEOFF(a,o) \
  199. (c302f_addr_t)((c302f_size_t)(a) + (o))
  200. /* get base address of bank b, given flash base address a */
  201. #define CMBF_BNK_ADDR_BASE(a,b) \
  202. CMBF_ADDR_ADD_BYTEOFF((a), \
  203. (c302f_size_t)(b) * CMBF_BNK_SIZE)
  204. /* adjust an address a (within a bank) to next word, block or bank */
  205. #define CMBF_BNK_ADDR_NEXT_WORD(a) \
  206. CMBF_ADDR_ADD_BYTEOFF((a), CMBF_BNK_WIDTH)
  207. #define CMBF_BNK_ADDR_NEXT_BLK(a) \
  208. CMBF_ADDR_ADD_BYTEOFF((a), CMBF_BNK_BLKSZ)
  209. #define CMBF_BNK_ADDR_NEXT_BNK(a) \
  210. CMBF_ADDR_ADD_BYTEOFF((a), CMBF_BNK_SIZE)
  211. /* get bank address of chip register r given a bank base address a */
  212. #define CMBF_BNK_ADDR_I8B5REG(a,r) \
  213. CMBF_ADDR_ADD_BYTEOFF((a), \
  214. (r) << CMBF_BNK_WSHIFT)
  215. /* make a bank representation for each chip address */
  216. #define CMBF_BNK_ADDR_MAN(a) CMBF_BNK_ADDR_I8B5REG((a), I8B5_ADDR_MAN)
  217. #define CMBF_BNK_ADDR_DEV(a) CMBF_BNK_ADDR_I8B5REG((a), I8B5_ADDR_DEV)
  218. #define CMBF_BNK_ADDR_CFGM(a) CMBF_BNK_ADDR_I8B5REG((a), I8B5_ADDR_CFGM)
  219. #define CMBF_BNK_ADDR_CFG(b,a) CMBF_BNK_ADDR_I8B5REG((a), I8B5_ADDR_CFG(b))
  220. /*
  221. * replicate a chip cmd/stat/rd value into each byte position within a word
  222. * so that multiple chips are accessed in a single word i/o operation
  223. *
  224. * this must be as wide as the c302f_word_t type
  225. */
  226. #define CMBF_FILL_WORD(o) (((unsigned long)(o) << 24) | \
  227. ((unsigned long)(o) << 16) | \
  228. ((unsigned long)(o) << 8) | \
  229. (unsigned long)(o))
  230. /* make a bank representation for each chip cmd/stat/rd value */
  231. /* Commands */
  232. #define CMBF_BNK_CMD_RST CMBF_FILL_WORD(I8B5_CMD_RST)
  233. #define CMBF_BNK_CMD_RD_ID CMBF_FILL_WORD(I8B5_CMD_RD_ID)
  234. #define CMBF_BNK_CMD_RD_STAT CMBF_FILL_WORD(I8B5_CMD_RD_STAT)
  235. #define CMBF_BNK_CMD_CLR_STAT CMBF_FILL_WORD(I8B5_CMD_CLR_STAT)
  236. #define CMBF_BNK_CMD_ERASE1 CMBF_FILL_WORD(I8B5_CMD_ERASE1)
  237. #define CMBF_BNK_CMD_ERASE2 CMBF_FILL_WORD(I8B5_CMD_ERASE2)
  238. #define CMBF_BNK_CMD_PROG CMBF_FILL_WORD(I8B5_CMD_PROG)
  239. #define CMBF_BNK_CMD_LOCK CMBF_FILL_WORD(I8B5_CMD_LOCK)
  240. #define CMBF_BNK_CMD_SET_LOCK_BLK CMBF_FILL_WORD(I8B5_CMD_SET_LOCK_BLK)
  241. #define CMBF_BNK_CMD_SET_LOCK_MSTR CMBF_FILL_WORD(I8B5_CMD_SET_LOCK_MSTR)
  242. #define CMBF_BNK_CMD_CLR_LOCK_BLK CMBF_FILL_WORD(I8B5_CMD_CLR_LOCK_BLK)
  243. /* status register bits */
  244. #define CMBF_BNK_STAT_DPS CMBF_FILL_WORD(I8B5_STAT_DPS)
  245. #define CMBF_BNK_STAT_PSS CMBF_FILL_WORD(I8B5_STAT_PSS)
  246. #define CMBF_BNK_STAT_VPPS CMBF_FILL_WORD(I8B5_STAT_VPPS)
  247. #define CMBF_BNK_STAT_PSLBS CMBF_FILL_WORD(I8B5_STAT_PSLBS)
  248. #define CMBF_BNK_STAT_ECLBS CMBF_FILL_WORD(I8B5_STAT_ECLBS)
  249. #define CMBF_BNK_STAT_ESS CMBF_FILL_WORD(I8B5_STAT_ESS)
  250. #define CMBF_BNK_STAT_RDY CMBF_FILL_WORD(I8B5_STAT_RDY)
  251. #define CMBF_BNK_STAT_ERR CMBF_FILL_WORD(I8B5_STAT_ERR)
  252. /* ID and Lock Configuration */
  253. #define CMBF_BNK_RD_ID_LOCK CMBF_FILL_WORD(I8B5_RD_ID_LOCK)
  254. #define CMBF_BNK_RD_ID_MAN CMBF_FILL_WORD(I8B5_RD_ID_MAN)
  255. #define CMBF_BNK_RD_ID_DEV CMBF_FILL_WORD(I8B5_RD_ID_DEV)