denali.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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 ONFI_DEVICE_FEATURES 0x380
  130. #define ONFI_DEVICE_FEATURES__VALUE 0x003f
  131. #define ONFI_OPTIONAL_COMMANDS 0x390
  132. #define ONFI_OPTIONAL_COMMANDS__VALUE 0x003f
  133. #define ONFI_TIMING_MODE 0x3a0
  134. #define ONFI_TIMING_MODE__VALUE 0x003f
  135. #define ONFI_PGM_CACHE_TIMING_MODE 0x3b0
  136. #define ONFI_PGM_CACHE_TIMING_MODE__VALUE 0x003f
  137. #define ONFI_DEVICE_NO_OF_LUNS 0x3c0
  138. #define ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS 0x00ff
  139. #define ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE 0x0100
  140. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L 0x3d0
  141. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L__VALUE 0xffff
  142. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U 0x3e0
  143. #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U__VALUE 0xffff
  144. #define FEATURES 0x3f0
  145. #define FEATURES__N_BANKS 0x0003
  146. #define FEATURES__ECC_MAX_ERR 0x003c
  147. #define FEATURES__DMA 0x0040
  148. #define FEATURES__CMD_DMA 0x0080
  149. #define FEATURES__PARTITION 0x0100
  150. #define FEATURES__XDMA_SIDEBAND 0x0200
  151. #define FEATURES__GPREG 0x0400
  152. #define FEATURES__INDEX_ADDR 0x0800
  153. #define TRANSFER_MODE 0x400
  154. #define TRANSFER_MODE__VALUE 0x0003
  155. #define INTR_STATUS(__bank) (0x410 + ((__bank) * 0x50))
  156. #define INTR_EN(__bank) (0x420 + ((__bank) * 0x50))
  157. #define INTR_STATUS__ECC_TRANSACTION_DONE 0x0001
  158. #define INTR_STATUS__ECC_ERR 0x0002
  159. #define INTR_STATUS__DMA_CMD_COMP 0x0004
  160. #define INTR_STATUS__TIME_OUT 0x0008
  161. #define INTR_STATUS__PROGRAM_FAIL 0x0010
  162. #define INTR_STATUS__ERASE_FAIL 0x0020
  163. #define INTR_STATUS__LOAD_COMP 0x0040
  164. #define INTR_STATUS__PROGRAM_COMP 0x0080
  165. #define INTR_STATUS__ERASE_COMP 0x0100
  166. #define INTR_STATUS__PIPE_CPYBCK_CMD_COMP 0x0200
  167. #define INTR_STATUS__LOCKED_BLK 0x0400
  168. #define INTR_STATUS__UNSUP_CMD 0x0800
  169. #define INTR_STATUS__INT_ACT 0x1000
  170. #define INTR_STATUS__RST_COMP 0x2000
  171. #define INTR_STATUS__PIPE_CMD_ERR 0x4000
  172. #define INTR_STATUS__PAGE_XFER_INC 0x8000
  173. #define INTR_EN__ECC_TRANSACTION_DONE 0x0001
  174. #define INTR_EN__ECC_ERR 0x0002
  175. #define INTR_EN__DMA_CMD_COMP 0x0004
  176. #define INTR_EN__TIME_OUT 0x0008
  177. #define INTR_EN__PROGRAM_FAIL 0x0010
  178. #define INTR_EN__ERASE_FAIL 0x0020
  179. #define INTR_EN__LOAD_COMP 0x0040
  180. #define INTR_EN__PROGRAM_COMP 0x0080
  181. #define INTR_EN__ERASE_COMP 0x0100
  182. #define INTR_EN__PIPE_CPYBCK_CMD_COMP 0x0200
  183. #define INTR_EN__LOCKED_BLK 0x0400
  184. #define INTR_EN__UNSUP_CMD 0x0800
  185. #define INTR_EN__INT_ACT 0x1000
  186. #define INTR_EN__RST_COMP 0x2000
  187. #define INTR_EN__PIPE_CMD_ERR 0x4000
  188. #define INTR_EN__PAGE_XFER_INC 0x8000
  189. #define PAGE_CNT(__bank) (0x430 + ((__bank) * 0x50))
  190. #define ERR_PAGE_ADDR(__bank) (0x440 + ((__bank) * 0x50))
  191. #define ERR_BLOCK_ADDR(__bank) (0x450 + ((__bank) * 0x50))
  192. #define DATA_INTR 0x550
  193. #define DATA_INTR__WRITE_SPACE_AV 0x0001
  194. #define DATA_INTR__READ_DATA_AV 0x0002
  195. #define DATA_INTR_EN 0x560
  196. #define DATA_INTR_EN__WRITE_SPACE_AV 0x0001
  197. #define DATA_INTR_EN__READ_DATA_AV 0x0002
  198. #define GPREG_0 0x570
  199. #define GPREG_0__VALUE 0xffff
  200. #define GPREG_1 0x580
  201. #define GPREG_1__VALUE 0xffff
  202. #define GPREG_2 0x590
  203. #define GPREG_2__VALUE 0xffff
  204. #define GPREG_3 0x5a0
  205. #define GPREG_3__VALUE 0xffff
  206. #define ECC_THRESHOLD 0x600
  207. #define ECC_THRESHOLD__VALUE 0x03ff
  208. #define ECC_ERROR_BLOCK_ADDRESS 0x610
  209. #define ECC_ERROR_BLOCK_ADDRESS__VALUE 0xffff
  210. #define ECC_ERROR_PAGE_ADDRESS 0x620
  211. #define ECC_ERROR_PAGE_ADDRESS__VALUE 0x0fff
  212. #define ECC_ERROR_PAGE_ADDRESS__BANK 0xf000
  213. #define ECC_ERROR_ADDRESS 0x630
  214. #define ECC_ERROR_ADDRESS__OFFSET 0x0fff
  215. #define ECC_ERROR_ADDRESS__SECTOR_NR 0xf000
  216. #define ERR_CORRECTION_INFO 0x640
  217. #define ERR_CORRECTION_INFO__BYTEMASK 0x00ff
  218. #define ERR_CORRECTION_INFO__DEVICE_NR 0x0f00
  219. #define ERR_CORRECTION_INFO__ERROR_TYPE 0x4000
  220. #define ERR_CORRECTION_INFO__LAST_ERR_INFO 0x8000
  221. #define DMA_ENABLE 0x700
  222. #define DMA_ENABLE__FLAG 0x0001
  223. #define IGNORE_ECC_DONE 0x710
  224. #define IGNORE_ECC_DONE__FLAG 0x0001
  225. #define DMA_INTR 0x720
  226. #define DMA_INTR__TARGET_ERROR 0x0001
  227. #define DMA_INTR__DESC_COMP_CHANNEL0 0x0002
  228. #define DMA_INTR__DESC_COMP_CHANNEL1 0x0004
  229. #define DMA_INTR__DESC_COMP_CHANNEL2 0x0008
  230. #define DMA_INTR__DESC_COMP_CHANNEL3 0x0010
  231. #define DMA_INTR__MEMCOPY_DESC_COMP 0x0020
  232. #define DMA_INTR_EN 0x730
  233. #define DMA_INTR_EN__TARGET_ERROR 0x0001
  234. #define DMA_INTR_EN__DESC_COMP_CHANNEL0 0x0002
  235. #define DMA_INTR_EN__DESC_COMP_CHANNEL1 0x0004
  236. #define DMA_INTR_EN__DESC_COMP_CHANNEL2 0x0008
  237. #define DMA_INTR_EN__DESC_COMP_CHANNEL3 0x0010
  238. #define DMA_INTR_EN__MEMCOPY_DESC_COMP 0x0020
  239. #define TARGET_ERR_ADDR_LO 0x740
  240. #define TARGET_ERR_ADDR_LO__VALUE 0xffff
  241. #define TARGET_ERR_ADDR_HI 0x750
  242. #define TARGET_ERR_ADDR_HI__VALUE 0xffff
  243. #define CHNL_ACTIVE 0x760
  244. #define CHNL_ACTIVE__CHANNEL0 0x0001
  245. #define CHNL_ACTIVE__CHANNEL1 0x0002
  246. #define CHNL_ACTIVE__CHANNEL2 0x0004
  247. #define CHNL_ACTIVE__CHANNEL3 0x0008
  248. #define ACTIVE_SRC_ID 0x800
  249. #define ACTIVE_SRC_ID__VALUE 0x00ff
  250. #define PTN_INTR 0x810
  251. #define PTN_INTR__CONFIG_ERROR 0x0001
  252. #define PTN_INTR__ACCESS_ERROR_BANK0 0x0002
  253. #define PTN_INTR__ACCESS_ERROR_BANK1 0x0004
  254. #define PTN_INTR__ACCESS_ERROR_BANK2 0x0008
  255. #define PTN_INTR__ACCESS_ERROR_BANK3 0x0010
  256. #define PTN_INTR__REG_ACCESS_ERROR 0x0020
  257. #define PTN_INTR_EN 0x820
  258. #define PTN_INTR_EN__CONFIG_ERROR 0x0001
  259. #define PTN_INTR_EN__ACCESS_ERROR_BANK0 0x0002
  260. #define PTN_INTR_EN__ACCESS_ERROR_BANK1 0x0004
  261. #define PTN_INTR_EN__ACCESS_ERROR_BANK2 0x0008
  262. #define PTN_INTR_EN__ACCESS_ERROR_BANK3 0x0010
  263. #define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020
  264. #define PERM_SRC_ID(__bank) (0x830 + ((__bank) * 0x40))
  265. #define PERM_SRC_ID__SRCID 0x00ff
  266. #define PERM_SRC_ID__DIRECT_ACCESS_ACTIVE 0x0800
  267. #define PERM_SRC_ID__WRITE_ACTIVE 0x2000
  268. #define PERM_SRC_ID__READ_ACTIVE 0x4000
  269. #define PERM_SRC_ID__PARTITION_VALID 0x8000
  270. #define MIN_BLK_ADDR(__bank) (0x840 + ((__bank) * 0x40))
  271. #define MIN_BLK_ADDR__VALUE 0xffff
  272. #define MAX_BLK_ADDR(__bank) (0x850 + ((__bank) * 0x40))
  273. #define MAX_BLK_ADDR__VALUE 0xffff
  274. #define MIN_MAX_BANK(__bank) (0x860 + ((__bank) * 0x40))
  275. #define MIN_MAX_BANK__MIN_VALUE 0x0003
  276. #define MIN_MAX_BANK__MAX_VALUE 0x000c
  277. /* ffsdefs.h */
  278. #define CLEAR 0 /*use this to clear a field instead of "fail"*/
  279. #define SET 1 /*use this to set a field instead of "pass"*/
  280. #define FAIL 1 /*failed flag*/
  281. #define PASS 0 /*success flag*/
  282. #define ERR -1 /*error flag*/
  283. /* lld.h */
  284. #define GOOD_BLOCK 0
  285. #define DEFECTIVE_BLOCK 1
  286. #define READ_ERROR 2
  287. #define CLK_X 5
  288. #define CLK_MULTI 4
  289. /* spectraswconfig.h */
  290. #define CMD_DMA 0
  291. #define SPECTRA_PARTITION_ID 0
  292. /**** Block Table and Reserved Block Parameters *****/
  293. #define SPECTRA_START_BLOCK 3
  294. #define NUM_FREE_BLOCKS_GATE 30
  295. /* KBV - Updated to LNW scratch register address */
  296. #define SCRATCH_REG_ADDR CONFIG_MTD_NAND_DENALI_SCRATCH_REG_ADDR
  297. #define SCRATCH_REG_SIZE 64
  298. #define GLOB_HWCTL_DEFAULT_BLKS 2048
  299. #define SUPPORT_15BITECC 1
  300. #define SUPPORT_8BITECC 1
  301. #define CUSTOM_CONF_PARAMS 0
  302. #define ONFI_BLOOM_TIME 1
  303. #define MODE5_WORKAROUND 0
  304. #define MODE_00 0x00000000
  305. #define MODE_01 0x04000000
  306. #define MODE_10 0x08000000
  307. #define MODE_11 0x0C000000
  308. #define DATA_TRANSFER_MODE 0
  309. #define PROTECTION_PER_BLOCK 1
  310. #define LOAD_WAIT_COUNT 2
  311. #define PROGRAM_WAIT_COUNT 3
  312. #define ERASE_WAIT_COUNT 4
  313. #define INT_MONITOR_CYCLE_COUNT 5
  314. #define READ_BUSY_PIN_ENABLED 6
  315. #define MULTIPLANE_OPERATION_SUPPORT 7
  316. #define PRE_FETCH_MODE 8
  317. #define CE_DONT_CARE_SUPPORT 9
  318. #define COPYBACK_SUPPORT 10
  319. #define CACHE_WRITE_SUPPORT 11
  320. #define CACHE_READ_SUPPORT 12
  321. #define NUM_PAGES_IN_BLOCK 13
  322. #define ECC_ENABLE_SELECT 14
  323. #define WRITE_ENABLE_2_READ_ENABLE 15
  324. #define ADDRESS_2_DATA 16
  325. #define READ_ENABLE_2_WRITE_ENABLE 17
  326. #define TWO_ROW_ADDRESS_CYCLES 18
  327. #define MULTIPLANE_ADDRESS_RESTRICT 19
  328. #define ACC_CLOCKS 20
  329. #define READ_WRITE_ENABLE_LOW_COUNT 21
  330. #define READ_WRITE_ENABLE_HIGH_COUNT 22
  331. #define ECC_SECTOR_SIZE 512
  332. struct nand_buf {
  333. int head;
  334. int tail;
  335. uint8_t *buf;
  336. dma_addr_t dma_buf;
  337. };
  338. #define INTEL_CE4100 1
  339. #define INTEL_MRST 2
  340. #define DT 3
  341. struct denali_nand_info {
  342. struct mtd_info mtd;
  343. struct nand_chip nand;
  344. int flash_bank; /* currently selected chip */
  345. int status;
  346. int platform;
  347. struct nand_buf buf;
  348. struct device *dev;
  349. int total_used_banks;
  350. uint32_t block; /* stored for future use */
  351. uint16_t page;
  352. void __iomem *flash_reg; /* Mapped io reg base address */
  353. void __iomem *flash_mem; /* Mapped io reg base address */
  354. /* elements used by ISR */
  355. struct completion complete;
  356. spinlock_t irq_lock;
  357. uint32_t irq_status;
  358. int irq_debug_array[32];
  359. int idx;
  360. int irq;
  361. uint32_t devnum; /* represent how many nands connected */
  362. uint32_t fwblks; /* represent how many blocks FW used */
  363. uint32_t totalblks;
  364. uint32_t blksperchip;
  365. uint32_t bbtskipbytes;
  366. uint32_t max_banks;
  367. };
  368. extern int denali_init(struct denali_nand_info *denali);
  369. extern void denali_remove(struct denali_nand_info *denali);
  370. #endif /* __DENALI_H__ */