Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Most of the following information was derived from the document |
Heinrich Schuchardt | a8e7c19 | 2020-02-26 05:29:47 +0100 | [diff] [blame] | 9 | * "Information Technology - AT Attachment-3 Interface (ATA-3)", |
| 10 | * ANSI X3.298-1997. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef _ATA_H |
| 14 | #define _ATA_H |
| 15 | |
Steven A. Falco | c8a5933 | 2008-08-15 15:29:12 -0400 | [diff] [blame] | 16 | #include <libata.h> |
| 17 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 18 | /* Register addressing depends on the hardware design; for instance, |
| 19 | * 8-bit (register) and 16-bit (data) accesses might use different |
| 20 | * address spaces. This is implemented by the following definitions. |
| 21 | */ |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | #define ATA_IO_DATA(x) (CONFIG_SYS_ATA_DATA_OFFSET+((x) * CONFIG_SYS_ATA_STRIDE)) |
| 24 | #define ATA_IO_REG(x) (CONFIG_SYS_ATA_REG_OFFSET +((x) * CONFIG_SYS_ATA_STRIDE)) |
| 25 | #define ATA_IO_ALT(x) (CONFIG_SYS_ATA_ALT_OFFSET +((x) * CONFIG_SYS_ATA_STRIDE)) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * I/O Register Descriptions |
| 29 | */ |
| 30 | #define ATA_DATA_REG ATA_IO_DATA(0) |
| 31 | #define ATA_ERROR_REG ATA_IO_REG(1) |
| 32 | #define ATA_SECT_CNT ATA_IO_REG(2) |
| 33 | #define ATA_SECT_NUM ATA_IO_REG(3) |
| 34 | #define ATA_CYL_LOW ATA_IO_REG(4) |
| 35 | #define ATA_CYL_HIGH ATA_IO_REG(5) |
| 36 | #define ATA_DEV_HD ATA_IO_REG(6) |
| 37 | #define ATA_COMMAND ATA_IO_REG(7) |
wdenk | 2f99a69 | 2004-01-04 22:51:12 +0000 | [diff] [blame] | 38 | #define ATA_DATA_EVEN ATA_IO_REG(8) |
| 39 | #define ATA_DATA_ODD ATA_IO_REG(9) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 40 | #define ATA_STATUS ATA_COMMAND |
| 41 | #define ATA_DEV_CTL ATA_IO_ALT(6) |
| 42 | #define ATA_LBA_LOW ATA_SECT_NUM |
| 43 | #define ATA_LBA_MID ATA_CYL_LOW |
| 44 | #define ATA_LBA_HIGH ATA_CYL_HIGH |
| 45 | #define ATA_LBA_SEL ATA_DEV_CTL |
| 46 | |
| 47 | /* |
| 48 | * Status register bits |
| 49 | */ |
| 50 | #define ATA_STAT_BUSY 0x80 /* Device Busy */ |
| 51 | #define ATA_STAT_READY 0x40 /* Device Ready */ |
| 52 | #define ATA_STAT_FAULT 0x20 /* Device Fault */ |
| 53 | #define ATA_STAT_SEEK 0x10 /* Device Seek Complete */ |
| 54 | #define ATA_STAT_DRQ 0x08 /* Data Request (ready) */ |
| 55 | #define ATA_STAT_CORR 0x04 /* Corrected Data Error */ |
| 56 | #define ATA_STAT_INDEX 0x02 /* Vendor specific */ |
| 57 | #define ATA_STAT_ERR 0x01 /* Error */ |
| 58 | |
| 59 | /* |
| 60 | * Device / Head Register Bits |
| 61 | */ |
Reinhard Arlt | eddcf95 | 2011-11-10 08:51:57 +0000 | [diff] [blame] | 62 | #ifndef ATA_DEVICE |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 63 | #define ATA_DEVICE(x) ((x & 1)<<4) |
Reinhard Arlt | eddcf95 | 2011-11-10 08:51:57 +0000 | [diff] [blame] | 64 | #endif /* ATA_DEVICE */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 65 | #define ATA_LBA 0xE0 |
| 66 | |
| 67 | /* |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 68 | * ATAPI Commands |
| 69 | */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 70 | #define ATAPI_CMD_INQUIRY 0x12 |
| 71 | #define ATAPI_CMD_REQ_SENSE 0x03 |
| 72 | #define ATAPI_CMD_READ_CAP 0x25 |
| 73 | #define ATAPI_CMD_START_STOP 0x1B |
| 74 | #define ATAPI_CMD_READ_12 0xA8 |
| 75 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 76 | #define ATA_GET_ERR() inb(ATA_STATUS) |
| 77 | #define ATA_GET_STAT() inb(ATA_STATUS) |
| 78 | #define ATA_OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good)) |
| 79 | #define ATA_BAD_R_STAT (ATA_STAT_BUSY | ATA_STAT_ERR) |
| 80 | #define ATA_BAD_W_STAT (ATA_BAD_R_STAT | ATA_STAT_FAULT) |
| 81 | #define ATA_BAD_STAT (ATA_BAD_R_STAT | ATA_STAT_DRQ) |
| 82 | #define ATA_DRIVE_READY (ATA_READY_STAT | ATA_STAT_SEEK) |
| 83 | #define ATA_DATA_READY (ATA_STAT_DRQ) |
| 84 | |
| 85 | #define ATA_BLOCKSIZE 512 /* bytes */ |
| 86 | #define ATA_BLOCKSHIFT 9 /* 2 ^ ATA_BLOCKSIZESHIFT = 512 */ |
Stanislav Galabov | 986b516 | 2016-02-17 15:23:29 +0200 | [diff] [blame] | 87 | #define ATA_SECTORWORDS (512 / sizeof(uint32_t)) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 88 | |
| 89 | #ifndef ATA_RESET_TIME |
| 90 | #define ATA_RESET_TIME 60 /* spec allows up to 31 seconds */ |
| 91 | #endif |
| 92 | |
| 93 | /* ------------------------------------------------------------------------- */ |
| 94 | |
| 95 | /* |
| 96 | * structure returned by ATA_CMD_IDENT, as per ANSI ATA2 rev.2f spec |
| 97 | */ |
| 98 | typedef struct hd_driveid { |
| 99 | unsigned short config; /* lots of obsolete bit flags */ |
| 100 | unsigned short cyls; /* "physical" cyls */ |
| 101 | unsigned short reserved2; /* reserved (word 2) */ |
| 102 | unsigned short heads; /* "physical" heads */ |
| 103 | unsigned short track_bytes; /* unformatted bytes per track */ |
| 104 | unsigned short sector_bytes; /* unformatted bytes per sector */ |
| 105 | unsigned short sectors; /* "physical" sectors per track */ |
| 106 | unsigned short vendor0; /* vendor unique */ |
| 107 | unsigned short vendor1; /* vendor unique */ |
| 108 | unsigned short vendor2; /* vendor unique */ |
| 109 | unsigned char serial_no[20]; /* 0 = not_specified */ |
| 110 | unsigned short buf_type; |
| 111 | unsigned short buf_size; /* 512 byte increments; 0 = not_specified */ |
| 112 | unsigned short ecc_bytes; /* for r/w long cmds; 0 = not_specified */ |
| 113 | unsigned char fw_rev[8]; /* 0 = not_specified */ |
| 114 | unsigned char model[40]; /* 0 = not_specified */ |
| 115 | unsigned char max_multsect; /* 0=not_implemented */ |
| 116 | unsigned char vendor3; /* vendor unique */ |
| 117 | unsigned short dword_io; /* 0=not_implemented; 1=implemented */ |
| 118 | unsigned char vendor4; /* vendor unique */ |
| 119 | unsigned char capability; /* bits 0:DMA 1:LBA 2:IORDYsw 3:IORDYsup*/ |
| 120 | unsigned short reserved50; /* reserved (word 50) */ |
| 121 | unsigned char vendor5; /* vendor unique */ |
| 122 | unsigned char tPIO; /* 0=slow, 1=medium, 2=fast */ |
| 123 | unsigned char vendor6; /* vendor unique */ |
| 124 | unsigned char tDMA; /* 0=slow, 1=medium, 2=fast */ |
| 125 | unsigned short field_valid; /* bits 0:cur_ok 1:eide_ok */ |
| 126 | unsigned short cur_cyls; /* logical cylinders */ |
| 127 | unsigned short cur_heads; /* logical heads */ |
| 128 | unsigned short cur_sectors; /* logical sectors per track */ |
| 129 | unsigned short cur_capacity0; /* logical total sectors on drive */ |
| 130 | unsigned short cur_capacity1; /* (2 words, misaligned int) */ |
| 131 | unsigned char multsect; /* current multiple sector count */ |
| 132 | unsigned char multsect_valid; /* when (bit0==1) multsect is ok */ |
Reinoud Zandijk | 3b5dc94 | 2021-02-24 17:44:42 +0100 | [diff] [blame] | 133 | unsigned short lba_capacity[2];/* two words containing total number of sectors */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 134 | unsigned short dma_1word; /* single-word dma info */ |
| 135 | unsigned short dma_mword; /* multiple-word dma info */ |
| 136 | unsigned short eide_pio_modes; /* bits 0:mode3 1:mode4 */ |
| 137 | unsigned short eide_dma_min; /* min mword dma cycle time (ns) */ |
| 138 | unsigned short eide_dma_time; /* recommended mword dma cycle time (ns) */ |
| 139 | unsigned short eide_pio; /* min cycle time (ns), no IORDY */ |
| 140 | unsigned short eide_pio_iordy; /* min cycle time (ns), with IORDY */ |
| 141 | unsigned short words69_70[2]; /* reserved words 69-70 */ |
| 142 | unsigned short words71_74[4]; /* reserved words 71-74 */ |
| 143 | unsigned short queue_depth; /* */ |
| 144 | unsigned short words76_79[4]; /* reserved words 76-79 */ |
| 145 | unsigned short major_rev_num; /* */ |
| 146 | unsigned short minor_rev_num; /* */ |
| 147 | unsigned short command_set_1; /* bits 0:Smart 1:Security 2:Removable 3:PM */ |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 148 | unsigned short command_set_2; /* bits 14:Smart Enabled 13:0 zero 10:lba48 support*/ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 149 | unsigned short cfsse; /* command set-feature supported extensions */ |
| 150 | unsigned short cfs_enable_1; /* command set-feature enabled */ |
| 151 | unsigned short cfs_enable_2; /* command set-feature enabled */ |
| 152 | unsigned short csf_default; /* command set-feature default */ |
| 153 | unsigned short dma_ultra; /* */ |
| 154 | unsigned short word89; /* reserved (word 89) */ |
| 155 | unsigned short word90; /* reserved (word 90) */ |
| 156 | unsigned short CurAPMvalues; /* current APM values */ |
| 157 | unsigned short word92; /* reserved (word 92) */ |
| 158 | unsigned short hw_config; /* hardware config */ |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 159 | unsigned short words94_99[6];/* reserved words 94-99 */ |
wdenk | c35ba4e | 2004-03-14 22:25:36 +0000 | [diff] [blame] | 160 | /*unsigned long long lba48_capacity; /--* 4 16bit values containing lba 48 total number of sectors */ |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 161 | unsigned short lba48_capacity[4]; /* 4 16bit values containing lba 48 total number of sectors */ |
| 162 | unsigned short words104_125[22];/* reserved words 104-125 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 163 | unsigned short last_lun; /* reserved (word 126) */ |
| 164 | unsigned short word127; /* reserved (word 127) */ |
| 165 | unsigned short dlf; /* device lock function |
| 166 | * 15:9 reserved |
| 167 | * 8 security level 1:max 0:high |
| 168 | * 7:6 reserved |
| 169 | * 5 enhanced erase |
| 170 | * 4 expire |
| 171 | * 3 frozen |
| 172 | * 2 locked |
| 173 | * 1 en/disabled |
| 174 | * 0 capability |
| 175 | */ |
| 176 | unsigned short csfo; /* current set features options |
| 177 | * 15:4 reserved |
| 178 | * 3 auto reassign |
| 179 | * 2 reverting |
| 180 | * 1 read-look-ahead |
| 181 | * 0 write cache |
| 182 | */ |
| 183 | unsigned short words130_155[26];/* reserved vendor words 130-155 */ |
| 184 | unsigned short word156; |
| 185 | unsigned short words157_159[3];/* reserved vendor words 157-159 */ |
Steven A. Falco | 2b7574e | 2008-08-15 15:34:10 -0400 | [diff] [blame] | 186 | unsigned short words160_162[3];/* reserved words 160-162 */ |
| 187 | unsigned short cf_advanced_caps; |
| 188 | unsigned short words164_255[92];/* reserved words 164-255 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 189 | } hd_driveid_t; |
| 190 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 191 | /* |
| 192 | * PIO Mode Configuration |
| 193 | * |
| 194 | * See ATA-3 (AT Attachment-3 Interface) documentation, Figure 14 / Table 21 |
| 195 | */ |
| 196 | |
| 197 | typedef struct { |
| 198 | unsigned int t_setup; /* Setup Time in [ns] or clocks */ |
| 199 | unsigned int t_length; /* Length Time in [ns] or clocks */ |
| 200 | unsigned int t_hold; /* Hold Time in [ns] or clocks */ |
| 201 | } |
| 202 | pio_config_t; |
| 203 | |
| 204 | #define IDE_MAX_PIO_MODE 4 /* max suppurted PIO mode */ |
| 205 | |
| 206 | /* ------------------------------------------------------------------------- */ |
| 207 | |
| 208 | #endif /* _ATA_H */ |