ata.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2000
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. /*
  7. * Most of the following information was derived from the document
  8. * "Information Technology - AT Attachment-3 Interface (ATA-3)",
  9. * ANSI X3.298-1997.
  10. */
  11. #ifndef _ATA_H
  12. #define _ATA_H
  13. #include <libata.h>
  14. /* Register addressing depends on the hardware design; for instance,
  15. * 8-bit (register) and 16-bit (data) accesses might use different
  16. * address spaces. This is implemented by the following definitions.
  17. */
  18. #ifndef CONFIG_SYS_ATA_STRIDE
  19. #define CONFIG_SYS_ATA_STRIDE 1
  20. #endif
  21. #define ATA_IO_DATA(x) (CONFIG_SYS_ATA_DATA_OFFSET+((x) * CONFIG_SYS_ATA_STRIDE))
  22. #define ATA_IO_REG(x) (CONFIG_SYS_ATA_REG_OFFSET +((x) * CONFIG_SYS_ATA_STRIDE))
  23. #define ATA_IO_ALT(x) (CONFIG_SYS_ATA_ALT_OFFSET +((x) * CONFIG_SYS_ATA_STRIDE))
  24. /*
  25. * I/O Register Descriptions
  26. */
  27. #define ATA_DATA_REG ATA_IO_DATA(0)
  28. #define ATA_ERROR_REG ATA_IO_REG(1)
  29. #define ATA_SECT_CNT ATA_IO_REG(2)
  30. #define ATA_SECT_NUM ATA_IO_REG(3)
  31. #define ATA_CYL_LOW ATA_IO_REG(4)
  32. #define ATA_CYL_HIGH ATA_IO_REG(5)
  33. #define ATA_DEV_HD ATA_IO_REG(6)
  34. #define ATA_COMMAND ATA_IO_REG(7)
  35. #define ATA_DATA_EVEN ATA_IO_REG(8)
  36. #define ATA_DATA_ODD ATA_IO_REG(9)
  37. #define ATA_STATUS ATA_COMMAND
  38. #define ATA_DEV_CTL ATA_IO_ALT(6)
  39. #define ATA_LBA_LOW ATA_SECT_NUM
  40. #define ATA_LBA_MID ATA_CYL_LOW
  41. #define ATA_LBA_HIGH ATA_CYL_HIGH
  42. #define ATA_LBA_SEL ATA_DEV_CTL
  43. /*
  44. * Status register bits
  45. */
  46. #define ATA_STAT_BUSY 0x80 /* Device Busy */
  47. #define ATA_STAT_READY 0x40 /* Device Ready */
  48. #define ATA_STAT_FAULT 0x20 /* Device Fault */
  49. #define ATA_STAT_SEEK 0x10 /* Device Seek Complete */
  50. #define ATA_STAT_DRQ 0x08 /* Data Request (ready) */
  51. #define ATA_STAT_CORR 0x04 /* Corrected Data Error */
  52. #define ATA_STAT_INDEX 0x02 /* Vendor specific */
  53. #define ATA_STAT_ERR 0x01 /* Error */
  54. /*
  55. * Device / Head Register Bits
  56. */
  57. #ifndef ATA_DEVICE
  58. #define ATA_DEVICE(x) ((x & 1)<<4)
  59. #endif /* ATA_DEVICE */
  60. #define ATA_LBA 0xE0
  61. /*
  62. * ATAPI Commands
  63. */
  64. #define ATAPI_CMD_INQUIRY 0x12
  65. #define ATAPI_CMD_REQ_SENSE 0x03
  66. #define ATAPI_CMD_READ_CAP 0x25
  67. #define ATAPI_CMD_START_STOP 0x1B
  68. #define ATAPI_CMD_READ_12 0xA8
  69. #define ATA_GET_ERR() inb(ATA_STATUS)
  70. #define ATA_GET_STAT() inb(ATA_STATUS)
  71. #define ATA_OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
  72. #define ATA_BAD_R_STAT (ATA_STAT_BUSY | ATA_STAT_ERR)
  73. #define ATA_BAD_W_STAT (ATA_BAD_R_STAT | ATA_STAT_FAULT)
  74. #define ATA_BAD_STAT (ATA_BAD_R_STAT | ATA_STAT_DRQ)
  75. #define ATA_DRIVE_READY (ATA_READY_STAT | ATA_STAT_SEEK)
  76. #define ATA_DATA_READY (ATA_STAT_DRQ)
  77. #define ATA_BLOCKSIZE 512 /* bytes */
  78. #define ATA_BLOCKSHIFT 9 /* 2 ^ ATA_BLOCKSIZESHIFT = 512 */
  79. #define ATA_SECTORWORDS (512 / sizeof(uint32_t))
  80. #ifndef ATA_RESET_TIME
  81. #define ATA_RESET_TIME 60 /* spec allows up to 31 seconds */
  82. #endif
  83. /* ------------------------------------------------------------------------- */
  84. /*
  85. * structure returned by ATA_CMD_IDENT, as per ANSI ATA2 rev.2f spec
  86. */
  87. typedef struct hd_driveid {
  88. unsigned short config; /* lots of obsolete bit flags */
  89. unsigned short cyls; /* "physical" cyls */
  90. unsigned short reserved2; /* reserved (word 2) */
  91. unsigned short heads; /* "physical" heads */
  92. unsigned short track_bytes; /* unformatted bytes per track */
  93. unsigned short sector_bytes; /* unformatted bytes per sector */
  94. unsigned short sectors; /* "physical" sectors per track */
  95. unsigned short vendor0; /* vendor unique */
  96. unsigned short vendor1; /* vendor unique */
  97. unsigned short vendor2; /* vendor unique */
  98. unsigned char serial_no[20]; /* 0 = not_specified */
  99. unsigned short buf_type;
  100. unsigned short buf_size; /* 512 byte increments; 0 = not_specified */
  101. unsigned short ecc_bytes; /* for r/w long cmds; 0 = not_specified */
  102. unsigned char fw_rev[8]; /* 0 = not_specified */
  103. unsigned char model[40]; /* 0 = not_specified */
  104. unsigned char max_multsect; /* 0=not_implemented */
  105. unsigned char vendor3; /* vendor unique */
  106. unsigned short dword_io; /* 0=not_implemented; 1=implemented */
  107. unsigned char vendor4; /* vendor unique */
  108. unsigned char capability; /* bits 0:DMA 1:LBA 2:IORDYsw 3:IORDYsup*/
  109. unsigned short reserved50; /* reserved (word 50) */
  110. unsigned char vendor5; /* vendor unique */
  111. unsigned char tPIO; /* 0=slow, 1=medium, 2=fast */
  112. unsigned char vendor6; /* vendor unique */
  113. unsigned char tDMA; /* 0=slow, 1=medium, 2=fast */
  114. unsigned short field_valid; /* bits 0:cur_ok 1:eide_ok */
  115. unsigned short cur_cyls; /* logical cylinders */
  116. unsigned short cur_heads; /* logical heads */
  117. unsigned short cur_sectors; /* logical sectors per track */
  118. unsigned short cur_capacity0; /* logical total sectors on drive */
  119. unsigned short cur_capacity1; /* (2 words, misaligned int) */
  120. unsigned char multsect; /* current multiple sector count */
  121. unsigned char multsect_valid; /* when (bit0==1) multsect is ok */
  122. unsigned int lba_capacity; /* total number of sectors */
  123. unsigned short dma_1word; /* single-word dma info */
  124. unsigned short dma_mword; /* multiple-word dma info */
  125. unsigned short eide_pio_modes; /* bits 0:mode3 1:mode4 */
  126. unsigned short eide_dma_min; /* min mword dma cycle time (ns) */
  127. unsigned short eide_dma_time; /* recommended mword dma cycle time (ns) */
  128. unsigned short eide_pio; /* min cycle time (ns), no IORDY */
  129. unsigned short eide_pio_iordy; /* min cycle time (ns), with IORDY */
  130. unsigned short words69_70[2]; /* reserved words 69-70 */
  131. unsigned short words71_74[4]; /* reserved words 71-74 */
  132. unsigned short queue_depth; /* */
  133. unsigned short words76_79[4]; /* reserved words 76-79 */
  134. unsigned short major_rev_num; /* */
  135. unsigned short minor_rev_num; /* */
  136. unsigned short command_set_1; /* bits 0:Smart 1:Security 2:Removable 3:PM */
  137. unsigned short command_set_2; /* bits 14:Smart Enabled 13:0 zero 10:lba48 support*/
  138. unsigned short cfsse; /* command set-feature supported extensions */
  139. unsigned short cfs_enable_1; /* command set-feature enabled */
  140. unsigned short cfs_enable_2; /* command set-feature enabled */
  141. unsigned short csf_default; /* command set-feature default */
  142. unsigned short dma_ultra; /* */
  143. unsigned short word89; /* reserved (word 89) */
  144. unsigned short word90; /* reserved (word 90) */
  145. unsigned short CurAPMvalues; /* current APM values */
  146. unsigned short word92; /* reserved (word 92) */
  147. unsigned short hw_config; /* hardware config */
  148. unsigned short words94_99[6];/* reserved words 94-99 */
  149. /*unsigned long long lba48_capacity; /--* 4 16bit values containing lba 48 total number of sectors */
  150. unsigned short lba48_capacity[4]; /* 4 16bit values containing lba 48 total number of sectors */
  151. unsigned short words104_125[22];/* reserved words 104-125 */
  152. unsigned short last_lun; /* reserved (word 126) */
  153. unsigned short word127; /* reserved (word 127) */
  154. unsigned short dlf; /* device lock function
  155. * 15:9 reserved
  156. * 8 security level 1:max 0:high
  157. * 7:6 reserved
  158. * 5 enhanced erase
  159. * 4 expire
  160. * 3 frozen
  161. * 2 locked
  162. * 1 en/disabled
  163. * 0 capability
  164. */
  165. unsigned short csfo; /* current set features options
  166. * 15:4 reserved
  167. * 3 auto reassign
  168. * 2 reverting
  169. * 1 read-look-ahead
  170. * 0 write cache
  171. */
  172. unsigned short words130_155[26];/* reserved vendor words 130-155 */
  173. unsigned short word156;
  174. unsigned short words157_159[3];/* reserved vendor words 157-159 */
  175. unsigned short words160_162[3];/* reserved words 160-162 */
  176. unsigned short cf_advanced_caps;
  177. unsigned short words164_255[92];/* reserved words 164-255 */
  178. } hd_driveid_t;
  179. /*
  180. * PIO Mode Configuration
  181. *
  182. * See ATA-3 (AT Attachment-3 Interface) documentation, Figure 14 / Table 21
  183. */
  184. typedef struct {
  185. unsigned int t_setup; /* Setup Time in [ns] or clocks */
  186. unsigned int t_length; /* Length Time in [ns] or clocks */
  187. unsigned int t_hold; /* Hold Time in [ns] or clocks */
  188. }
  189. pio_config_t;
  190. #define IDE_MAX_PIO_MODE 4 /* max suppurted PIO mode */
  191. /* ------------------------------------------------------------------------- */
  192. #endif /* _ATA_H */