fsmc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. /*
  26. * The placement of the Command Latch Enable (CLE) and
  27. * Address Latch Enable (ALE) is twisted around in the
  28. * SPEAR310 implementation.
  29. */
  30. #if defined(CONFIG_MACH_SPEAR310)
  31. #define PLAT_NAND_CLE (1 << 17)
  32. #define PLAT_NAND_ALE (1 << 16)
  33. #else
  34. #define PLAT_NAND_CLE (1 << 16)
  35. #define PLAT_NAND_ALE (1 << 17)
  36. #endif
  37. #define FSMC_MAX_NOR_BANKS 4
  38. #define FSMC_MAX_NAND_BANKS 4
  39. #define FSMC_FLASH_WIDTH8 1
  40. #define FSMC_FLASH_WIDTH16 2
  41. struct fsmc_nor_bank_regs {
  42. uint32_t ctrl;
  43. uint32_t ctrl_tim;
  44. };
  45. /* ctrl register definitions */
  46. #define BANK_ENABLE (1 << 0)
  47. #define MUXED (1 << 1)
  48. #define NOR_DEV (2 << 2)
  49. #define WIDTH_8 (0 << 4)
  50. #define WIDTH_16 (1 << 4)
  51. #define RSTPWRDWN (1 << 6)
  52. #define WPROT (1 << 7)
  53. #define WRT_ENABLE (1 << 12)
  54. #define WAIT_ENB (1 << 13)
  55. /* ctrl_tim register definitions */
  56. struct fsmc_nand_bank_regs {
  57. uint32_t pc;
  58. uint32_t sts;
  59. uint32_t comm;
  60. uint32_t attrib;
  61. uint32_t ioata;
  62. uint32_t ecc1;
  63. uint32_t ecc2;
  64. uint32_t ecc3;
  65. };
  66. #define FSMC_NOR_REG_SIZE 0x40
  67. struct fsmc_regs {
  68. struct fsmc_nor_bank_regs nor_bank_regs[FSMC_MAX_NOR_BANKS];
  69. uint8_t reserved_1[0x40 - 0x20];
  70. struct fsmc_nand_bank_regs bank_regs[FSMC_MAX_NAND_BANKS];
  71. uint8_t reserved_2[0xfe0 - 0xc0];
  72. uint32_t peripid0; /* 0xfe0 */
  73. uint32_t peripid1; /* 0xfe4 */
  74. uint32_t peripid2; /* 0xfe8 */
  75. uint32_t peripid3; /* 0xfec */
  76. uint32_t pcellid0; /* 0xff0 */
  77. uint32_t pcellid1; /* 0xff4 */
  78. uint32_t pcellid2; /* 0xff8 */
  79. uint32_t pcellid3; /* 0xffc */
  80. };
  81. #define FSMC_BUSY_WAIT_TIMEOUT (1 * HZ)
  82. /* pc register definitions */
  83. #define FSMC_RESET (1 << 0)
  84. #define FSMC_WAITON (1 << 1)
  85. #define FSMC_ENABLE (1 << 2)
  86. #define FSMC_DEVTYPE_NAND (1 << 3)
  87. #define FSMC_DEVWID_8 (0 << 4)
  88. #define FSMC_DEVWID_16 (1 << 4)
  89. #define FSMC_ECCEN (1 << 6)
  90. #define FSMC_ECCPLEN_512 (0 << 7)
  91. #define FSMC_ECCPLEN_256 (1 << 7)
  92. #define FSMC_TCLR_1 (1 << 9)
  93. #define FSMC_TAR_1 (1 << 13)
  94. /* sts register definitions */
  95. #define FSMC_CODE_RDY (1 << 15)
  96. /* comm register definitions */
  97. #define FSMC_TSET_0 (0 << 0)
  98. #define FSMC_TWAIT_6 (6 << 8)
  99. #define FSMC_THOLD_4 (4 << 16)
  100. #define FSMC_THIZ_1 (1 << 24)
  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. /**
  117. * fsmc_nand_platform_data - platform specific NAND controller config
  118. * @partitions: partition table for the platform, use a default fallback
  119. * if this is NULL
  120. * @nr_partitions: the number of partitions in the previous entry
  121. * @options: different options for the driver
  122. * @width: bus width
  123. * @bank: default bank
  124. * @select_bank: callback to select a certain bank, this is
  125. * platform-specific. If the controller only supports one bank
  126. * this may be set to NULL
  127. */
  128. struct fsmc_nand_platform_data {
  129. struct mtd_partition *partitions;
  130. unsigned int nr_partitions;
  131. unsigned int options;
  132. unsigned int width;
  133. unsigned int bank;
  134. void (*select_bank)(uint32_t bank, uint32_t busw);
  135. };
  136. extern int __init fsmc_nor_init(struct platform_device *pdev,
  137. unsigned long base, uint32_t bank, uint32_t width);
  138. extern void __init fsmc_init_board_info(struct platform_device *pdev,
  139. struct mtd_partition *partitions, unsigned int nr_partitions,
  140. unsigned int width);
  141. #endif /* __MTD_FSMC_H */