mi/util.c
// set the Advanced Power Management mode for the drive.   Modern hard
// drives can have a number of power management states, ranging from
// lowest (least performance) to highest power consumption, which results
// in the highest performance.
set the Advanced Power Management mode for the drive.   Modern hard
drives can have a number of power management states, ranging from
lowest (least performance) to highest power consumption, which results
in the highest performance.
set the Advanced Power Management mode for the drive . Modern hard drives can have a number of power management states ranging from lowest ( least performance ) to highest power consumption which results in the highest performance .
int32_t ata_setapm(struct ATA *ata, int ata_chan, int ata_dev, uint32_t apm_val)
{
	int32_t rc = 0;
	if( (apm_val > ATA_APM_MAXPERF) || (apm_val < 0) ) {
			printf("invalid APM value: must be %d-%d\n", 1, ATA_APM_MAXPERF-ATA_APM_MINPERF);
			rc = -1;
	}
	ata_setataparams(ata, apm_val, 0);
	ata_setfeature_param(ata, ATA_APM_ENABLE);
	if(apm_val == 0)
			ata_setfeature_param(ata, ATA_APM_DISABLE);
	if(!rc) {
		rc = ata_cmd(ata, ata_chan, ata_dev, ATA__SETFEATURES, 0);
		if(rc)
			perror("Set APM failed");
		else {
			printf("Set APM value to %d\n", apm_val);
			if(apm_val == ATA_APM_MAXPERF)
					printf("APM value set to maximum performance (most power consumption)\n");
			else if(apm_val == ATA_APM_MINPERF)
				printf("APM value set to minimum performance (least power consumption)\n");
			else if(apm_val == 0)
				printf("APM Disabled\n");
		}
	}
	return rc;
}
int32_t ata_setapm ( struct ATA * ata , int ata_chan , int ata_dev , uint32_t apm_val ) { int32_t rc = 0 ; if ( ( apm_val > ATA_APM_MAXPERF ) || ( apm_val < 0 ) ) { printf ( " \n " , 1 , ATA_APM_MAXPERF - ATA_APM_MINPERF ) ; rc = -1 ; } ata_setataparams ( ata , apm_val , 0 ) ; ata_setfeature_param ( ata , ATA_APM_ENABLE ) ; if ( apm_val == 0 ) ata_setfeature_param ( ata , ATA_APM_DISABLE ) ; if ( ! rc ) { rc = ata_cmd ( ata , ata_chan , ata_dev , ATA__SETFEATURES , 0 ) ; if ( rc ) perror ( " " ) ; else { printf ( " \n " , apm_val ) ; if ( apm_val == ATA_APM_MAXPERF ) printf ( " \n " ) ; else if ( apm_val == ATA_APM_MINPERF ) printf ( " \n " ) ; else if ( apm_val == 0 ) printf ( " \n " ) ; } } return rc ; }
set the Advanced Power Management mode for the drive.
set the Advanced Power Management mode for the drive .
// user inputs vale 1-126, 0x01-0xFE // allocate and initialize the ata_cmd structure // send the APM command to the drive as a FEATURE