Beispiel #1
0
static int
do_fan( SaHpiSessionIdT session_id, SaHpiResourceIdT resource_id,
        SaHpiRdrT *rdr )
{
        SaErrorT rv;
        SaHpiCtrlRecT *ctrl_rec = &rdr->RdrTypeUnion.CtrlRec;

        printf( "\tfan: num %d, id ", ctrl_rec->Num );
        display_textbuffer( rdr->IdString );
        printf( "\n" );

        if ( ctrl_rec->Type != SAHPI_CTRL_TYPE_ANALOG ) {
                fprintf( stderr, "cannot handle non analog fan controls !\n" );
                return 0;
        }

        printf( "\t\tmin       %d\n", ctrl_rec->TypeUnion.Analog.Min );
        printf( "\t\tmax       %d\n", ctrl_rec->TypeUnion.Analog.Max );
        printf( "\t\tdefault   %d\n", ctrl_rec->TypeUnion.Analog.Default );

        SaHpiCtrlStateAnalogT speed;

        rv = get_fan_speed( session_id, resource_id, ctrl_rec->Num, &speed );

        if ( rv != SA_OK )
                return 0;

        printf( "\t\tcurrent   %d\n", speed );

        if ( fan_speed == -1 )
                return 0;
  
        if (    fan_speed < ctrl_rec->TypeUnion.Analog.Min 
                || fan_speed > ctrl_rec->TypeUnion.Analog.Max ) {
                fprintf( stderr, "fan speed %d out of range [%d,%d] !\n",
                         fan_speed, ctrl_rec->TypeUnion.Analog.Min,
                         ctrl_rec->TypeUnion.Analog.Max );
                return 0;
        }

        speed = fan_speed;
        rv = set_fan_speed( session_id, resource_id, ctrl_rec->Num, speed );

        if ( rv != SA_OK )
                return 0;
  
        rv = get_fan_speed( session_id, resource_id, ctrl_rec->Num, &speed );

        if ( rv != SA_OK )
                return 0;
  
        printf( "\t\tnew speed %d\n", speed );

        return 0;
}
Beispiel #2
0
int main(void)
{
	int result, done, op;

	result = SusiDllInit();
	if (result == FALSE) {
		printf("SusiDllInit() failed\n");
		return 1;
	}

	result = SusiHWMAvailable();
	if (result == FALSE) {
		printf("SusiHWMAvailable() failed\n");
		SusiDllUnInit();
		return 1;
	}

	result = show_platform_info();
	
	done = 0;
	while (! done) {
		show_menu();
		if (scanf("%i", &op) <= 0)
			op = -1;

		switch (op) {
		case 0:
			done = 1;
			continue;
		case 1:
			result = get_voltage();
			break;
		case 2:
			result = get_temperature();
			break;
		case 3:
			result = get_fan_speed();
			break;
		case 4:
			result = set_fan_speed();
			break;
		default:
			printf("\nUnknown choice!\n\n");
			continue;
		}
		if (result != 0) {
			printf("Library returns with error.\n");
			SusiDllUnInit();
			return 1;
		}
	}

	result = SusiDllUnInit();
	if (result == FALSE) {
		printf("SusiDllUnInit() failed\n");
		return 1;
	}

	return 0;
}
Beispiel #3
0
/*
 * Open fan devices and initialize per fan data structure.
 * Returns #fans found.
 */
static int
envd_setup_fans(void)
{
	int		i, fd;
	fanspeed_t	speed;
	env_fan_t	*fanp;
	char		path[FILENAME_MAX];
	int		fancnt = 0;

	for (i = 0; (fanp = envd_fans[i]) != NULL; i++) {
		fanp->fd = -1;
		fanp->cur_speed = 0;
		fanp->prev_speed = 0;

		(void) strcpy(path, "/devices");
		(void) strlcat(path, fanp->devfs_path, sizeof (path));
		fd = open(path, O_RDWR);
		if (fd == -1) {
			envd_log(LOG_WARNING, ENV_FAN_OPEN_FAIL, fanp->name,
			    fanp->devfs_path, errno, strerror(errno));
			fanp->present = B_FALSE;
			continue;
		}
		fanp->fd = fd;
		fanp->present = B_TRUE;
		fancnt++;

		/*
		 * Set cur_speed/prev_speed to current fan speed
		 */
		if (get_fan_speed(fanp, &speed) == -1) {
			/*
			 * The Fan driver does not know the current fan speed.
			 * Initialize it to 50% of the max speed and reread
			 * to get the current speed.
			 */
			speed = fanp->speed_max/2;
			(void) set_fan_speed(fanp, speed);
			if (get_fan_speed(fanp, &speed) == -1)
				continue;
		}
		fanp->cur_speed = speed;
		fanp->prev_speed = speed;
	}
	return (fancnt);
}
Beispiel #4
0
/*
 * Read function for volatile "Speed" property on "fan" class node
 */
static int
get_current_speed(ptree_rarg_t *parg, void *buf)
{
	fanspeed_t	speed;
	picl_prophdl_t	proph;
	fan_node_t	*fnodep;

	/*
	 * Locate the fan in our fan_nodes table by matching the
	 * property handle and get fan speed.
	 */
	proph = parg->proph;
	for (fnodep = &fan_nodes[0]; fnodep->fan_name != NULL; fnodep++) {
		if (fnodep->proph != proph)
			continue;
		if (get_fan_speed(fnodep->fanp, &speed) < 0)
			return (PICL_FAILURE);

		(void) memcpy(buf, (caddr_t)&speed, sizeof (speed));
		return (PICL_SUCCESS);
	}
	return (PICL_FAILURE);
}