fsmc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * incude/mtd/fsmc.h
  3. *
  4. * ST Microelectronics
  5. * Flexible Static Memory Controller (FSMC)
  6. * platform data interface and header file
  7. *
  8. * Copyright © 2010 ST Microelectronics
  9. * Vipin Kumar <vipin.kumar@st.com>
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #ifndef __MTD_FSMC_H
  16. #define __MTD_FSMC_H
  17. #include <linux/io.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/mtd/physmap.h>
  20. #include <linux/types.h>
  21. #include <linux/mtd/partitions.h>
  22. #include <asm/param.h>
  23. #define FSMC_NAND_BW8 1
  24. #define FSMC_NAND_BW16 2
  25. #define FSMC_MAX_NOR_BANKS 4
  26. #define FSMC_MAX_NAND_BANKS 4
  27. #define FSMC_FLASH_WIDTH8 1
  28. #define FSMC_FLASH_WIDTH16 2
  29. struct fsmc_nor_bank_regs {
  30. uint32_t ctrl;
  31. uint32_t ctrl_tim;
  32. };
  33. /* ctrl register definitions */
  34. #define BANK_ENABLE (1 << 0)
  35. #define MUXED (1 << 1)
  36. #define NOR_DEV (2 << 2)
  37. #define WIDTH_8 (0 << 4)
  38. #define WIDTH_16 (1 << 4)
  39. #define RSTPWRDWN (1 << 6)
  40. #define WPROT (1 << 7)
  41. #define WRT_ENABLE (1 << 12)
  42. #define WAIT_ENB (1 << 13)
  43. /* ctrl_tim register definitions */
  44. struct fsmc_nand_bank_regs {
  45. uint32_t pc;
  46. uint32_t sts;
  47. uint32_t comm;
  48. uint32_t attrib;
  49. uint32_t ioata;
  50. uint32_t ecc1;
  51. uint32_t ecc2;
  52. uint32_t ecc3;
  53. };
  54. #define FSMC_NOR_REG_SIZE 0x40
  55. struct fsmc_regs {
  56. struct fsmc_nor_bank_regs nor_bank_regs[FSMC_MAX_NOR_BANKS];
  57. uint8_t reserved_1[0x40 - 0x20];
  58. struct fsmc_nand_bank_regs bank_regs[FSMC_MAX_NAND_BANKS];
  59. uint8_t reserved_2[0xfe0 - 0xc0];
  60. uint32_t peripid0; /* 0xfe0 */
  61. uint32_t peripid1; /* 0xfe4 */
  62. uint32_t peripid2; /* 0xfe8 */
  63. uint32_t peripid3; /* 0xfec */
  64. uint32_t pcellid0; /* 0xff0 */
  65. uint32_t pcellid1; /* 0xff4 */
  66. uint32_t pcellid2; /* 0xff8 */
  67. uint32_t pcellid3; /* 0xffc */
  68. };
  69. #define FSMC_BUSY_WAIT_TIMEOUT (1 * HZ)
  70. /* pc register definitions */
  71. #define FSMC_RESET (1 << 0)
  72. #define FSMC_WAITON (1 << 1)
  73. #define FSMC_ENABLE (1 << 2)
  74. #define FSMC_DEVTYPE_NAND (1 << 3)
  75. #define FSMC_DEVWID_8 (0 << 4)
  76. #define FSMC_DEVWID_16 (1 << 4)
  77. #define FSMC_ECCEN (1 << 6)
  78. #define FSMC_ECCPLEN_512 (0 << 7)
  79. #define FSMC_ECCPLEN_256 (1 << 7)
  80. #define FSMC_TCLR_1 (1)
  81. #define FSMC_TCLR_SHIFT (9)
  82. #define FSMC_TCLR_MASK (0xF)
  83. #define FSMC_TAR_1 (1)
  84. #define FSMC_TAR_SHIFT (13)
  85. #define FSMC_TAR_MASK (0xF)
  86. /* sts register definitions */
  87. #define FSMC_CODE_RDY (1 << 15)
  88. /* comm register definitions */
  89. #define FSMC_TSET_0 0
  90. #define FSMC_TSET_SHIFT 0
  91. #define FSMC_TSET_MASK 0xFF
  92. #define FSMC_TWAIT_6 6
  93. #define FSMC_TWAIT_SHIFT 8
  94. #define FSMC_TWAIT_MASK 0xFF
  95. #define FSMC_THOLD_4 4
  96. #define FSMC_THOLD_SHIFT 16
  97. #define FSMC_THOLD_MASK 0xFF
  98. #define FSMC_THIZ_1 1
  99. #define FSMC_THIZ_SHIFT 24
  100. #define FSMC_THIZ_MASK 0xFF
  101. /*
  102. * There are 13 bytes of ecc for every 512 byte block in FSMC version 8
  103. * and it has to be read consecutively and immediately after the 512
  104. * byte data block for hardware to generate the error bit offsets
  105. * Managing the ecc bytes in the following way is easier. This way is
  106. * similar to oobfree structure maintained already in u-boot nand driver
  107. */
  108. #define MAX_ECCPLACE_ENTRIES 32
  109. struct fsmc_nand_eccplace {
  110. uint8_t offset;
  111. uint8_t length;
  112. };
  113. struct fsmc_eccplace {
  114. struct fsmc_nand_eccplace eccplace[MAX_ECCPLACE_ENTRIES];
  115. };
  116. struct fsmc_nand_timings {
  117. uint8_t tclr;
  118. uint8_t tar;
  119. uint8_t thiz;
  120. uint8_t thold;
  121. uint8_t twait;
  122. uint8_t tset;
  123. };
  124. enum access_mode {
  125. USE_DMA_ACCESS = 1,
  126. USE_WORD_ACCESS,
  127. };
  128. /**
  129. * fsmc_nand_platform_data - platform specific NAND controller config
  130. * @partitions: partition table for the platform, use a default fallback
  131. * if this is NULL
  132. * @nr_partitions: the number of partitions in the previous entry
  133. * @options: different options for the driver
  134. * @width: bus width
  135. * @bank: default bank
  136. * @select_bank: callback to select a certain bank, this is
  137. * platform-specific. If the controller only supports one bank
  138. * this may be set to NULL
  139. */
  140. struct fsmc_nand_platform_data {
  141. struct fsmc_nand_timings *nand_timings;
  142. struct mtd_partition *partitions;
  143. unsigned int nr_partitions;
  144. unsigned int options;
  145. unsigned int width;
  146. unsigned int bank;
  147. /* CLE, ALE offsets */
  148. unsigned long cle_off;
  149. unsigned long ale_off;
  150. enum access_mode mode;
  151. void (*select_bank)(uint32_t bank, uint32_t busw);
  152. };
  153. extern int __init fsmc_nor_init(struct platform_device *pdev,
  154. unsigned long base, uint32_t bank, uint32_t width);
  155. extern void __init fsmc_init_board_info(struct platform_device *pdev,
  156. struct mtd_partition *partitions, unsigned int nr_partitions,
  157. unsigned int width);
  158. #endif /* __MTD_FSMC_H */