2 * Copyright (C) 2008 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
4 * port from libata of linux kernel
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 ATA_CMD_DEV_RESET
= 0x08, /* ATAPI device reset */
33 ATA_CMD_FLUSH_CACHE
= 0xE7,
34 ATA_CMD_FLUSH_CACHE_EXT
= 0xEA,
35 ATA_CMD_ID_ATA
= 0xEC,
36 ATA_CMD_ID_ATAPI
= 0xA1,
37 ATA_CMD_READ_DMA
= 0xC8,
38 ATA_CMD_READ_DMA_EXT
= 0x25,
39 ATA_CMD_WRITE_DMA
= 0xCA,
40 ATA_CMD_WRITE_DMA_EXT
= 0x35,
41 ATA_CMD_PIO_READ
= 0x20,
42 ATA_CMD_PIO_READ_EXT
= 0x24,
43 ATA_CMD_PIO_WRITE
= 0x30,
44 ATA_CMD_PIO_WRITE_EXT
= 0x34,
45 ATA_CMD_SET_FEATURES
= 0xEF,
48 ATA_CMD_READ_FPDMA_QUEUED
= 0x60,
49 ATA_CMD_WRITE_FPDMA_QUEUED
= 0x61,
54 enum ata_set_features
{
55 /* SETFEATURES stuff */
56 SETFEATURES_XFER
= 0x03,
65 XFER_MW_DMA_4
= 0x24, /* CFA only */
66 XFER_MW_DMA_3
= 0x23, /* CFA only */
70 XFER_PIO_6
= 0x0E, /* CFA only */
71 XFER_PIO_5
= 0x0D, /* CFA only */
79 SETFEATURES_WC_ON
= 0x02, /* Enable write cache */
80 SETFEATURES_WC_OFF
= 0x82, /* Disable write cache */
82 SETFEATURES_SPINUP
= 0x07, /* Spin-up drive */
86 ATA_PROT_UNKNOWN
, /* unknown */
87 ATA_PROT_NODATA
, /* no data */
88 ATA_PROT_PIO
, /* PIO data xfer */
89 ATA_PROT_DMA
, /* DMA */
90 ATA_PROT_NCQ
, /* NCQ */
91 ATA_PROT_ATAPI
, /* packet command, PIO data xfer */
92 ATA_PROT_ATAPI_NODATA
, /* packet command, no data */
93 ATA_PROT_ATAPI_DMA
, /* packet command, DMA */
97 ATA_DEV_ATA
, /* ATA device */
98 ATA_DEV_ATAPI
, /* ATAPI device */
99 ATA_DEV_PMP
, /* Port Multiplier Port */
100 ATA_DEV_UNKNOWN
, /* unknown */
105 ATA_MAX_SECTORS_128
= 128,
106 ATA_MAX_SECTORS
= 256,
107 ATA_MAX_SECTORS_LBA48
= 65535,
109 /* bits in ATA command block registers */
110 ATA_HOB
= (1 << 7), /* LBA48 selector */
111 ATA_NIEN
= (1 << 1), /* disable-irq flag */
112 ATA_LBA
= (1 << 6), /* LBA28 selector */
113 ATA_DEV1
= (1 << 4), /* Select Device 1 (slave) */
114 ATA_BUSY
= (1 << 7), /* BSY status bit */
115 ATA_DRDY
= (1 << 6), /* device ready */
116 ATA_DF
= (1 << 5), /* device fault */
117 ATA_DRQ
= (1 << 3), /* data request i/o */
118 ATA_ERR
= (1 << 0), /* have an error */
119 ATA_SRST
= (1 << 2), /* software reset */
120 ATA_ICRC
= (1 << 7), /* interface CRC error */
121 ATA_UNC
= (1 << 6), /* uncorrectable media error */
122 ATA_IDNF
= (1 << 4), /* ID not found */
123 ATA_ABORTED
= (1 << 2), /* command aborted */
129 ATA_ID_FIELD_VALID
= 53,
130 ATA_ID_LBA_SECTORS
= 60,
131 ATA_ID_MWDMA_MODES
= 63,
132 ATA_ID_PIO_MODES
= 64,
133 ATA_ID_QUEUE_DEPTH
= 75,
134 ATA_ID_SATA_CAP
= 76,
135 ATA_ID_SATA_FEATURES
= 78,
136 ATA_ID_SATA_FEATURES_EN
= 79,
137 ATA_ID_MAJOR_VER
= 80,
138 ATA_ID_MINOR_VER
= 81,
139 ATA_ID_UDMA_MODES
= 88,
140 ATA_ID_LBA48_SECTORS
= 100,
142 ATA_ID_SERNO_LEN
= 20,
143 ATA_ID_FW_REV_LEN
= 8,
144 ATA_ID_PROD_LEN
= 40,
147 ATA_PIO4
= ATA_PIO3
| (1 << 1),
149 ATA_UDMA0
= (1 << 0),
150 ATA_UDMA1
= ATA_UDMA0
| (1 << 1),
151 ATA_UDMA2
= ATA_UDMA1
| (1 << 2),
152 ATA_UDMA3
= ATA_UDMA2
| (1 << 3),
153 ATA_UDMA4
= ATA_UDMA3
| (1 << 4),
154 ATA_UDMA5
= ATA_UDMA4
| (1 << 5),
155 ATA_UDMA6
= ATA_UDMA5
| (1 << 6),
156 ATA_UDMA7
= ATA_UDMA6
| (1 << 7),
159 #define ata_id_is_ata(id) (((id)[0] & (1 << 15)) == 0)
160 #define ata_id_wcache_enabled(id) ((id)[85] & (1 << 5))
161 #define ata_id_has_fua(id) ((id)[84] & (1 << 6))
162 #define ata_id_has_flush(id) ((id)[83] & (1 << 12))
163 #define ata_id_has_flush_ext(id) ((id)[83] & (1 << 13))
164 #define ata_id_has_lba48(id) ((id)[83] & (1 << 10))
165 #define ata_id_has_wcache(id) ((id)[82] & (1 << 5))
166 #define ata_id_has_lba(id) ((id)[49] & (1 << 9))
167 #define ata_id_has_dma(id) ((id)[49] & (1 << 8))
168 #define ata_id_has_ncq(id) ((id)[76] & (1 << 8))
169 #define ata_id_queue_depth(id) (((id)[75] & 0x1f) + 1)
171 #define ata_id_u32(id,n) \
172 (((u32) (id)[(n) + 1] << 16) | ((u32) (id)[(n)]))
173 #define ata_id_u64(id,n) \
174 ( ((u64) (id)[(n) + 3] << 48) | \
175 ((u64) (id)[(n) + 2] << 32) | \
176 ((u64) (id)[(n) + 1] << 16) | \
177 ((u64) (id)[(n) + 0]) )
180 static inline unsigned int ata_id_major_version(const u16
*id
)
184 if (id
[ATA_ID_MAJOR_VER
] == 0xFFFF)
187 for (mver
= 14; mver
>= 1; mver
--)
188 if (id
[ATA_ID_MAJOR_VER
] & (1 << mver
))
193 static inline int ata_id_is_sata(const u16
*id
)
195 return ata_id_major_version(id
) >= 5 && id
[93] == 0;
198 u64
ata_id_n_sectors(u16
*id
);
199 u32
ata_dev_classify(u32 sig
);
200 void ata_id_c_string(const u16
*id
, unsigned char *s
,
201 unsigned int ofs
, unsigned int len
);
202 void ata_dump_id(u16
*id
);
203 void ata_swap_buf_le16(u16
*buf
, unsigned int buf_words
);
205 #endif /* __LIBATA_H__ */