sh_flctl.h 5.8 KB

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