From : Ian Moote   - HddSleep.Txt

This is a small example of how to place your Ide hard-drive into Idle
or Stand-By mode via a small assembly-language routine.  It's
surprisingly simple.

This is not a tutorial on hardware programming or hardware-level hard-
drive access.  For that information you'll have to consult other
sources, or my other two articles on those respective subjects.  This
mini-article is merely for the benefit and edification of those who are
interested in the green features of hard-drives but who are not
particularly interested in reading an entire article on hard-drive
access.

Yes, everything you're about to read I've done personally on several
different models and brands of Ide hard-drive.  No, I'm not an expert.

The first thing you should know is that we're going to be accessing the
hard-drive at the hardware level, using three different I/O ports.  If
you don't have any experience with hardware-level programming or you're
squeemish about accessing your hard-drive at the lowest level then the 
best advice would probably be, "then don't try it."  In reality, 
however, there's very little that can accidentally go wrong, even if
your routine runs amok.

The ports that we're interested in are located at addresses 01F7, 01F6,
and 01F2; they are the Command, SDH, and Sector Count registers,
respectively.  (If you have a secondary hard-drive interface installed,
the addresses will be 0177, 0176, and 0172, respectively.)

I will be demonstrating five commands for placing your hard-drive into
three different modes of idleness, the Idle mode, the Stand-By mode,
and the Sleep mode.

The Idle mode shuts off all non-essential drive electronics, thereby
consuming less power on the 5V supply line.  Some drives will also park
their heads.  In this mode the media is still spinning and the drive
>should< respond to immediately all commands.  In actual practice,
however, it can take as long as a second for Idle drives to respond to
any supported request.  (I believe the reason may be that some drives
may be performing a routine POST during the orderly power-up of their
electronics.)  Some drives also set Busy in this mode, but the
controller will still report Ready so you will be able to issue
commands to the drive.

Stand-By mode is the one that most people are specifically interested
in as it is the one that spins down the media.  Stand-By mode consumes
the least amount of power because the 12V spindle motor is inactive.
The documentation that I've read does not mention what happens to the
drive electronics in this state, just that the spindle is powered down
and that the drive interface remains active and able to respond to all
commands.  I've also noticed from many spec sheets that Stand-By mode
seems to consume more power on the 5V line than when in Idle mode.
This leads me to believe that the drive electronics are generally not
powered down as in the Idle mode.  It can take from three to ten
seconds for a drive in Stand-By mode to respond to commands involving
media-access.  I've done a little experimentation here and it seems
that you can combine the Idle and Stand-By modes by first issuing the
Idle command, then the Stand-By command.  If you issue an Idle command
while the drive is in Stand-By mode, the media will spin up and the
drive will enter Idle mode.

The Sleep mode shuts the drive right down.  When in Sleep mode the
interface is capable of accepting only a soft reset.  Only a soft reset
will awaken a Sleeping drive.  On many spec sheets, the power-
consumption levels are identical to Stand-By mode, but on some it is
obvious that Sleep is a combination of Stand-By and Idle.

The last two modes are Timed Idle and Timed Stand-By, where the drive
may be programmed to enter the Idle or Stand-By modes after a short
delay.  Some drives will not enter a Timed Idle state and issuing the
Timed Idle command will actually place the drive in a Timed Stand-By
mode.  The delay is specified in five second intervals, up to a maximum
of about 15 minutes.  Some drives have a minimum delay period of one
minute.

And now here's how you do it all.  You must first select the drive you
want to affect by specifying it in the SDH register.  (Only the fourth
bit of this register is significant for these commands.  If the fourth
bit is off then the master drive is selected; if the bit is true then
the slave is selected.)  Then you issue the appropriate command to the
Command register.  If you are using a timed power-down mode then you
must also specify the period in the Sector Count register.

The command codes are:

E0h = Stand-By
E1h = Idle
E2h = Timed Stand-By
E3h = Timed Idle
E6h = Sleep

Here's how you place your drive in Idle mode (the code is pretty
generic and should work on any assembler, but compilers such as Tasm 
and Masm may require a lot of extraneous header information and
procedure declarations):

   RADIX 10h
   ;
   HddSDH   EQU 01F6 ;SDH register
   HddCmd   EQU 01F7 ;Command register
   Drive    EQU 00   ;00=Master, 10=slave.
   ;
   MOV AL,Drive      ;What drive?
   MOV DX,HddSDH     ;Address of SDH register
   OUT DX,AL         ;Set the SDH register
   ;
   MOV AL,0E1        ;The Idle command.
   MOV DX,HDDCMD     ;The address of the Command register.
   OUT DX,AL         ;Send the command.  The drive is now Idle.
   ;
   RET


It works exactly the same way for the Stand-By and Sleep modes.  Here's
how you place your drive in Timed Stand-By mode:

   RADIX 10h
   ;
   HddSct   EQU 01F2 ;Sector count register
   HddSDH   EQU 01F6 ;SDH register
   HddCmd   EQU 01F7 ;Command register
   Drive    EQU 00   ;00=Master, 10=slave.
   ;
   MOV AL,Drive      ;What drive?
   MOV DX,HddSDH     ;Address of SDH register
   OUT DX,AL         ;Set the SDH register
   ;
   MOV AL,0C         ;Twelve five-second units (one minute).
   MOV DX,HddSct     ;Address of the Sector Count Register.
   OUT DX,AL         ;The interval is written to the register.
   ;
   MOV AL,0E2        ;The Timed Stand-By command.
   MOV DX,HDDCMD     ;The address of the Command register.
   OUT DX,AL         ;Send the command.  The drive is now in Stand-By
                     ;  mode, and after being accessed, will return to
                     ;  Stand-By mode after a minute of inactivity.
   ;
   RET


Note that the controller issues an interrupt after the completion of
each of these commands.  It is important when issuing multiple commands
that you wait for the drive controller to show Ready before issuing the
next command or the command will be lost.  Such detail is, however,
beyond the scope of this article.

