FreeBSD/sys/dev/extres/regulator/regulator_fixed.c
/*
 * Enable/disable regulator.
 * Take shared GPIO pins in account
 */
Enable/disable regulator.
Take shared GPIO pins in account
Enable / disable regulator . Take shared GPIO pins in account
static int
regnode_fixed_enable(struct regnode *regnode, bool enable, int *udelay)
{
	device_t dev;
	struct regnode_fixed_sc *sc;
	struct gpiobus_pin *pin;
	int rv;
	sc = regnode_get_softc(regnode);
	dev = regnode_get_device(regnode);
	*udelay = 0;
	if (sc->param->always_on && !enable)
		return (0);
	if (sc->gpio_entry == NULL)
		return (0);
	pin = &sc->gpio_entry->gpio_pin;
	if (enable) {
		sc->gpio_entry->enable_cnt++;
		if (sc->gpio_entry->enable_cnt > 1)
			return (0);
	} else {
		KASSERT(sc->gpio_entry->enable_cnt > 0,
		    ("Invalid enable count"));
		sc->gpio_entry->enable_cnt--;
		if (sc->gpio_entry->enable_cnt >= 1)
			return (0);
	}
	if (!sc->param->enable_active_high)
		enable = !enable;
	rv = GPIO_PIN_SET(pin->dev, pin->pin, enable);
	if (rv != 0) {
		device_printf(dev, "Cannot set GPIO pin: %d\n", pin->pin);
		return (rv);
	}
	*udelay = sc->param->enable_delay;
	return (0);
}
static int regnode_fixed_enable ( struct regnode * regnode , bool enable , int * udelay ) { device_t dev ; struct regnode_fixed_sc * sc ; struct gpiobus_pin * pin ; int rv ; sc = regnode_get_softc ( regnode ) ; dev = regnode_get_device ( regnode ) ; * udelay = 0 ; if ( sc -> param -> always_on && ! enable ) return ( 0 ) ; if ( sc -> gpio_entry == NULL ) return ( 0 ) ; pin = & sc -> gpio_entry -> gpio_pin ; if ( enable ) { sc -> gpio_entry -> enable_cnt ++ ; if ( sc -> gpio_entry -> enable_cnt > 1 ) return ( 0 ) ; } else { KASSERT ( sc -> gpio_entry -> enable_cnt > 0 , ( " " ) ) ; sc -> gpio_entry -> enable_cnt -- ; if ( sc -> gpio_entry -> enable_cnt >= 1 ) return ( 0 ) ; } if ( ! sc -> param -> enable_active_high ) enable = ! enable ; rv = GPIO_PIN_SET ( pin -> dev , pin -> pin , enable ) ; if ( rv != 0 ) { device_printf ( dev , " \n " , pin -> pin ) ; return ( rv ) ; } * udelay = sc -> param -> enable_delay ; return ( 0 ) ; }
Enable/disable regulator.
Enable / disable regulator .