FreeBSD/sys/dev/gpio/ofw_gpiobus.c
/*
 * Utility functions for easier handling of OFW GPIO pins.
 *
 * !!! BEWARE !!!
 * GPIOBUS uses children's IVARs, so we cannot use this interface for cross
 * tree consumers.
 *
 */
Utility functions for easier handling of OFW GPIO pins.
BEWARE
GPIOBUS uses children's IVARs, so we cannot use this interface for cross
tree consumers.
Utility functions for easier handling of OFW GPIO pins . BEWARE GPIOBUS uses children ' s IVARs so we cannot use this interface for cross tree consumers .
static int
gpio_pin_get_by_ofw_impl(device_t consumer, phandle_t cnode,
    char *prop_name, int idx, gpio_pin_t *out_pin)
{
	phandle_t xref;
	pcell_t *cells;
	device_t busdev;
	struct gpiobus_pin pin;
	int ncells, rv;
	KASSERT(consumer != NULL && cnode > 0,
	    ("both consumer and cnode required"));
	rv = ofw_bus_parse_xref_list_alloc(cnode, prop_name, "#gpio-cells",
	    idx, &xref, &ncells, &cells);
	if (rv != 0)
		return (rv);
	pin.dev = OF_device_from_xref(xref);
	if (pin.dev == NULL) {
		OF_prop_free(cells);
		return (ENODEV);
	}
	busdev = GPIO_GET_BUS(pin.dev);
	if (busdev == NULL) {
		OF_prop_free(cells);
		return (ENODEV);
	}
	rv = gpio_map_gpios(pin.dev, cnode, OF_node_from_xref(xref), ncells,
	    cells, &pin.pin, &pin.flags);
	OF_prop_free(cells);
	if (rv != 0)
		return (ENXIO);
	rv = gpiobus_acquire_pin(busdev, pin.pin);
	if (rv != 0)
		return (EBUSY);
	*out_pin = malloc(sizeof(struct gpiobus_pin), M_DEVBUF,
	    M_WAITOK | M_ZERO);
	**out_pin = pin;
	return (0);
}
static int gpio_pin_get_by_ofw_impl ( device_t consumer , phandle_t cnode , char * prop_name , int idx , gpio_pin_t * out_pin ) { phandle_t xref ; pcell_t * cells ; device_t busdev ; struct gpiobus_pin pin ; int ncells , rv ; KASSERT ( consumer != NULL && cnode > 0 , ( " " ) ) ; rv = ofw_bus_parse_xref_list_alloc ( cnode , prop_name , " " , idx , & xref , & ncells , & cells ) ; if ( rv != 0 ) return ( rv ) ; pin . dev = OF_device_from_xref ( xref ) ; if ( pin . dev == NULL ) { OF_prop_free ( cells ) ; return ( ENODEV ) ; } busdev = GPIO_GET_BUS ( pin . dev ) ; if ( busdev == NULL ) { OF_prop_free ( cells ) ; return ( ENODEV ) ; } rv = gpio_map_gpios ( pin . dev , cnode , OF_node_from_xref ( xref ) , ncells , cells , & pin . pin , & pin . flags ) ; OF_prop_free ( cells ) ; if ( rv != 0 ) return ( ENXIO ) ; rv = gpiobus_acquire_pin ( busdev , pin . pin ) ; if ( rv != 0 ) return ( EBUSY ) ; * out_pin = malloc ( sizeof ( struct gpiobus_pin ) , M_DEVBUF , M_WAITOK | M_ZERO ) ; * * out_pin = pin ; return ( 0 ) ; }
Utility functions for easier handling of OFW GPIO pins.
Utility functions for easier handling of OFW GPIO pins .
/* Translate provider to device. */ /* Test if GPIO bus already exist. */ /* Map GPIO pin. */ /* Reserve GPIO pin. */