wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Most of the following information was derived from the document |
| 26 | * "Information Technology - AT Attachment-3 Interface (ATA-3)" |
| 27 | * which can be found at: |
| 28 | * http://www.dt.wdc.com/ata/ata-3/ata3r5v.zip |
| 29 | * ftp://poctok.iae.nsk.su/pub/asm/Documents/IDE/ATA3R5V.ZIP |
| 30 | * ftp://ftp.fee.vutbr.cz/pub/doc/io/ata/ata-3/ata3r5v.zip |
| 31 | */ |
| 32 | |
| 33 | #ifndef _ATA_H |
| 34 | #define _ATA_H |
| 35 | |
| 36 | /* Register addressing depends on the hardware design; for instance, |
| 37 | * 8-bit (register) and 16-bit (data) accesses might use different |
| 38 | * address spaces. This is implemented by the following definitions. |
| 39 | */ |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 40 | #ifndef CFG_ATA_STRIDE |
| 41 | #define CFG_ATA_STRIDE 1 |
| 42 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 43 | |
wdenk | 9fd5e31 | 2003-12-07 23:55:12 +0000 | [diff] [blame] | 44 | #define ATA_IO_DATA(x) (CFG_ATA_DATA_OFFSET+((x) * CFG_ATA_STRIDE)) |
| 45 | #define ATA_IO_REG(x) (CFG_ATA_REG_OFFSET +((x) * CFG_ATA_STRIDE)) |
| 46 | #define ATA_IO_ALT(x) (CFG_ATA_ALT_OFFSET +((x) * CFG_ATA_STRIDE)) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * I/O Register Descriptions |
| 50 | */ |
| 51 | #define ATA_DATA_REG ATA_IO_DATA(0) |
| 52 | #define ATA_ERROR_REG ATA_IO_REG(1) |
| 53 | #define ATA_SECT_CNT ATA_IO_REG(2) |
| 54 | #define ATA_SECT_NUM ATA_IO_REG(3) |
| 55 | #define ATA_CYL_LOW ATA_IO_REG(4) |
| 56 | #define ATA_CYL_HIGH ATA_IO_REG(5) |
| 57 | #define ATA_DEV_HD ATA_IO_REG(6) |
| 58 | #define ATA_COMMAND ATA_IO_REG(7) |
wdenk | a522fa0 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 59 | #define ATA_DATA_EVEN ATA_IO_REG(8) |
| 60 | #define ATA_DATA_ODD ATA_IO_REG(9) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 61 | #define ATA_STATUS ATA_COMMAND |
| 62 | #define ATA_DEV_CTL ATA_IO_ALT(6) |
| 63 | #define ATA_LBA_LOW ATA_SECT_NUM |
| 64 | #define ATA_LBA_MID ATA_CYL_LOW |
| 65 | #define ATA_LBA_HIGH ATA_CYL_HIGH |
| 66 | #define ATA_LBA_SEL ATA_DEV_CTL |
| 67 | |
| 68 | /* |
| 69 | * Status register bits |
| 70 | */ |
| 71 | #define ATA_STAT_BUSY 0x80 /* Device Busy */ |
| 72 | #define ATA_STAT_READY 0x40 /* Device Ready */ |
| 73 | #define ATA_STAT_FAULT 0x20 /* Device Fault */ |
| 74 | #define ATA_STAT_SEEK 0x10 /* Device Seek Complete */ |
| 75 | #define ATA_STAT_DRQ 0x08 /* Data Request (ready) */ |
| 76 | #define ATA_STAT_CORR 0x04 /* Corrected Data Error */ |
| 77 | #define ATA_STAT_INDEX 0x02 /* Vendor specific */ |
| 78 | #define ATA_STAT_ERR 0x01 /* Error */ |
| 79 | |
| 80 | /* |
| 81 | * Device / Head Register Bits |
| 82 | */ |
| 83 | #define ATA_DEVICE(x) ((x & 1)<<4) |
| 84 | #define ATA_LBA 0xE0 |
| 85 | |
| 86 | /* |
| 87 | * ATA Commands (only mandatory commands listed here) |
| 88 | */ |
| 89 | #define ATA_CMD_READ 0x20 /* Read Sectors (with retries) */ |
| 90 | #define ATA_CMD_READN 0x21 /* Read Sectors ( no retries) */ |
| 91 | #define ATA_CMD_WRITE 0x30 /* Write Sectores (with retries)*/ |
| 92 | #define ATA_CMD_WRITEN 0x31 /* Write Sectors ( no retries)*/ |
| 93 | #define ATA_CMD_VRFY 0x40 /* Read Verify (with retries) */ |
| 94 | #define ATA_CMD_VRFYN 0x41 /* Read verify ( no retries) */ |
| 95 | #define ATA_CMD_SEEK 0x70 /* Seek */ |
| 96 | #define ATA_CMD_DIAG 0x90 /* Execute Device Diagnostic */ |
| 97 | #define ATA_CMD_INIT 0x91 /* Initialize Device Parameters */ |
| 98 | #define ATA_CMD_RD_MULT 0xC4 /* Read Multiple */ |
| 99 | #define ATA_CMD_WR_MULT 0xC5 /* Write Multiple */ |
| 100 | #define ATA_CMD_SETMULT 0xC6 /* Set Multiple Mode */ |
| 101 | #define ATA_CMD_RD_DMA 0xC8 /* Read DMA (with retries) */ |
| 102 | #define ATA_CMD_RD_DMAN 0xC9 /* Read DMS ( no retries) */ |
| 103 | #define ATA_CMD_WR_DMA 0xCA /* Write DMA (with retries) */ |
| 104 | #define ATA_CMD_WR_DMAN 0xCB /* Write DMA ( no retires) */ |
| 105 | #define ATA_CMD_IDENT 0xEC /* Identify Device */ |
| 106 | #define ATA_CMD_SETF 0xEF /* Set Features */ |
| 107 | #define ATA_CMD_CHK_PWR 0xE5 /* Check Power Mode */ |
| 108 | |
| 109 | /* |
| 110 | * ATAPI Commands |
| 111 | */ |
| 112 | #define ATAPI_CMD_IDENT 0xA1 /* Identify AT Atachment Packed Interface Device */ |
| 113 | #define ATAPI_CMD_PACKET 0xA0 /* Packed Command */ |
| 114 | |
| 115 | |
| 116 | #define ATAPI_CMD_INQUIRY 0x12 |
| 117 | #define ATAPI_CMD_REQ_SENSE 0x03 |
| 118 | #define ATAPI_CMD_READ_CAP 0x25 |
| 119 | #define ATAPI_CMD_START_STOP 0x1B |
| 120 | #define ATAPI_CMD_READ_12 0xA8 |
| 121 | |
| 122 | |
| 123 | #define ATA_GET_ERR() inb(ATA_STATUS) |
| 124 | #define ATA_GET_STAT() inb(ATA_STATUS) |
| 125 | #define ATA_OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good)) |
| 126 | #define ATA_BAD_R_STAT (ATA_STAT_BUSY | ATA_STAT_ERR) |
| 127 | #define ATA_BAD_W_STAT (ATA_BAD_R_STAT | ATA_STAT_FAULT) |
| 128 | #define ATA_BAD_STAT (ATA_BAD_R_STAT | ATA_STAT_DRQ) |
| 129 | #define ATA_DRIVE_READY (ATA_READY_STAT | ATA_STAT_SEEK) |
| 130 | #define ATA_DATA_READY (ATA_STAT_DRQ) |
| 131 | |
| 132 | #define ATA_BLOCKSIZE 512 /* bytes */ |
| 133 | #define ATA_BLOCKSHIFT 9 /* 2 ^ ATA_BLOCKSIZESHIFT = 512 */ |
| 134 | #define ATA_SECTORWORDS (512 / sizeof(unsigned long)) |
| 135 | |
| 136 | #ifndef ATA_RESET_TIME |
| 137 | #define ATA_RESET_TIME 60 /* spec allows up to 31 seconds */ |
| 138 | #endif |
| 139 | |
| 140 | /* ------------------------------------------------------------------------- */ |
| 141 | |
| 142 | /* |
| 143 | * structure returned by ATA_CMD_IDENT, as per ANSI ATA2 rev.2f spec |
| 144 | */ |
| 145 | typedef struct hd_driveid { |
| 146 | unsigned short config; /* lots of obsolete bit flags */ |
| 147 | unsigned short cyls; /* "physical" cyls */ |
| 148 | unsigned short reserved2; /* reserved (word 2) */ |
| 149 | unsigned short heads; /* "physical" heads */ |
| 150 | unsigned short track_bytes; /* unformatted bytes per track */ |
| 151 | unsigned short sector_bytes; /* unformatted bytes per sector */ |
| 152 | unsigned short sectors; /* "physical" sectors per track */ |
| 153 | unsigned short vendor0; /* vendor unique */ |
| 154 | unsigned short vendor1; /* vendor unique */ |
| 155 | unsigned short vendor2; /* vendor unique */ |
| 156 | unsigned char serial_no[20]; /* 0 = not_specified */ |
| 157 | unsigned short buf_type; |
| 158 | unsigned short buf_size; /* 512 byte increments; 0 = not_specified */ |
| 159 | unsigned short ecc_bytes; /* for r/w long cmds; 0 = not_specified */ |
| 160 | unsigned char fw_rev[8]; /* 0 = not_specified */ |
| 161 | unsigned char model[40]; /* 0 = not_specified */ |
| 162 | unsigned char max_multsect; /* 0=not_implemented */ |
| 163 | unsigned char vendor3; /* vendor unique */ |
| 164 | unsigned short dword_io; /* 0=not_implemented; 1=implemented */ |
| 165 | unsigned char vendor4; /* vendor unique */ |
| 166 | unsigned char capability; /* bits 0:DMA 1:LBA 2:IORDYsw 3:IORDYsup*/ |
| 167 | unsigned short reserved50; /* reserved (word 50) */ |
| 168 | unsigned char vendor5; /* vendor unique */ |
| 169 | unsigned char tPIO; /* 0=slow, 1=medium, 2=fast */ |
| 170 | unsigned char vendor6; /* vendor unique */ |
| 171 | unsigned char tDMA; /* 0=slow, 1=medium, 2=fast */ |
| 172 | unsigned short field_valid; /* bits 0:cur_ok 1:eide_ok */ |
| 173 | unsigned short cur_cyls; /* logical cylinders */ |
| 174 | unsigned short cur_heads; /* logical heads */ |
| 175 | unsigned short cur_sectors; /* logical sectors per track */ |
| 176 | unsigned short cur_capacity0; /* logical total sectors on drive */ |
| 177 | unsigned short cur_capacity1; /* (2 words, misaligned int) */ |
| 178 | unsigned char multsect; /* current multiple sector count */ |
| 179 | unsigned char multsect_valid; /* when (bit0==1) multsect is ok */ |
| 180 | unsigned int lba_capacity; /* total number of sectors */ |
| 181 | unsigned short dma_1word; /* single-word dma info */ |
| 182 | unsigned short dma_mword; /* multiple-word dma info */ |
| 183 | unsigned short eide_pio_modes; /* bits 0:mode3 1:mode4 */ |
| 184 | unsigned short eide_dma_min; /* min mword dma cycle time (ns) */ |
| 185 | unsigned short eide_dma_time; /* recommended mword dma cycle time (ns) */ |
| 186 | unsigned short eide_pio; /* min cycle time (ns), no IORDY */ |
| 187 | unsigned short eide_pio_iordy; /* min cycle time (ns), with IORDY */ |
| 188 | unsigned short words69_70[2]; /* reserved words 69-70 */ |
| 189 | unsigned short words71_74[4]; /* reserved words 71-74 */ |
| 190 | unsigned short queue_depth; /* */ |
| 191 | unsigned short words76_79[4]; /* reserved words 76-79 */ |
| 192 | unsigned short major_rev_num; /* */ |
| 193 | unsigned short minor_rev_num; /* */ |
| 194 | unsigned short command_set_1; /* bits 0:Smart 1:Security 2:Removable 3:PM */ |
| 195 | unsigned short command_set_2; /* bits 14:Smart Enabled 13:0 zero */ |
| 196 | unsigned short cfsse; /* command set-feature supported extensions */ |
| 197 | unsigned short cfs_enable_1; /* command set-feature enabled */ |
| 198 | unsigned short cfs_enable_2; /* command set-feature enabled */ |
| 199 | unsigned short csf_default; /* command set-feature default */ |
| 200 | unsigned short dma_ultra; /* */ |
| 201 | unsigned short word89; /* reserved (word 89) */ |
| 202 | unsigned short word90; /* reserved (word 90) */ |
| 203 | unsigned short CurAPMvalues; /* current APM values */ |
| 204 | unsigned short word92; /* reserved (word 92) */ |
| 205 | unsigned short hw_config; /* hardware config */ |
| 206 | unsigned short words94_125[32];/* reserved words 94-125 */ |
| 207 | unsigned short last_lun; /* reserved (word 126) */ |
| 208 | unsigned short word127; /* reserved (word 127) */ |
| 209 | unsigned short dlf; /* device lock function |
| 210 | * 15:9 reserved |
| 211 | * 8 security level 1:max 0:high |
| 212 | * 7:6 reserved |
| 213 | * 5 enhanced erase |
| 214 | * 4 expire |
| 215 | * 3 frozen |
| 216 | * 2 locked |
| 217 | * 1 en/disabled |
| 218 | * 0 capability |
| 219 | */ |
| 220 | unsigned short csfo; /* current set features options |
| 221 | * 15:4 reserved |
| 222 | * 3 auto reassign |
| 223 | * 2 reverting |
| 224 | * 1 read-look-ahead |
| 225 | * 0 write cache |
| 226 | */ |
| 227 | unsigned short words130_155[26];/* reserved vendor words 130-155 */ |
| 228 | unsigned short word156; |
| 229 | unsigned short words157_159[3];/* reserved vendor words 157-159 */ |
| 230 | unsigned short words160_255[95];/* reserved words 160-255 */ |
| 231 | } hd_driveid_t; |
| 232 | |
| 233 | |
| 234 | /* |
| 235 | * PIO Mode Configuration |
| 236 | * |
| 237 | * See ATA-3 (AT Attachment-3 Interface) documentation, Figure 14 / Table 21 |
| 238 | */ |
| 239 | |
| 240 | typedef struct { |
| 241 | unsigned int t_setup; /* Setup Time in [ns] or clocks */ |
| 242 | unsigned int t_length; /* Length Time in [ns] or clocks */ |
| 243 | unsigned int t_hold; /* Hold Time in [ns] or clocks */ |
| 244 | } |
| 245 | pio_config_t; |
| 246 | |
| 247 | #define IDE_MAX_PIO_MODE 4 /* max suppurted PIO mode */ |
| 248 | |
| 249 | /* ------------------------------------------------------------------------- */ |
| 250 | |
| 251 | #endif /* _ATA_H */ |