2 * Copyright (C) 2008 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
4 * port from the 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,
25 u64 ata_id_n_sectors(u16 *id)
27 if (ata_id_has_lba(id)) {
28 if (ata_id_has_lba48(id))
29 return ata_id_u64(id, ATA_ID_LBA48_SECTORS);
31 return ata_id_u32(id, ATA_ID_LBA_SECTORS);
37 u32 ata_dev_classify(u32 sig)
41 lbam = (sig >> 16) & 0xff;
42 lbah = (sig >> 24) & 0xff;
44 if (((lbam == 0) && (lbah == 0)) ||
45 ((lbam == 0x3c) && (lbah == 0xc3)))
48 if ((lbam == 0x14) && (lbah == 0xeb))
51 if ((lbam == 0x69) && (lbah == 0x96))
54 return ATA_DEV_UNKNOWN;
57 static void ata_id_string(const u16 *id, unsigned char *s,
58 unsigned int ofs, unsigned int len)
76 void ata_id_c_string(const u16 *id, unsigned char *s,
77 unsigned int ofs, unsigned int len)
81 ata_id_string(id, s, ofs, len - 1);
83 p = s + strnlen((char *)s, len - 1);
84 while (p > s && p[-1] == ' ')
89 void ata_dump_id(u16 *id)
91 unsigned char serial[ATA_ID_SERNO_LEN + 1];
92 unsigned char firmware[ATA_ID_FW_REV_LEN + 1];
93 unsigned char product[ATA_ID_PROD_LEN + 1];
97 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
98 printf("S/N: %s\n\r", serial);
100 /* Firmware version */
101 ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware));
102 printf("Firmware version: %s\n\r", firmware);
105 ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product));
106 printf("Product model number: %s\n\r", product);
108 /* Total sectors of device */
109 n_sectors = ata_id_n_sectors(id);
110 printf("Capablity: %lld sectors\n\r", n_sectors);
112 printf ("id[49]: capabilities = 0x%04x\n"
113 "id[53]: field valid = 0x%04x\n"
114 "id[63]: mwdma = 0x%04x\n"
115 "id[64]: pio = 0x%04x\n"
116 "id[75]: queue depth = 0x%04x\n",
123 printf ("id[76]: sata capablity = 0x%04x\n"
124 "id[78]: sata features supported = 0x%04x\n"
125 "id[79]: sata features enable = 0x%04x\n",
130 printf ("id[80]: major version = 0x%04x\n"
131 "id[81]: minor version = 0x%04x\n"
132 "id[82]: command set supported 1 = 0x%04x\n"
133 "id[83]: command set supported 2 = 0x%04x\n"
134 "id[84]: command set extension = 0x%04x\n",
140 printf ("id[85]: command set enable 1 = 0x%04x\n"
141 "id[86]: command set enable 2 = 0x%04x\n"
142 "id[87]: command set default = 0x%04x\n"
143 "id[88]: udma = 0x%04x\n"
144 "id[93]: hardware reset result = 0x%04x\n",
152 void ata_swap_buf_le16(u16 *buf, unsigned int buf_words)
156 for (i = 0; i < buf_words; i++)
157 buf[i] = le16_to_cpu(buf[i]);