FreeBSD/sys/dev/extres/regulator/regulator_fixed.c
/*
 * GPIO list functions.
 * Two or more regulators can share single GPIO pins, so we must track all
 * GPIOs in gpio_list.
 * The GPIO pin is registerd and reseved for first consumer, all others share
 * gpio_entry with it.
 */
GPIO list functions.
Two or more regulators can share single GPIO pins, so we must track all
GPIOs in gpio_list.
The GPIO pin is registerd and reseved for first consumer, all others share
gpio_entry with it.
GPIO list functions . Two or more regulators can share single GPIO pins so we must track all GPIOs in gpio_list . The GPIO pin is registerd and reseved for first consumer all others share gpio_entry with it .
static struct gpio_entry *
regnode_get_gpio_entry(struct gpiobus_pin *gpio_pin)
{
	struct gpio_entry *entry, *tmp;
	device_t busdev;
	int rv;
	busdev = GPIO_GET_BUS(gpio_pin->dev);
	if (busdev == NULL)
		return (NULL);
	entry = malloc(sizeof(struct gpio_entry), M_FIXEDREGULATOR,
	    M_WAITOK | M_ZERO);
	mtx_lock(&gpio_list_mtx);
	TAILQ_FOREACH(tmp, &gpio_list, link) {
		if (tmp->gpio_pin.dev == gpio_pin->dev &&
		    tmp->gpio_pin.pin == gpio_pin->pin) {
			tmp->use_cnt++;
			mtx_unlock(&gpio_list_mtx);
			free(entry, M_FIXEDREGULATOR);
			return (tmp);
		}
	}
	rv = gpiobus_acquire_pin(busdev, gpio_pin->pin);
	if (rv != 0) {
		mtx_unlock(&gpio_list_mtx);
		free(entry, M_FIXEDREGULATOR);
		return (NULL);
	}
	entry->gpio_pin = *gpio_pin;
	entry->use_cnt = 1;
	TAILQ_INSERT_TAIL(&gpio_list, entry, link);
	mtx_unlock(&gpio_list_mtx);
	return (entry);
}
static struct gpio_entry * regnode_get_gpio_entry ( struct gpiobus_pin * gpio_pin ) { struct gpio_entry * entry , * tmp ; device_t busdev ; int rv ; busdev = GPIO_GET_BUS ( gpio_pin -> dev ) ; if ( busdev == NULL ) return ( NULL ) ; entry = malloc ( sizeof ( struct gpio_entry ) , M_FIXEDREGULATOR , M_WAITOK | M_ZERO ) ; mtx_lock ( & gpio_list_mtx ) ; TAILQ_FOREACH ( tmp , & gpio_list , link ) { if ( tmp -> gpio_pin . dev == gpio_pin -> dev && tmp -> gpio_pin . pin == gpio_pin -> pin ) { tmp -> use_cnt ++ ; mtx_unlock ( & gpio_list_mtx ) ; free ( entry , M_FIXEDREGULATOR ) ; return ( tmp ) ; } } rv = gpiobus_acquire_pin ( busdev , gpio_pin -> pin ) ; if ( rv != 0 ) { mtx_unlock ( & gpio_list_mtx ) ; free ( entry , M_FIXEDREGULATOR ) ; return ( NULL ) ; } entry -> gpio_pin = * gpio_pin ; entry -> use_cnt = 1 ; TAILQ_INSERT_TAIL ( & gpio_list , entry , link ) ; mtx_unlock ( & gpio_list_mtx ) ; return ( entry ) ; }
GPIO list functions.
GPIO list functions .
/* Reserve pin. */ /* XXX Can we call gpiobus_acquire_pin() with gpio_list_mtx held? */ /* Everything is OK, build new entry and insert it to list. */