FreeBSD/sys/powerpc/powermac/fcu.c
/*
 * This function returns the number of fans. If we call it the second time
 * and we have allocated memory for sc->sc_fans, we fill in the properties.
 */
This function returns the number of fans. If we call it the second time
and we have allocated memory for sc->sc_fans, we fill in the properties.
This function returns the number of fans . If we call it the second time and we have allocated memory for sc - > sc_fans we fill in the properties .
static int
fcu_fill_fan_prop(device_t dev)
{
	phandle_t child;
	struct fcu_softc *sc;
	u_int id[8];
	char location[96];
	char type[64];
	int i = 0, j, len = 0, prop_len, prev_len = 0;
	sc = device_get_softc(dev);
	child = ofw_bus_get_node(dev);
	prop_len = OF_getprop(child, "hwctrl-location", location,
			      sizeof(location));
	while (len < prop_len) {
		if (sc->sc_fans != NULL) {
			strcpy(sc->sc_fans[i].fan.name, location + len);
		}
		prev_len = strlen(location + len) + 1;
		len += prev_len;
		i++;
	}
	if (sc->sc_fans == NULL)
		return (i);
	len = 0;
	i = 0;
	prev_len = 0;
	prop_len = OF_getprop(child, "hwctrl-type", type, sizeof(type));
	while (len < prop_len) {
		if (strcmp(type + len, "fan-rpm") == 0)
			sc->sc_fans[i].type = FCU_FAN_RPM;
		else
			sc->sc_fans[i].type = FCU_FAN_PWM;
		prev_len = strlen(type + len) + 1;
		len += prev_len;
		i++;
	}
	prop_len = OF_getprop(child, "hwctrl-id", id, sizeof(id));
	for (j = 0; j < i; j++)
		sc->sc_fans[j].id = ((id[j] >> 8) & 0x0f) % 8;
	prop_len = OF_getprop(child, "hwctrl-zone", id, sizeof(id));
	for (j = 0; j < i; j++)
		sc->sc_fans[j].fan.zone = id[j];
	for (j = 0; j < i; j++) {
		sc->sc_fans[j].dev = sc->sc_dev;
		if (sc->sc_fans[j].type == FCU_FAN_RPM) {
			sc->sc_fans[j].fan.min_rpm = 4800 >> fcu_rpm_shift;
			sc->sc_fans[j].fan.max_rpm = 56000 >> fcu_rpm_shift;
			sc->sc_fans[j].setpoint =
			    fcu_fan_get_rpm(&sc->sc_fans[j]);
			sc->sc_fans[j].fan.read = 
			    (int (*)(struct pmac_fan *))(fcu_fan_get_rpm);
			sc->sc_fans[j].fan.set =
			    (int (*)(struct pmac_fan *, int))(fcu_fan_set_rpm);
		} else {
			sc->sc_fans[j].fan.min_rpm = 30;	
			sc->sc_fans[j].fan.max_rpm = 100;
			sc->sc_fans[j].fan.read = NULL;
			sc->sc_fans[j].fan.set =
			    (int (*)(struct pmac_fan *, int))(fcu_fan_set_pwm);
		}
		sc->sc_fans[j].fan.default_rpm = sc->sc_fans[j].fan.max_rpm;
	}
	return (i);
}
static int fcu_fill_fan_prop ( device_t dev ) { phandle_t child ; struct fcu_softc * sc ; u_int id [ 8 ] ; char location [ 96 ] ; char type [ 64 ] ; int i = 0 , j , len = 0 , prop_len , prev_len = 0 ; sc = device_get_softc ( dev ) ; child = ofw_bus_get_node ( dev ) ; prop_len = OF_getprop ( child , " " , location , sizeof ( location ) ) ; while ( len < prop_len ) { if ( sc -> sc_fans != NULL ) { strcpy ( sc -> sc_fans [ i ] . fan . name , location + len ) ; } prev_len = strlen ( location + len ) + 1 ; len += prev_len ; i ++ ; } if ( sc -> sc_fans == NULL ) return ( i ) ; len = 0 ; i = 0 ; prev_len = 0 ; prop_len = OF_getprop ( child , " " , type , sizeof ( type ) ) ; while ( len < prop_len ) { if ( strcmp ( type + len , " " ) == 0 ) sc -> sc_fans [ i ] . type = FCU_FAN_RPM ; else sc -> sc_fans [ i ] . type = FCU_FAN_PWM ; prev_len = strlen ( type + len ) + 1 ; len += prev_len ; i ++ ; } prop_len = OF_getprop ( child , " " , id , sizeof ( id ) ) ; for ( j = 0 ; j < i ; j ++ ) sc -> sc_fans [ j ] . id = ( ( id [ j ] >> 8 ) & 0x0f ) % 8 ; prop_len = OF_getprop ( child , " " , id , sizeof ( id ) ) ; for ( j = 0 ; j < i ; j ++ ) sc -> sc_fans [ j ] . fan . zone = id [ j ] ; for ( j = 0 ; j < i ; j ++ ) { sc -> sc_fans [ j ] . dev = sc -> sc_dev ; if ( sc -> sc_fans [ j ] . type == FCU_FAN_RPM ) { sc -> sc_fans [ j ] . fan . min_rpm = 4800 >> fcu_rpm_shift ; sc -> sc_fans [ j ] . fan . max_rpm = 56000 >> fcu_rpm_shift ; sc -> sc_fans [ j ] . setpoint = fcu_fan_get_rpm ( & sc -> sc_fans [ j ] ) ; sc -> sc_fans [ j ] . fan . read = ( int ( * ) ( struct pmac_fan * ) ) ( fcu_fan_get_rpm ) ; sc -> sc_fans [ j ] . fan . set = ( int ( * ) ( struct pmac_fan * , int ) ) ( fcu_fan_set_rpm ) ; } else { sc -> sc_fans [ j ] . fan . min_rpm = 30 ; sc -> sc_fans [ j ] . fan . max_rpm = 100 ; sc -> sc_fans [ j ] . fan . read = NULL ; sc -> sc_fans [ j ] . fan . set = ( int ( * ) ( struct pmac_fan * , int ) ) ( fcu_fan_set_pwm ) ; } sc -> sc_fans [ j ] . fan . default_rpm = sc -> sc_fans [ j ] . fan . max_rpm ; } return ( i ) ; }
This function returns the number of fans.
This function returns the number of fans .
/* Fill the fan location property. */ /* Fill the fan type property. */ /* Fill the fan ID property. */ /* Fill the fan zone property. */ /* Finish setting up fan properties */ /* Percent */