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