Index: /trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc	(revision 614)
+++ /trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc	(revision 615)
@@ -31,4 +31,9 @@
 TIMEOUT_MAXIMUM			EQU		255			; We would actually want 31 seconds here but I don't think there are so slow drives
 
+
+; ATA specs say that in standby mode time to respond could be as long as 30 seconds
+; Note that some low-power drives (like Toshiba 1,8" HDD) have power management enabled by default
+; TODO: It might be better to define timeouts in IDEVARS (in ROMVARS) or in DPT. Having even a single bit in DPT means
+; we could adjust timeouts on runtime when enabling or disabling power management.
 %ifdef MODULE_POWER_MANAGEMENT
 	TIMEOUT_BSY			EQU		TIMEOUT_MOTOR_STARTUP
Index: /trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 614)
+++ /trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 615)
@@ -97,4 +97,5 @@
 COMMAND_IDENTIFY_DEVICE					EQU		0ECh
 COMMAND_SET_FEATURES					EQU		0EFh
+COMMAND_STAND_BY						EQU		0E2h
 COMMAND_IDLE							EQU		0E3h
 
@@ -103,6 +104,8 @@
 FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE	EQU		01h		; CFA feature set only
 FEATURE_ENABLE_WRITE_CACHE				EQU		02h
+FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT	EQU	05h
 FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE	EQU		81h		; CFA feature set only
 FEATURE_DISABLE_WRITE_CACHE				EQU		82h		; Can also be used to flush cache
+FEATURE_DISABLE_ADVANCED_POWER_MANAGEMENT	EQU	85h		; Might not be supported even if FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT is
 FEATURE_SET_TRANSFER_MODE				EQU		03h		; Transfer mode goes to the Sector Count Register
 	PIO_DEFAULT_MODE					EQU		0h
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 614)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 615)
@@ -101,2 +101,36 @@
 %endif ; MODULE_8BIT_IDE_ADVANCED
 %endif ; MODULE_8BIT_IDE
+
+
+;--------------------------------------------------------------------
+; Enable/disable advanced power management command can be used to scale
+; power consumption and performance. Drive supporting Enable APM might not
+; support Disable AMP so we set the drive to max performance if stand by
+; timer value is 0 (idle/standby disabled)
+;
+;
+; AH23h_EnableOrDisableAdvancedPowerManagement
+;	Parameters:
+;		DL:		Stand By timer value (0=disable APM)
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		AH:		Int 13h return status
+;		CF:		0 if successful, 1 if error
+;	Corrupts registers:
+;		AL, BX, CX, DX, SI
+;--------------------------------------------------------------------
+%ifdef MODULE_POWER_MANAGEMENT
+AH23h_EnableOrDisableAdvancedPowerManagement:
+	mov		si, FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT
+	test	dl, dl
+	jnz		SHORT .EnablePowerSave
+	dec		dx
+	dec		dx		; DL = FEh = Maximum performance
+	jmp		AH23h_SetControllerFeatures
+	
+; TODO: We should add power management level to IDEVARS to be adjustable with xtidecfg
+.EnablePowerSave:
+	mov		dl, 0BFh	; For Toshiba 1.8" HDD: 80h...BFh = Mode 1
+	jmp		AH23h_SetControllerFeatures
+%endif ; %ifdef MODULE_POWER_MANAGEMENT
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 614)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 615)
@@ -200,6 +200,22 @@
 	jz		SHORT .NoPowerManagementSupport
 
+	; Do we need to disable APM?
+;TODO: We should check APM feature set flag from ATA ID word 83. The above
+;FLGH_DPT_POWER_MANAGEMENT_SUPPORTED is from ATA ID word 82
+	mov		dl, [cs:ROMVARS.bIdleTimeout]
+	push	dx
+	push	dx
+	call	AH23h_EnableOrDisableAdvancedPowerManagement
+
+	; COMMAND_IDLE is not enough for Toshiba 1,8" HDD since idle mode is the default mode
+	; COMMAND_STAND_BY seemed to do the trick
+	pop		dx
+	mov		al, COMMAND_STAND_BY
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
+	call	Idepack_StoreNonExtParametersAndIssueCommandFromAL
+	STORE_ERROR_FLAG_TO_DPT		FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER
+
+	pop		dx
 	mov		al, COMMAND_IDLE
-	mov		dl, [cs:ROMVARS.bIdleTimeout]
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
 	call	Idepack_StoreNonExtParametersAndIssueCommandFromAL
