uboot/drivers/block/libata.c
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2008 Freescale Semiconductor, Inc.
   3 *              Dave Liu <daveliu@freescale.com>
   4 *              port from the libata of linux kernel
   5 *
   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.
  10 *
  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.
  15 *
  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,
  19 * MA 02111-1307 USA
  20 *
  21 */
  22
  23#include <libata.h>
  24
  25u64 ata_id_n_sectors(u16 *id)
  26{
  27        if (ata_id_has_lba(id)) {
  28                if (ata_id_has_lba48(id))
  29                        return ata_id_u64(id, ATA_ID_LBA48_SECTORS);
  30                else
  31                        return ata_id_u32(id, ATA_ID_LBA_SECTORS);
  32        } else {
  33                return 0;
  34        }
  35}
  36
  37u32 ata_dev_classify(u32 sig)
  38{
  39        u8 lbam, lbah;
  40
  41        lbam = (sig >> 16) & 0xff;
  42        lbah = (sig >> 24) & 0xff;
  43
  44        if (((lbam == 0) && (lbah == 0)) ||
  45                ((lbam == 0x3c) && (lbah == 0xc3)))
  46                return ATA_DEV_ATA;
  47
  48        if ((lbam == 0x14) && (lbah == 0xeb))
  49                return ATA_DEV_ATAPI;
  50
  51        if ((lbam == 0x69) && (lbah == 0x96))
  52                return ATA_DEV_PMP;
  53
  54        return ATA_DEV_UNKNOWN;
  55}
  56
  57static void ata_id_string(const u16 *id, unsigned char *s,
  58                         unsigned int ofs, unsigned int len)
  59{
  60        unsigned int c;
  61
  62        while (len > 0) {
  63                c = id[ofs] >> 8;
  64                *s = c;
  65                s++;
  66
  67                c = id[ofs] & 0xff;
  68                *s = c;
  69                s++;
  70
  71                ofs++;
  72                len -= 2;
  73        }
  74}
  75
  76void ata_id_c_string(const u16 *id, unsigned char *s,
  77                         unsigned int ofs, unsigned int len)
  78{
  79        unsigned char *p;
  80
  81        ata_id_string(id, s, ofs, len - 1);
  82
  83        p = s + strnlen((char *)s, len - 1);
  84        while (p > s && p[-1] == ' ')
  85                p--;
  86        *p = '\0';
  87}
  88
  89void ata_dump_id(u16 *id)
  90{
  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];
  94        u64 n_sectors;
  95
  96        /* Serial number */
  97        ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
  98        printf("S/N: %s\n\r", serial);
  99
 100        /* Firmware version */
 101        ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware));
 102        printf("Firmware version: %s\n\r", firmware);
 103
 104        /* Product model */
 105        ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product));
 106        printf("Product model number: %s\n\r", product);
 107
 108        /* Total sectors of device  */
 109        n_sectors = ata_id_n_sectors(id);
 110        printf("Capablity: %lld sectors\n\r", n_sectors);
 111
 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",
 117                id[49],
 118                id[53],
 119                id[63],
 120                id[64],
 121                id[75]);
 122
 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",
 126                id[76],
 127                id[78],
 128                id[79]);
 129
 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",
 135                id[80],
 136                id[81],
 137                id[82],
 138                id[83],
 139                id[84]);
 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",
 145                id[85],
 146                id[86],
 147                id[87],
 148                id[88],
 149                id[93]);
 150}
 151
 152void ata_swap_buf_le16(u16 *buf, unsigned int buf_words)
 153{
 154        unsigned int i;
 155
 156        for (i = 0; i < buf_words; i++)
 157                buf[i] = le16_to_cpu(buf[i]);
 158}
 159