denali.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * NAND Flash Controller Device Driver
  3. * Copyright (c) 2009 - 2010, Intel Corporation and its suppliers.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. */
  19. #ifndef __DENALI_H__
  20. #define __DENALI_H__
  21. #include <linux/mtd/nand.h>
  22. #define DEVICE_RESET 0x0
  23. #define DEVICE_RESET__BANK0 0x0001
  24. #define DEVICE_RESET__BANK1 0x0002
  25. #define DEVICE_RESET__BANK2 0x0004
  26. #define DEVICE_RESET__BANK3 0x0008
  27. #define TRANSFER_SPARE_REG 0x10
  28. #define TRANSFER_SPARE_REG__FLAG 0x0001
  29. #define LOAD_WAIT_CNT 0x20
  30. #define LOAD_WAIT_CNT__VALUE 0xffff
  31. #define PROGRAM_WAIT_CNT 0x30
  32. #define PROGRAM_WAIT_CNT__VALUE 0xffff
  33. #define ERASE_WAIT_CNT 0x40
  34. #define ERASE_WAIT_CNT__VALUE 0xffff
  35. #define INT_MON_CYCCNT 0x50
  36. #define INT_MON_CYCCNT__VALUE 0xffff
  37. #define RB_PIN_ENABLED 0x60
  38. #define RB_PIN_ENABLED__BANK0 0x0001
  39. #define RB_PIN_ENABLED__BANK1 0x0002
  40. #define RB_PIN_ENABLED__BANK2 0x0004
  41. #define RB_PIN_ENABLED__BANK3 0x0008
  42. #define MULTIPLANE_OPERATION 0x70
  43. #define MULTIPLANE_OPERATION__FLAG 0x0001
  44. #define MULTIPLANE_READ_ENABLE 0x80
  45. #define MULTIPLANE_READ_ENABLE__FLAG 0x0001
  46. #define COPYBACK_DISABLE 0x90
  47. #define COPYBACK_DISABLE__FLAG 0x0001
  48. #define CACHE_WRITE_ENABLE 0xa0
  49. #define CACHE_WRITE_ENABLE__FLAG 0x0001
  50. #define CACHE_READ_ENABLE 0xb0
  51. #define CACHE_READ_ENABLE__FLAG 0x0001
  52. #define PREFETCH_MODE 0xc0
  53. #define PREFETCH_MODE__PREFETCH_EN 0x0001
  54. #define PREFETCH_MODE__PREFETCH_BURST_LENGTH 0xfff0
  55. #define CHIP_ENABLE_DONT_CARE 0xd0
  56. #define CHIP_EN_DONT_CARE__FLAG 0x01
  57. #define ECC_ENABLE 0xe0
  58. #define ECC_ENABLE__FLAG 0x0001
  59. #define GLOBAL_INT_ENABLE 0xf0
  60. #define GLOBAL_INT_EN_FLAG 0x01
  61. #define WE_2_RE 0x100
  62. #define WE_2_RE__VALUE 0x003f
  63. #define ADDR_2_DATA 0x110
  64. #define ADDR_2_DATA__VALUE 0x003f
  65. #define RE_2_WE 0x120
  66. #define RE_2_WE__VALUE 0x003f
  67. #define ACC_CLKS 0x130
  68. #define ACC_CLKS__VALUE 0x000f
  69. #define NUMBER_OF_PLANES 0x140
  70. #define NUMBER_OF_PLANES__VALUE 0x0007
  71. #define PAGES_PER_BLOCK 0x150
  72. #define PAGES_PER_BLOCK__VALUE 0xffff
  73. #define DEVICE_WIDTH 0x160
  74. #define DEVICE_WIDTH__VALUE 0x0003
  75. #define DEVICE_MAIN_AREA_SIZE 0x170
  76. #define DEVICE_MAIN_AREA_SIZE__VALUE 0xffff
  77. #define DEVICE_SPARE_AREA_SIZE 0x180
  78. #define DEVICE_SPARE_AREA_SIZE__VALUE 0xffff
  79. #define TWO_ROW_ADDR_CYCLES 0x190
  80. #define TWO_ROW_ADDR_CYCLES__FLAG 0x0001
  81. #define MULTIPLANE_ADDR_RESTRICT 0x1a0
  82. #define MULTIPLANE_ADDR_RESTRICT__FLAG 0x0001
  83. #define ECC_CORRECTION 0x1b0
  84. #define ECC_CORRECTION__VALUE 0x001f
  85. #define READ_MODE 0x1c0
  86. #define READ_MODE__VALUE 0x000f
  87. #define WRITE_MODE 0x1d0
  88. #define WRITE_MODE__VALUE 0x000f
  89. #define COPYBACK_MODE 0x1e0
  90. #define COPYBACK_MODE__VALUE 0x000f
  91. #define RDWR_EN_LO_CNT 0x1f0
  92. #define RDWR_EN_LO_CNT__VALUE 0x001f
  93. #define RDWR_EN_HI_CNT 0x200
  94. #define RDWR_EN_HI_CNT__VALUE 0x001f
  95. #define MAX_RD_DELAY 0x210
  96. #define MAX_RD_DELAY__VALUE 0x000f
  97. #define CS_SETUP_CNT 0x220
  98. #define CS_SETUP_CNT__VALUE 0x001f
  99. #define SPARE_AREA_SKIP_BYTES 0x230
  100. #define SPARE_AREA_SKIP_BYTES__VALUE 0x003f
  101. #define SPARE_AREA_MARKER 0x240
  102. #define SPARE_AREA_MARKER__VALUE 0xffff
  103. #define DEVICES_CONNECTED 0x250
  104. #define DEVICES_CONNECTED__VALUE 0x0007
  105. #define DIE_MASK 0x260
  106. #define DIE_MASK__VALUE 0x00ff
  107. #define FIRST_BLOCK_OF_NEXT_PLANE 0x270
  108. #define FIRST_BLOCK_OF_NEXT_PLANE__VALUE 0xffff
  109. #define WRITE_PROTECT 0x280
  110. #define WRITE_PROTECT__FLAG 0x0001
  111. #define RE_2_RE 0x290
  112. #define RE_2_RE__VALUE 0x003f
  113. #define MANUFACTURER_ID 0x300
  114. #define MANUFACTURER_ID__VALUE 0x00ff
  115. #define DEVICE_ID 0x310
  116. #define DEVICE_ID__VALUE 0x00ff
  117. #define DEVICE_PARAM_0 0x320
  118. #define DEVICE_PARAM_0__VALUE 0x00ff
  119. #define DEVICE_PARAM_1 0x330
  120. #define DEVICE_PARAM_1__VALUE 0x00ff
  121. #define DEVICE_PARAM_2 0x340
  122. #define DEVICE_PARAM_2__VALUE 0x00ff
  123. #define LOGICAL_PAGE_DATA_SIZE 0x350
  124. #define LOGICAL_PAGE_DATA_SIZE__VALUE 0xffff
  125. #define LOGICAL_PAGE_SPARE_SIZE 0x360
  126. #define LOGICAL_PAGE_SPARE_SIZE__VALUE 0xffff
  127. #define REVISION 0x370
  128. #define REVISION__VALUE 0xffff
  129. #define MAKE_COMPARABLE_REVISION(x) swab16((x) & REVISION__VALUE)
  130. #define REVISION_5_1 0x00000501
  131. #define ONFI_DEVICE_FEATURES 0x380
  132. #define ONFI_DEVICE_FEATURES__VALUE 0x003f
  133. #define ONFI_OPTIONAL_COMMANDS 0x390
  134. #define ONFI_OPTIONAL_COMMANDS__VALUE 0x003f
  135. #define ONFI_TIMING_MODE 0x3a0
  136. #define ONFI_TIMING_MODE__VALUE 0x003f
  137. #define ONFI_PGM_CACHE_TIMING_MODE 0x3b0
  138. #define ONFI_PGM_CACHE_TIMING_MODE__VALUE 0x003f
  139. #define ONFI_DEVICE_NO_OF_LUNS 0x3c0
  140. #define ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS 0x00ff
  141. #define ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE 0x0100
  142. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L 0x3d0
  143. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L__VALUE 0xffff
  144. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U 0x3e0
  145. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U__VALUE 0xffff
  146. #define FEATURES 0x3f0
  147. #define FEATURES__N_BANKS 0x0003
  148. #define FEATURES__ECC_MAX_ERR 0x003c
  149. #define FEATURES__DMA 0x0040
  150. #define FEATURES__CMD_DMA 0x0080
  151. #define FEATURES__PARTITION 0x0100
  152. #define FEATURES__XDMA_SIDEBAND 0x0200
  153. #define FEATURES__GPREG 0x0400
  154. #define FEATURES__INDEX_ADDR 0x0800
  155. #define TRANSFER_MODE 0x400
  156. #define TRANSFER_MODE__VALUE 0x0003
  157. #define INTR_STATUS(__bank) (0x410 + ((__bank) * 0x50))
  158. #define INTR_EN(__bank) (0x420 + ((__bank) * 0x50))
  159. #define INTR_STATUS__ECC_TRANSACTION_DONE 0x0001
  160. #define INTR_STATUS__ECC_ERR 0x0002
  161. #define INTR_STATUS__DMA_CMD_COMP 0x0004
  162. #define INTR_STATUS__TIME_OUT 0x0008
  163. #define INTR_STATUS__PROGRAM_FAIL 0x0010
  164. #define INTR_STATUS__ERASE_FAIL 0x0020
  165. #define INTR_STATUS__LOAD_COMP 0x0040
  166. #define INTR_STATUS__PROGRAM_COMP 0x0080
  167. #define INTR_STATUS__ERASE_COMP 0x0100
  168. #define INTR_STATUS__PIPE_CPYBCK_CMD_COMP 0x0200
  169. #define INTR_STATUS__LOCKED_BLK 0x0400
  170. #define INTR_STATUS__UNSUP_CMD 0x0800
  171. #define INTR_STATUS__INT_ACT 0x1000
  172. #define INTR_STATUS__RST_COMP 0x2000
  173. #define INTR_STATUS__PIPE_CMD_ERR 0x4000
  174. #define INTR_STATUS__PAGE_XFER_INC 0x8000
  175. #define INTR_EN__ECC_TRANSACTION_DONE 0x0001
  176. #define INTR_EN__ECC_ERR 0x0002
  177. #define INTR_EN__DMA_CMD_COMP 0x0004
  178. #define INTR_EN__TIME_OUT 0x0008
  179. #define INTR_EN__PROGRAM_FAIL 0x0010
  180. #define INTR_EN__ERASE_FAIL 0x0020
  181. #define INTR_EN__LOAD_COMP 0x0040
  182. #define INTR_EN__PROGRAM_COMP 0x0080
  183. #define INTR_EN__ERASE_COMP 0x0100
  184. #define INTR_EN__PIPE_CPYBCK_CMD_COMP 0x0200
  185. #define INTR_EN__LOCKED_BLK 0x0400
  186. #define INTR_EN__UNSUP_CMD 0x0800
  187. #define INTR_EN__INT_ACT 0x1000
  188. #define INTR_EN__RST_COMP 0x2000
  189. #define INTR_EN__PIPE_CMD_ERR 0x4000
  190. #define INTR_EN__PAGE_XFER_INC 0x8000
  191. #define PAGE_CNT(__bank) (0x430 + ((__bank) * 0x50))
  192. #define ERR_PAGE_ADDR(__bank) (0x440 + ((__bank) * 0x50))
  193. #define ERR_BLOCK_ADDR(__bank) (0x450 + ((__bank) * 0x50))
  194. #define DATA_INTR 0x550
  195. #define DATA_INTR__WRITE_SPACE_AV 0x0001
  196. #define DATA_INTR__READ_DATA_AV 0x0002
  197. #define DATA_INTR_EN 0x560
  198. #define DATA_INTR_EN__WRITE_SPACE_AV 0x0001
  199. #define DATA_INTR_EN__READ_DATA_AV 0x0002
  200. #define GPREG_0 0x570
  201. #define GPREG_0__VALUE 0xffff
  202. #define GPREG_1 0x580
  203. #define GPREG_1__VALUE 0xffff
  204. #define GPREG_2 0x590
  205. #define GPREG_2__VALUE 0xffff
  206. #define GPREG_3 0x5a0
  207. #define GPREG_3__VALUE 0xffff
  208. #define ECC_THRESHOLD 0x600
  209. #define ECC_THRESHOLD__VALUE 0x03ff
  210. #define ECC_ERROR_BLOCK_ADDRESS 0x610
  211. #define ECC_ERROR_BLOCK_ADDRESS__VALUE 0xffff
  212. #define ECC_ERROR_PAGE_ADDRESS 0x620
  213. #define ECC_ERROR_PAGE_ADDRESS__VALUE 0x0fff
  214. #define ECC_ERROR_PAGE_ADDRESS__BANK 0xf000
  215. #define ECC_ERROR_ADDRESS 0x630
  216. #define ECC_ERROR_ADDRESS__OFFSET 0x0fff
  217. #define ECC_ERROR_ADDRESS__SECTOR_NR 0xf000
  218. #define ERR_CORRECTION_INFO 0x640
  219. #define ERR_CORRECTION_INFO__BYTEMASK 0x00ff
  220. #define ERR_CORRECTION_INFO__DEVICE_NR 0x0f00
  221. #define ERR_CORRECTION_INFO__ERROR_TYPE 0x4000
  222. #define ERR_CORRECTION_INFO__LAST_ERR_INFO 0x8000
  223. #define DMA_ENABLE 0x700
  224. #define DMA_ENABLE__FLAG 0x0001
  225. #define IGNORE_ECC_DONE 0x710
  226. #define IGNORE_ECC_DONE__FLAG 0x0001
  227. #define DMA_INTR 0x720
  228. #define DMA_INTR__TARGET_ERROR 0x0001
  229. #define DMA_INTR__DESC_COMP_CHANNEL0 0x0002
  230. #define DMA_INTR__DESC_COMP_CHANNEL1 0x0004
  231. #define DMA_INTR__DESC_COMP_CHANNEL2 0x0008
  232. #define DMA_INTR__DESC_COMP_CHANNEL3 0x0010
  233. #define DMA_INTR__MEMCOPY_DESC_COMP 0x0020
  234. #define DMA_INTR_EN 0x730
  235. #define DMA_INTR_EN__TARGET_ERROR 0x0001
  236. #define DMA_INTR_EN__DESC_COMP_CHANNEL0 0x0002
  237. #define DMA_INTR_EN__DESC_COMP_CHANNEL1 0x0004
  238. #define DMA_INTR_EN__DESC_COMP_CHANNEL2 0x0008
  239. #define DMA_INTR_EN__DESC_COMP_CHANNEL3 0x0010
  240. #define DMA_INTR_EN__MEMCOPY_DESC_COMP 0x0020
  241. #define TARGET_ERR_ADDR_LO 0x740
  242. #define TARGET_ERR_ADDR_LO__VALUE 0xffff
  243. #define TARGET_ERR_ADDR_HI 0x750
  244. #define TARGET_ERR_ADDR_HI__VALUE 0xffff
  245. #define CHNL_ACTIVE 0x760
  246. #define CHNL_ACTIVE__CHANNEL0 0x0001
  247. #define CHNL_ACTIVE__CHANNEL1 0x0002
  248. #define CHNL_ACTIVE__CHANNEL2 0x0004
  249. #define CHNL_ACTIVE__CHANNEL3 0x0008
  250. #define ACTIVE_SRC_ID 0x800
  251. #define ACTIVE_SRC_ID__VALUE 0x00ff
  252. #define PTN_INTR 0x810
  253. #define PTN_INTR__CONFIG_ERROR 0x0001
  254. #define PTN_INTR__ACCESS_ERROR_BANK0 0x0002
  255. #define PTN_INTR__ACCESS_ERROR_BANK1 0x0004
  256. #define PTN_INTR__ACCESS_ERROR_BANK2 0x0008
  257. #define PTN_INTR__ACCESS_ERROR_BANK3 0x0010
  258. #define PTN_INTR__REG_ACCESS_ERROR 0x0020
  259. #define PTN_INTR_EN 0x820
  260. #define PTN_INTR_EN__CONFIG_ERROR 0x0001
  261. #define PTN_INTR_EN__ACCESS_ERROR_BANK0 0x0002
  262. #define PTN_INTR_EN__ACCESS_ERROR_BANK1 0x0004
  263. #define PTN_INTR_EN__ACCESS_ERROR_BANK2 0x0008
  264. #define PTN_INTR_EN__ACCESS_ERROR_BANK3 0x0010
  265. #define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020
  266. #define PERM_SRC_ID(__bank) (0x830 + ((__bank) * 0x40))
  267. #define PERM_SRC_ID__SRCID 0x00ff
  268. #define PERM_SRC_ID__DIRECT_ACCESS_ACTIVE 0x0800
  269. #define PERM_SRC_ID__WRITE_ACTIVE 0x2000
  270. #define PERM_SRC_ID__READ_ACTIVE 0x4000
  271. #define PERM_SRC_ID__PARTITION_VALID 0x8000
  272. #define MIN_BLK_ADDR(__bank) (0x840 + ((__bank) * 0x40))
  273. #define MIN_BLK_ADDR__VALUE 0xffff
  274. #define MAX_BLK_ADDR(__bank) (0x850 + ((__bank) * 0x40))
  275. #define MAX_BLK_ADDR__VALUE 0xffff
  276. #define MIN_MAX_BANK(__bank) (0x860 + ((__bank) * 0x40))
  277. #define MIN_MAX_BANK__MIN_VALUE 0x0003
  278. #define MIN_MAX_BANK__MAX_VALUE 0x000c
  279. /* ffsdefs.h */
  280. #define CLEAR 0 /*use this to clear a field instead of "fail"*/
  281. #define SET 1 /*use this to set a field instead of "pass"*/
  282. #define FAIL 1 /*failed flag*/
  283. #define PASS 0 /*success flag*/
  284. #define ERR -1 /*error flag*/
  285. /* lld.h */
  286. #define GOOD_BLOCK 0
  287. #define DEFECTIVE_BLOCK 1
  288. #define READ_ERROR 2
  289. #define CLK_X 5
  290. #define CLK_MULTI 4
  291. /* spectraswconfig.h */
  292. #define CMD_DMA 0
  293. #define SPECTRA_PARTITION_ID 0
  294. /**** Block Table and Reserved Block Parameters *****/
  295. #define SPECTRA_START_BLOCK 3
  296. #define NUM_FREE_BLOCKS_GATE 30
  297. /* KBV - Updated to LNW scratch register address */
  298. #define SCRATCH_REG_ADDR CONFIG_MTD_NAND_DENALI_SCRATCH_REG_ADDR
  299. #define SCRATCH_REG_SIZE 64
  300. #define GLOB_HWCTL_DEFAULT_BLKS 2048
  301. #define SUPPORT_15BITECC 1
  302. #define SUPPORT_8BITECC 1
  303. #define CUSTOM_CONF_PARAMS 0
  304. #define ONFI_BLOOM_TIME 1
  305. #define MODE5_WORKAROUND 0
  306. #define MODE_00 0x00000000
  307. #define MODE_01 0x04000000
  308. #define MODE_10 0x08000000
  309. #define MODE_11 0x0C000000
  310. #define DATA_TRANSFER_MODE 0
  311. #define PROTECTION_PER_BLOCK 1
  312. #define LOAD_WAIT_COUNT 2
  313. #define PROGRAM_WAIT_COUNT 3
  314. #define ERASE_WAIT_COUNT 4
  315. #define INT_MONITOR_CYCLE_COUNT 5
  316. #define READ_BUSY_PIN_ENABLED 6
  317. #define MULTIPLANE_OPERATION_SUPPORT 7
  318. #define PRE_FETCH_MODE 8
  319. #define CE_DONT_CARE_SUPPORT 9
  320. #define COPYBACK_SUPPORT 10
  321. #define CACHE_WRITE_SUPPORT 11
  322. #define CACHE_READ_SUPPORT 12
  323. #define NUM_PAGES_IN_BLOCK 13
  324. #define ECC_ENABLE_SELECT 14
  325. #define WRITE_ENABLE_2_READ_ENABLE 15
  326. #define ADDRESS_2_DATA 16
  327. #define READ_ENABLE_2_WRITE_ENABLE 17
  328. #define TWO_ROW_ADDRESS_CYCLES 18
  329. #define MULTIPLANE_ADDRESS_RESTRICT 19
  330. #define ACC_CLOCKS 20
  331. #define READ_WRITE_ENABLE_LOW_COUNT 21
  332. #define READ_WRITE_ENABLE_HIGH_COUNT 22
  333. #define ECC_SECTOR_SIZE 512
  334. struct nand_buf {
  335. int head;
  336. int tail;
  337. uint8_t *buf;
  338. dma_addr_t dma_buf;
  339. };
  340. #define INTEL_CE4100 1
  341. #define INTEL_MRST 2
  342. #define DT 3
  343. struct denali_nand_info {
  344. struct nand_chip nand;
  345. int flash_bank; /* currently selected chip */
  346. int status;
  347. int platform;
  348. struct nand_buf buf;
  349. struct device *dev;
  350. int total_used_banks;
  351. uint32_t block; /* stored for future use */
  352. uint16_t page;
  353. void __iomem *flash_reg; /* Mapped io reg base address */
  354. void __iomem *flash_mem; /* Mapped io reg base address */
  355. /* elements used by ISR */
  356. struct completion complete;
  357. spinlock_t irq_lock;
  358. uint32_t irq_status;
  359. int irq_debug_array[32];
  360. int idx;
  361. int irq;
  362. uint32_t devnum; /* represent how many nands connected */
  363. uint32_t fwblks; /* represent how many blocks FW used */
  364. uint32_t totalblks;
  365. uint32_t blksperchip;
  366. uint32_t bbtskipbytes;
  367. uint32_t max_banks;
  368. };
  369. extern int denali_init(struct denali_nand_info *denali);
  370. extern void denali_remove(struct denali_nand_info *denali);
  371. #endif /* __DENALI_H__ */