sh_flctl.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * SuperH FLCTL nand controller
  3. *
  4. * Copyright © 2008 Renesas Solutions Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef __SH_FLCTL_H__
  20. #define __SH_FLCTL_H__
  21. #include <linux/completion.h>
  22. #include <linux/mtd/mtd.h>
  23. #include <linux/mtd/nand.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <linux/pm_qos.h>
  26. /* FLCTL registers */
  27. #define FLCMNCR(f) (f->reg + 0x0)
  28. #define FLCMDCR(f) (f->reg + 0x4)
  29. #define FLCMCDR(f) (f->reg + 0x8)
  30. #define FLADR(f) (f->reg + 0xC)
  31. #define FLADR2(f) (f->reg + 0x3C)
  32. #define FLDATAR(f) (f->reg + 0x10)
  33. #define FLDTCNTR(f) (f->reg + 0x14)
  34. #define FLINTDMACR(f) (f->reg + 0x18)
  35. #define FLBSYTMR(f) (f->reg + 0x1C)
  36. #define FLBSYCNT(f) (f->reg + 0x20)
  37. #define FLDTFIFO(f) (f->reg + 0x24)
  38. #define FLECFIFO(f) (f->reg + 0x28)
  39. #define FLTRCR(f) (f->reg + 0x2C)
  40. #define FLHOLDCR(f) (f->reg + 0x38)
  41. #define FL4ECCRESULT0(f) (f->reg + 0x80)
  42. #define FL4ECCRESULT1(f) (f->reg + 0x84)
  43. #define FL4ECCRESULT2(f) (f->reg + 0x88)
  44. #define FL4ECCRESULT3(f) (f->reg + 0x8C)
  45. #define FL4ECCCR(f) (f->reg + 0x90)
  46. #define FL4ECCCNT(f) (f->reg + 0x94)
  47. #define FLERRADR(f) (f->reg + 0x98)
  48. /* FLCMNCR control bits */
  49. #define _4ECCCNTEN (0x1 << 24)
  50. #define _4ECCEN (0x1 << 23)
  51. #define _4ECCCORRECT (0x1 << 22)
  52. #define SHBUSSEL (0x1 << 20)
  53. #define SEL_16BIT (0x1 << 19)
  54. #define SNAND_E (0x1 << 18) /* SNAND (0=512 1=2048)*/
  55. #define QTSEL_E (0x1 << 17)
  56. #define ENDIAN (0x1 << 16) /* 1 = little endian */
  57. #define FCKSEL_E (0x1 << 15)
  58. #define ACM_SACCES_MODE (0x01 << 10)
  59. #define NANWF_E (0x1 << 9)
  60. #define SE_D (0x1 << 8) /* Spare area disable */
  61. #define CE1_ENABLE (0x1 << 4) /* Chip Enable 1 */
  62. #define CE0_ENABLE (0x1 << 3) /* Chip Enable 0 */
  63. #define TYPESEL_SET (0x1 << 0)
  64. /*
  65. * Clock settings using the PULSEx registers from FLCMNCR
  66. *
  67. * Some hardware uses bits called PULSEx instead of FCKSEL_E and QTSEL_E
  68. * to control the clock divider used between the High-Speed Peripheral Clock
  69. * and the FLCTL internal clock. If so, use CLK_8_BIT_xxx for connecting 8 bit
  70. * and CLK_16_BIT_xxx for connecting 16 bit bus bandwith NAND chips. For the 16
  71. * bit version the divider is seperate for the pulse width of high and low
  72. * signals.
  73. */
  74. #define PULSE3 (0x1 << 27)
  75. #define PULSE2 (0x1 << 17)
  76. #define PULSE1 (0x1 << 15)
  77. #define PULSE0 (0x1 << 9)
  78. #define CLK_8B_0_5 PULSE1
  79. #define CLK_8B_1 0x0
  80. #define CLK_8B_1_5 (PULSE1 | PULSE2)
  81. #define CLK_8B_2 PULSE0
  82. #define CLK_8B_3 (PULSE0 | PULSE1 | PULSE2)
  83. #define CLK_8B_4 (PULSE0 | PULSE2)
  84. #define CLK_16B_6L_2H PULSE0
  85. #define CLK_16B_9L_3H (PULSE0 | PULSE1 | PULSE2)
  86. #define CLK_16B_12L_4H (PULSE0 | PULSE2)
  87. /* FLCMDCR control bits */
  88. #define ADRCNT2_E (0x1 << 31) /* 5byte address enable */
  89. #define ADRMD_E (0x1 << 26) /* Sector address access */
  90. #define CDSRC_E (0x1 << 25) /* Data buffer selection */
  91. #define DOSR_E (0x1 << 24) /* Status read check */
  92. #define SELRW (0x1 << 21) /* 0:read 1:write */
  93. #define DOADR_E (0x1 << 20) /* Address stage execute */
  94. #define ADRCNT_1 (0x00 << 18) /* Address data bytes: 1byte */
  95. #define ADRCNT_2 (0x01 << 18) /* Address data bytes: 2byte */
  96. #define ADRCNT_3 (0x02 << 18) /* Address data bytes: 3byte */
  97. #define ADRCNT_4 (0x03 << 18) /* Address data bytes: 4byte */
  98. #define DOCMD2_E (0x1 << 17) /* 2nd cmd stage execute */
  99. #define DOCMD1_E (0x1 << 16) /* 1st cmd stage execute */
  100. /* FLINTDMACR control bits */
  101. #define ESTERINTE (0x1 << 24) /* ECC error interrupt enable */
  102. #define AC1CLR (0x1 << 19) /* ECC FIFO clear */
  103. #define AC0CLR (0x1 << 18) /* Data FIFO clear */
  104. #define DREQ0EN (0x1 << 16) /* FLDTFIFODMA Request Enable */
  105. #define ECERB (0x1 << 9) /* ECC error */
  106. #define STERB (0x1 << 8) /* Status error */
  107. #define STERINTE (0x1 << 4) /* Status error enable */
  108. /* FLTRCR control bits */
  109. #define TRSTRT (0x1 << 0) /* translation start */
  110. #define TREND (0x1 << 1) /* translation end */
  111. /*
  112. * FLHOLDCR control bits
  113. *
  114. * HOLDEN: Bus Occupancy Enable (inverted)
  115. * Enable this bit when the external bus might be used in between transfers.
  116. * If not set and the bus gets used by other modules, a deadlock occurs.
  117. */
  118. #define HOLDEN (0x1 << 0)
  119. /* FL4ECCCR control bits */
  120. #define _4ECCFA (0x1 << 2) /* 4 symbols correct fault */
  121. #define _4ECCEND (0x1 << 1) /* 4 symbols end */
  122. #define _4ECCEXST (0x1 << 0) /* 4 symbols exist */
  123. #define LOOP_TIMEOUT_MAX 0x00010000
  124. enum flctl_ecc_res_t {
  125. FL_SUCCESS,
  126. FL_REPAIRABLE,
  127. FL_ERROR,
  128. FL_TIMEOUT
  129. };
  130. struct dma_chan;
  131. struct sh_flctl {
  132. struct nand_chip chip;
  133. struct platform_device *pdev;
  134. struct dev_pm_qos_request pm_qos;
  135. void __iomem *reg;
  136. resource_size_t fifo;
  137. uint8_t done_buff[2048 + 64]; /* max size 2048 + 64 */
  138. int read_bytes;
  139. unsigned int index;
  140. int seqin_column; /* column in SEQIN cmd */
  141. int seqin_page_addr; /* page_addr in SEQIN cmd */
  142. uint32_t seqin_read_cmd; /* read cmd in SEQIN cmd */
  143. int erase1_page_addr; /* page_addr in ERASE1 cmd */
  144. uint32_t erase_ADRCNT; /* bits of FLCMDCR in ERASE1 cmd */
  145. uint32_t rw_ADRCNT; /* bits of FLCMDCR in READ WRITE cmd */
  146. uint32_t flcmncr_base; /* base value of FLCMNCR */
  147. uint32_t flintdmacr_base; /* irq enable bits */
  148. unsigned page_size:1; /* NAND page size (0 = 512, 1 = 2048) */
  149. unsigned hwecc:1; /* Hardware ECC (0 = disabled, 1 = enabled) */
  150. unsigned holden:1; /* Hardware has FLHOLDCR and HOLDEN is set */
  151. unsigned qos_request:1; /* QoS request to prevent deep power shutdown */
  152. /* DMA related objects */
  153. struct dma_chan *chan_fifo0_rx;
  154. struct dma_chan *chan_fifo0_tx;
  155. struct completion dma_complete;
  156. };
  157. struct sh_flctl_platform_data {
  158. struct mtd_partition *parts;
  159. int nr_parts;
  160. unsigned long flcmncr_val;
  161. unsigned has_hwecc:1;
  162. unsigned use_holden:1;
  163. unsigned int slave_id_fifo0_tx;
  164. unsigned int slave_id_fifo0_rx;
  165. };
  166. static inline struct sh_flctl *mtd_to_flctl(struct mtd_info *mtdinfo)
  167. {
  168. return container_of(mtd_to_nand(mtdinfo), struct sh_flctl, chip);
  169. }
  170. #endif /* __SH_FLCTL_H__ */