ftide020.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * Faraday FTIDE020_s ATA Controller (AHB)
  3. *
  4. * (C) Copyright 2011 Andes Technology
  5. * Greentime Hu <greentime@andestech.com>
  6. * Macpaul Lin <macpaul@andestech.com>
  7. * Kuo-Wei Chou <kwchou@andestech.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. */
  28. #ifndef __FTIDE020_H
  29. #define __FTIDE020_H
  30. /* ftide020.h - ide support functions for the FTIDE020_S controller */
  31. /* ATA controller register offset */
  32. struct ftide020_s {
  33. unsigned int rw_fifo; /* 0x00 - READ/WRITE FIFO */
  34. unsigned int cmd_fifo; /* 0x04 - R: Status Reg, W: CMD_FIFO */
  35. unsigned int cr; /* 0x08 - Control Reg */
  36. unsigned int dmatirr; /* 0x0c - DMA Threshold/Interrupt Reg */
  37. unsigned int ctrd0; /* 0x10 - Command Timing Reg Device 0 */
  38. unsigned int dtrd0; /* 0x14 - Data Timing Reg Device 0 */
  39. unsigned int ctrd1; /* 0x18 - Command Timing Reg Device 1 */
  40. unsigned int dtrd1; /* 0x1c - Data Timing Reg Device 1 */
  41. unsigned int ahbtr; /* 0x20 - AHB Timeout Reg */
  42. unsigned int RESVD0; /* 0x24 */
  43. unsigned int RESVD1; /* 0x28 */
  44. unsigned int RESVD2; /* 0x2c */
  45. unsigned int f_cfifo; /* 0x30 - Feature Info of CMD_FIFO */
  46. unsigned int f_wfifo; /* 0x34 - Feature Info of WRITE_FIFO */
  47. unsigned int f_rfifo; /* 0x3c - Feature Info of READ_FIFO */
  48. unsigned int revision; /* 0x38 - Revision No. of FTIDE020_S */
  49. };
  50. /* reference parameters */
  51. #define CONFIG_IDE_REG_CS 0x2 /* ref: ATA spec chaper 10, table 42 */
  52. #define CONFIG_CTRD1_PROBE_T1 0x2
  53. #define CONFIG_CTRD1_PROBE_T2 0x5
  54. /* status register - 0x04 */
  55. #define STATUS_CSEL (1 << 0) /* CSEL */
  56. #define STATUS_CS(x) (((x) >> 1) & 0x3) /* CS#[1:0] */
  57. #define STATUS_DMACK (1 << 3) /* DMACK# */
  58. #define STATUS_DMARQ (1 << 4) /* DMA req */
  59. #define STATUS_INTRQ (1 << 5) /* INT req */
  60. #define STATUS_DIOR (1 << 6) /* DIOR */
  61. #define STATUS_IORDY (1 << 7) /* I/O ready */
  62. #define STATUS_DIOW (1 << 8) /* DIOW# */
  63. #define STATUS_PDIAG (1 << 9) /* PDIAG */
  64. #define STATUS_DASP (1 << 10) /* DASP# */
  65. #define STATUS_DEV (1 << 11) /* selected device */
  66. #define STATUS_PIO (1 << 12) /* PIO in progress */
  67. #define STATUS_DMA (1 << 13) /* DMA in progress */
  68. #define STATUS_WFE (1 << 14) /* write fifo full */
  69. #define STATUS_RFE (1 << 15) /* read fifo empty */
  70. #define STATUS_COUNTER(x) (((x) >> 16) & 0x3fff) /* data tx counter */
  71. #define STATUS_ERR (1 << 30) /* trasfer terminated */
  72. #define STATUS_AER (1 << 31) /* AHB timeout indicate */
  73. /* Control register - 0x08 */
  74. #define CONTROL_TYPE_PIO 0x0
  75. #define CONTROL_TYPE_UDMA 0x1
  76. /* Device 0 */
  77. #define CONTROL_TYP0(x) (((x) & 0x7) << 0)
  78. #define CONTROL_IRE0 (1 << 3) /* enable IORDY for PIO */
  79. #define CONTROL_RESVD_DW0 (1 << 4) /* Reserved - DW0 ? */
  80. #define CONTROL_E0 (1 << 5) /* E0: 1: Big Endian */
  81. #define CONTROL_RESVD_WP0 (1 << 6) /* Reserved - WP0 ? */
  82. #define CONTROL_RESVD_SE0 (1 << 7) /* Reserved - SE0 ? */
  83. #define CONTROL_RESVD_ECC0 (1 << 8) /* Reserved - ECC0 ? */
  84. #define CONTROL_RAEIE (1 << 9) /* IRQ - read fifo almost full */
  85. #define CONTROL_RNEIE (1 << 10) /* IRQ - read fifo not empty */
  86. #define CONTROL_WAFIE (1 << 11) /* IRQ - write fifo almost empty */
  87. #define CONTROL_WNFIE (1 << 12) /* IRQ - write fifo not full */
  88. #define CONTROL_RESVD_FIRQ (1 << 13) /* RESERVED - FIRQ ? */
  89. #define CONTROL_AERIE (1 << 14) /* IRQ - AHB timeout error */
  90. #define CONTROL_IIE (1 << 15) /* IDE IRQ enable */
  91. /* Device 1 */
  92. #define CONTROL_TYP1(x) (((x) & 0x7) << 16)
  93. #define CONTROL_IRE1 (1 << 19) /* enable IORDY for PIO */
  94. #define CONTROL_RESVD_DW1 (1 << 20) /* Reserved - DW1 ? */
  95. #define CONTROL_E1 (1 << 21) /* E1: 1: Big Endian */
  96. #define CONTROL_RESVD_WP1 (1 << 22) /* Reserved - WP1 ? */
  97. #define CONTROL_RESVD_SE1 (1 << 23) /* Reserved - SE1 ? */
  98. #define CONTROL_RESVD_ECC1 (1 << 24) /* Reserved - ECC1 ? */
  99. #define CONTROL_DRE (1 << 25) /* DMA receive enable */
  100. #define CONTROL_DTE (1 << 26) /* DMA transmit enable */
  101. #define CONTRIL_RESVD (1 << 27)
  102. #define CONTROL_TERIE (1 << 28) /* transfer terminate error IRQ */
  103. #define CONTROL_T (1 << 29) /* terminate current operation */
  104. #define CONTROL_SRST (1 << 30) /* IDE soft reset */
  105. #define CONTROL_RST (1 << 31) /* IDE hardware reset */
  106. /* IRQ register - 0x0c */
  107. #define IRQ_RXTHRESH(x) (((x) & 0x3ff) << 0) /* Read FIFO threshold */
  108. #define IRQ_RFAEIRQ (1 << 10) /* Read FIFO almost full intr req */
  109. #define IRQ_RFNEIRQ (1 << 11) /* Read FIFO not empty intr req */
  110. #define IRQ_WFAFIRQ (1 << 12) /* Write FIFO almost empty int req */
  111. #define IRQ_WFNFIRQ (1 << 13) /* Write FIFO not full intr req */
  112. #define IRQ_RESVD_FIRQ (1 << 14) /* Reserved - FIRQ ? */
  113. #define IRQ_IIRQ (1 << 15) /* IDE device interrupt request */
  114. #define IRQ_TXTHRESH(x) (((x) & 0x3ff) << 16) /* Write FIFO thershold */
  115. #define IRQ_TERMERR (1 << 28) /* Transfer termination indication */
  116. #define IRQ_AHBERR (1 << 29) /* AHB Timeout indication */
  117. /* Command Timing Register 0-1: ctrd (0x10, 0x18) */
  118. #define CT_REG_T1(x) (((x) & 0xff) << 0) /* setup time of addressed */
  119. #define CT_REG_T2(x) (((x) & 0xff) << 8) /* pluse width of DIOR/DIOW */
  120. #define CT_REG_T4(x) (((x) & 0xff) << 16) /* data hold time */
  121. #define CT_REG_TEOC(x) (((x) & 0xff) << 24) /* time to the end of a cycle */
  122. /* Data Timing Register 0-1: dtrd (0x14, 0x1c) */
  123. /*
  124. * PIO mode:
  125. * b(0:7) DT_REG_PIO_T1: the setup time of addressed
  126. * b(8:15) DT_REG_PIO_T2: the pluse width of DIOR/DIOW
  127. * b(16:23) DT_REG_PIO_T4: data hold time
  128. * b(24:31) DT_REG_PIO_TEOC: the time to the end of a cycle
  129. */
  130. #define DT_REG_PIO_T1(x) (((x) & 0xff) << 0)
  131. #define DT_REG_PIO_T2(x) (((x) & 0xff) << 8)
  132. #define DT_REG_PIO_T4(x) (((x) & 0xff) << 16)
  133. #define DT_REG_PIO_TEOC(x) (((x) & 0xff) << 24)
  134. /*
  135. * UDMA mode:
  136. * b(0:3) DT_REG_UDMA_TENV: the envelope time
  137. * b(4:7) DT_REG_UDMA_TMLI: interlock time
  138. * b(8:15) DT_REG_UDMA_TCYC: cycle time - data time
  139. * b(16:19) DT_REG_UDMA_TACK: setup and hold time of DMACK
  140. * b(23:30) DT_REG_UDMA_TCVS: setup time of CRC
  141. * b(24:31) DT_REG_UDMA_TRP: time to ready to pause
  142. */
  143. #define DT_REG_UDMA_TENV(x) (((x) & 0xf) << 0)
  144. #define DT_REG_UDMA_TMLI(x) (((x) & 0xf) << 4)
  145. #define DT_REG_UDMA_TCYC(x) (((x) & 0xff) << 8)
  146. #define DT_REG_UDMA_TACK(x) (((x) & 0xf) << 16)
  147. #define DT_REG_UDMA_TCVS(x) (((x) & 0xf) << 20)
  148. #define DT_REG_UDMA_TRP(x) (((x) & 0xff) << 24)
  149. /* ftide020_s command formats */
  150. /* read: IDE Register (CF1) */
  151. #define IDE_REG_OPCODE_READ (1 << 13) /* 0x2000 */
  152. #define IDE_REG_CS_READ(x) (((x) & 0x3) << 11)
  153. #define IDE_REG_DA_READ(x) (((x) & 0x7) << 8)
  154. #define IDE_REG_CMD_READ(x) 0x0 /* fixed value */
  155. /* write: IDE Register (CF2) */
  156. #define IDE_REG_OPCODE_WRITE (0x5 << 13) /* 0xA000 */
  157. #define IDE_REG_CS_WRITE(x) (((x) & 0x3) << 11)
  158. #define IDE_REG_DA_WRITE(x) (((x) & 0x7) << 8)
  159. /* b(0:7) IDE_REG_CMD_WRITE(x): Actual ATA command or data */
  160. #define IDE_REG_CMD_WRITE(x) (((x) & 0xff) << 0)
  161. /* read/write data: PIO/UDMA (CF3) */
  162. #define IDE_DATA_WRITE (1 << 15) /* read: 0, write: 1 */
  163. #define IDE_DATA_OPCODE (0x2 << 13) /* device data access opcode */
  164. /* b(0:12) IDE_DATA_COUNTER(x): Number of transfers minus 1 */
  165. #define IDE_DATA_COUNTER(x) (((x) & 0x1fff) << 0)
  166. /* set device: (CF4) */
  167. #define IDE_SET_OPCODE (0x2740 << 2) /* [15:2], 0x9d00 */
  168. /* CF3 counter value: 0: Tx in bytes, 1: in blocks (each block is 8 bytes) */
  169. #define IDE_SET_CX8(x) (((x) & 0x1) << 1)
  170. #define IDE_SET_DEV(x) (((x) & 0x1) << 0) /* 0: Master, 1: Slave */
  171. /*
  172. * IDE command bit definition
  173. * This section is designed for minor hardware revision compatibility.
  174. */
  175. #define READ_REG_CMD IDE_REG_OPCODE_READ /* 0x2000 */
  176. #define WRITE_REG_CMD IDE_REG_OPCODE_WRITE /* 0xA000 */
  177. #define READ_DATA_CMD IDE_DATA_OPCODE /* 0x4000 */
  178. #define WRITE_DATA_CMD (IDE_DATA_OPCODE | IDE_DATA_WRITE) /* 0xC000 */
  179. #define SET_DEV_CMD IDE_SET_OPCODE /* 0x9D00 */
  180. #define TATOL_TIMING 3
  181. #define CMD_TIMING 0
  182. #define PIO_TIMING 1
  183. #define DMA_TIMING 2
  184. /* Timing Parameters */
  185. /* Register Access Timing Parameters */
  186. #define REG_PARAMETER 4
  187. #define REG_T0 0
  188. #define REG_T1 1
  189. #define REG_T2 2
  190. #define REG_T4 3
  191. #define REG_MODE 5
  192. #define REG_MODE0 0
  193. #define REG_MODE1 1
  194. #define REG_MODE2 2
  195. #define REG_MODE3 3
  196. #define REG_MODE4 4
  197. /* PIO Access Timing Parameters */
  198. #define PIO_PARAMETER 4
  199. #define PIO_T0 0
  200. #define PIO_T1 1
  201. #define PIO_T2 2
  202. #define PIO_T4 3
  203. #define PIO_MODE 5
  204. #define PIO_MODE0 0
  205. #define PIO_MODE1 1
  206. #define PIO_MODE2 2
  207. #define PIO_MODE3 3
  208. #define PIO_MODE4 4
  209. /* UDMA Access Timing Parameters */
  210. #define UDMA_PARAMETER 6
  211. #define UDMA_TCYC 0
  212. #define UDMA_TCVS 1
  213. #define UDMA_TMLI 2
  214. #define UDMA_TENV 3
  215. #define UDMA_TRP 4
  216. #define UDMA_TACK 5
  217. #define UDMA_MODE 7
  218. #define UDMA_MODE0 0
  219. #define UDMA_MODE1 1
  220. #define UDMA_MODE2 2
  221. #define UDMA_MODE3 3
  222. #define UDMA_MODE4 4
  223. #define UDMA_MODE5 5
  224. #define UDMA_MODE6 6
  225. /*
  226. * RX_THRESH:
  227. * hardware limitation: max = 8, should support 1,4,8,16,32,64,128,256
  228. */
  229. #define RX_THRESH 8
  230. #define WRITE_FIFO 32 /* Hardwired value */
  231. /* Time Table */
  232. unsigned int REG_ACCESS_TIMING[REG_PARAMETER][REG_MODE] = {
  233. {600, 383, 330, 180, 120},
  234. {70, 50, 30, 30, 25},
  235. {290, 290, 290, 80, 70},
  236. {30, 20, 15, 10, 10},
  237. };
  238. unsigned int PIO_ACCESS_TIMING[PIO_PARAMETER][PIO_MODE] = {
  239. {600, 383, 240, 180, 120},
  240. {70, 50, 30, 30, 25},
  241. {165, 125, 100, 80, 70},
  242. {30, 20, 15, 10, 10},
  243. };
  244. unsigned int UDMA_ACCESS_TIMING[UDMA_PARAMETER][UDMA_MODE] = {
  245. {1120, 730, 540, 390, 250, 168, 130}, /* 10X */
  246. {700, 480, 310, 200, 67, 100, 100}, /* 10X */
  247. {200, 200, 200, 200, 200, 200, 200}, /* 10X */
  248. {200, 200, 200, 200, 200, 200, 200}, /* 10X */
  249. {1600, 1250, 1000, 1000, 1000, 850, 850}, /* 10X */
  250. {200, 200, 200, 200, 200, 200, 200}, /* 10X */
  251. };
  252. #endif /* __FTIDE020_H */