libata.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2008 Freescale Semiconductor, Inc.
  4. * Dave Liu <daveliu@freescale.com>
  5. * port from the libata of linux kernel
  6. */
  7. #include <common.h>
  8. #include <compiler.h>
  9. #include <libata.h>
  10. u64 ata_id_n_sectors(u16 *id)
  11. {
  12. if (ata_id_has_lba(id)) {
  13. if (ata_id_has_lba48(id))
  14. return ata_id_u64(id, ATA_ID_LBA48_SECTORS);
  15. else
  16. return ata_id_u32(id, ATA_ID_LBA_SECTORS);
  17. } else {
  18. return 0;
  19. }
  20. }
  21. u32 ata_dev_classify(u32 sig)
  22. {
  23. u8 lbam, lbah;
  24. lbam = (sig >> 16) & 0xff;
  25. lbah = (sig >> 24) & 0xff;
  26. if (((lbam == 0) && (lbah == 0)) ||
  27. ((lbam == 0x3c) && (lbah == 0xc3)))
  28. return ATA_DEV_ATA;
  29. if ((lbam == 0x14) && (lbah == 0xeb))
  30. return ATA_DEV_ATAPI;
  31. if ((lbam == 0x69) && (lbah == 0x96))
  32. return ATA_DEV_PMP;
  33. return ATA_DEV_UNKNOWN;
  34. }
  35. static void ata_id_string(const u16 *id, unsigned char *s,
  36. unsigned int ofs, unsigned int len)
  37. {
  38. unsigned int c;
  39. while (len > 0) {
  40. c = id[ofs] >> 8;
  41. *s = c;
  42. s++;
  43. c = id[ofs] & 0xff;
  44. *s = c;
  45. s++;
  46. ofs++;
  47. len -= 2;
  48. }
  49. }
  50. void ata_id_c_string(const u16 *id, unsigned char *s,
  51. unsigned int ofs, unsigned int len)
  52. {
  53. unsigned char *p;
  54. ata_id_string(id, s, ofs, len - 1);
  55. p = s + strnlen((char *)s, len - 1);
  56. while (p > s && p[-1] == ' ')
  57. p--;
  58. *p = '\0';
  59. }
  60. void ata_dump_id(u16 *id)
  61. {
  62. unsigned char serial[ATA_ID_SERNO_LEN + 1];
  63. unsigned char firmware[ATA_ID_FW_REV_LEN + 1];
  64. unsigned char product[ATA_ID_PROD_LEN + 1];
  65. u64 n_sectors;
  66. /* Serial number */
  67. ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
  68. printf("S/N: %s\n\r", serial);
  69. /* Firmware version */
  70. ata_id_c_string(id, firmware, ATA_ID_FW_REV, sizeof(firmware));
  71. printf("Firmware version: %s\n\r", firmware);
  72. /* Product model */
  73. ata_id_c_string(id, product, ATA_ID_PROD, sizeof(product));
  74. printf("Product model number: %s\n\r", product);
  75. /* Total sectors of device */
  76. n_sectors = ata_id_n_sectors(id);
  77. printf("Capablity: %lld sectors\n\r", n_sectors);
  78. printf ("id[49]: capabilities = 0x%04x\n"
  79. "id[53]: field valid = 0x%04x\n"
  80. "id[63]: mwdma = 0x%04x\n"
  81. "id[64]: pio = 0x%04x\n"
  82. "id[75]: queue depth = 0x%04x\n",
  83. id[49],
  84. id[53],
  85. id[63],
  86. id[64],
  87. id[75]);
  88. printf ("id[76]: sata capablity = 0x%04x\n"
  89. "id[78]: sata features supported = 0x%04x\n"
  90. "id[79]: sata features enable = 0x%04x\n",
  91. id[76],
  92. id[78],
  93. id[79]);
  94. printf ("id[80]: major version = 0x%04x\n"
  95. "id[81]: minor version = 0x%04x\n"
  96. "id[82]: command set supported 1 = 0x%04x\n"
  97. "id[83]: command set supported 2 = 0x%04x\n"
  98. "id[84]: command set extension = 0x%04x\n",
  99. id[80],
  100. id[81],
  101. id[82],
  102. id[83],
  103. id[84]);
  104. printf ("id[85]: command set enable 1 = 0x%04x\n"
  105. "id[86]: command set enable 2 = 0x%04x\n"
  106. "id[87]: command set default = 0x%04x\n"
  107. "id[88]: udma = 0x%04x\n"
  108. "id[93]: hardware reset result = 0x%04x\n",
  109. id[85],
  110. id[86],
  111. id[87],
  112. id[88],
  113. id[93]);
  114. }
  115. void ata_swap_buf_le16(u16 *buf, unsigned int buf_words)
  116. {
  117. unsigned int i;
  118. for (i = 0; i < buf_words; i++)
  119. buf[i] = le16_to_cpu(buf[i]);
  120. }