blob: a7bcee6a64ce5dd04f9659307b78c75dacadac04 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
wdenkfe8c2802002-11-03 00:38:21 +00002/*
3 * (C) Copyright 2000
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenkfe8c2802002-11-03 00:38:21 +00005 */
6
7/*
8 * Most of the following information was derived from the document
Heinrich Schuchardta8e7c192020-02-26 05:29:47 +01009 * "Information Technology - AT Attachment-3 Interface (ATA-3)",
10 * ANSI X3.298-1997.
wdenkfe8c2802002-11-03 00:38:21 +000011 */
12
13#ifndef _ATA_H
14#define _ATA_H
15
Steven A. Falcoc8a59332008-08-15 15:29:12 -040016#include <libata.h>
17
wdenkfe8c2802002-11-03 00:38:21 +000018/* 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-VILLARD03836942008-10-16 15:01:15 +020023#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))
wdenkfe8c2802002-11-03 00:38:21 +000026
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)
wdenk2f99a692004-01-04 22:51:12 +000038#define ATA_DATA_EVEN ATA_IO_REG(8)
39#define ATA_DATA_ODD ATA_IO_REG(9)
wdenkfe8c2802002-11-03 00:38:21 +000040#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 Arlteddcf952011-11-10 08:51:57 +000062#ifndef ATA_DEVICE
wdenkfe8c2802002-11-03 00:38:21 +000063#define ATA_DEVICE(x) ((x & 1)<<4)
Reinhard Arlteddcf952011-11-10 08:51:57 +000064#endif /* ATA_DEVICE */
wdenkfe8c2802002-11-03 00:38:21 +000065#define ATA_LBA 0xE0
66
67/*
wdenkfe8c2802002-11-03 00:38:21 +000068 * ATAPI Commands
69 */
wdenkfe8c2802002-11-03 00:38:21 +000070#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
76
77#define ATA_GET_ERR() inb(ATA_STATUS)
78#define ATA_GET_STAT() inb(ATA_STATUS)
79#define ATA_OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
80#define ATA_BAD_R_STAT (ATA_STAT_BUSY | ATA_STAT_ERR)
81#define ATA_BAD_W_STAT (ATA_BAD_R_STAT | ATA_STAT_FAULT)
82#define ATA_BAD_STAT (ATA_BAD_R_STAT | ATA_STAT_DRQ)
83#define ATA_DRIVE_READY (ATA_READY_STAT | ATA_STAT_SEEK)
84#define ATA_DATA_READY (ATA_STAT_DRQ)
85
86#define ATA_BLOCKSIZE 512 /* bytes */
87#define ATA_BLOCKSHIFT 9 /* 2 ^ ATA_BLOCKSIZESHIFT = 512 */
Stanislav Galabov986b5162016-02-17 15:23:29 +020088#define ATA_SECTORWORDS (512 / sizeof(uint32_t))
wdenkfe8c2802002-11-03 00:38:21 +000089
90#ifndef ATA_RESET_TIME
91#define ATA_RESET_TIME 60 /* spec allows up to 31 seconds */
92#endif
93
94/* ------------------------------------------------------------------------- */
95
96/*
97 * structure returned by ATA_CMD_IDENT, as per ANSI ATA2 rev.2f spec
98 */
99typedef struct hd_driveid {
100 unsigned short config; /* lots of obsolete bit flags */
101 unsigned short cyls; /* "physical" cyls */
102 unsigned short reserved2; /* reserved (word 2) */
103 unsigned short heads; /* "physical" heads */
104 unsigned short track_bytes; /* unformatted bytes per track */
105 unsigned short sector_bytes; /* unformatted bytes per sector */
106 unsigned short sectors; /* "physical" sectors per track */
107 unsigned short vendor0; /* vendor unique */
108 unsigned short vendor1; /* vendor unique */
109 unsigned short vendor2; /* vendor unique */
110 unsigned char serial_no[20]; /* 0 = not_specified */
111 unsigned short buf_type;
112 unsigned short buf_size; /* 512 byte increments; 0 = not_specified */
113 unsigned short ecc_bytes; /* for r/w long cmds; 0 = not_specified */
114 unsigned char fw_rev[8]; /* 0 = not_specified */
115 unsigned char model[40]; /* 0 = not_specified */
116 unsigned char max_multsect; /* 0=not_implemented */
117 unsigned char vendor3; /* vendor unique */
118 unsigned short dword_io; /* 0=not_implemented; 1=implemented */
119 unsigned char vendor4; /* vendor unique */
120 unsigned char capability; /* bits 0:DMA 1:LBA 2:IORDYsw 3:IORDYsup*/
121 unsigned short reserved50; /* reserved (word 50) */
122 unsigned char vendor5; /* vendor unique */
123 unsigned char tPIO; /* 0=slow, 1=medium, 2=fast */
124 unsigned char vendor6; /* vendor unique */
125 unsigned char tDMA; /* 0=slow, 1=medium, 2=fast */
126 unsigned short field_valid; /* bits 0:cur_ok 1:eide_ok */
127 unsigned short cur_cyls; /* logical cylinders */
128 unsigned short cur_heads; /* logical heads */
129 unsigned short cur_sectors; /* logical sectors per track */
130 unsigned short cur_capacity0; /* logical total sectors on drive */
131 unsigned short cur_capacity1; /* (2 words, misaligned int) */
132 unsigned char multsect; /* current multiple sector count */
133 unsigned char multsect_valid; /* when (bit0==1) multsect is ok */
Reinoud Zandijk3b5dc942021-02-24 17:44:42 +0100134 unsigned short lba_capacity[2];/* two words containing total number of sectors */
wdenkfe8c2802002-11-03 00:38:21 +0000135 unsigned short dma_1word; /* single-word dma info */
136 unsigned short dma_mword; /* multiple-word dma info */
137 unsigned short eide_pio_modes; /* bits 0:mode3 1:mode4 */
138 unsigned short eide_dma_min; /* min mword dma cycle time (ns) */
139 unsigned short eide_dma_time; /* recommended mword dma cycle time (ns) */
140 unsigned short eide_pio; /* min cycle time (ns), no IORDY */
141 unsigned short eide_pio_iordy; /* min cycle time (ns), with IORDY */
142 unsigned short words69_70[2]; /* reserved words 69-70 */
143 unsigned short words71_74[4]; /* reserved words 71-74 */
144 unsigned short queue_depth; /* */
145 unsigned short words76_79[4]; /* reserved words 76-79 */
146 unsigned short major_rev_num; /* */
147 unsigned short minor_rev_num; /* */
148 unsigned short command_set_1; /* bits 0:Smart 1:Security 2:Removable 3:PM */
wdenkf602aa02004-03-13 23:29:43 +0000149 unsigned short command_set_2; /* bits 14:Smart Enabled 13:0 zero 10:lba48 support*/
wdenkfe8c2802002-11-03 00:38:21 +0000150 unsigned short cfsse; /* command set-feature supported extensions */
151 unsigned short cfs_enable_1; /* command set-feature enabled */
152 unsigned short cfs_enable_2; /* command set-feature enabled */
153 unsigned short csf_default; /* command set-feature default */
154 unsigned short dma_ultra; /* */
155 unsigned short word89; /* reserved (word 89) */
156 unsigned short word90; /* reserved (word 90) */
157 unsigned short CurAPMvalues; /* current APM values */
158 unsigned short word92; /* reserved (word 92) */
159 unsigned short hw_config; /* hardware config */
wdenkf602aa02004-03-13 23:29:43 +0000160 unsigned short words94_99[6];/* reserved words 94-99 */
wdenkc35ba4e2004-03-14 22:25:36 +0000161 /*unsigned long long lba48_capacity; /--* 4 16bit values containing lba 48 total number of sectors */
wdenkf602aa02004-03-13 23:29:43 +0000162 unsigned short lba48_capacity[4]; /* 4 16bit values containing lba 48 total number of sectors */
163 unsigned short words104_125[22];/* reserved words 104-125 */
wdenkfe8c2802002-11-03 00:38:21 +0000164 unsigned short last_lun; /* reserved (word 126) */
165 unsigned short word127; /* reserved (word 127) */
166 unsigned short dlf; /* device lock function
167 * 15:9 reserved
168 * 8 security level 1:max 0:high
169 * 7:6 reserved
170 * 5 enhanced erase
171 * 4 expire
172 * 3 frozen
173 * 2 locked
174 * 1 en/disabled
175 * 0 capability
176 */
177 unsigned short csfo; /* current set features options
178 * 15:4 reserved
179 * 3 auto reassign
180 * 2 reverting
181 * 1 read-look-ahead
182 * 0 write cache
183 */
184 unsigned short words130_155[26];/* reserved vendor words 130-155 */
185 unsigned short word156;
186 unsigned short words157_159[3];/* reserved vendor words 157-159 */
Steven A. Falco2b7574e2008-08-15 15:34:10 -0400187 unsigned short words160_162[3];/* reserved words 160-162 */
188 unsigned short cf_advanced_caps;
189 unsigned short words164_255[92];/* reserved words 164-255 */
wdenkfe8c2802002-11-03 00:38:21 +0000190} hd_driveid_t;
191
192
193/*
194 * PIO Mode Configuration
195 *
196 * See ATA-3 (AT Attachment-3 Interface) documentation, Figure 14 / Table 21
197 */
198
199typedef struct {
200 unsigned int t_setup; /* Setup Time in [ns] or clocks */
201 unsigned int t_length; /* Length Time in [ns] or clocks */
202 unsigned int t_hold; /* Hold Time in [ns] or clocks */
203}
204pio_config_t;
205
206#define IDE_MAX_PIO_MODE 4 /* max suppurted PIO mode */
207
208/* ------------------------------------------------------------------------- */
209
210#endif /* _ATA_H */