FreeBSD/sys/arm/at91/at91_pinctrl.c
/* XXX Make this a subclass of simplebus */
XXX Make this a subclass of simplebus
XXX Make this a subclass of simplebus
static struct pinctrl_devinfo *
at91_pinctrl_setup_dinfo(device_t dev, phandle_t node)
{
	struct pinctrl_softc *sc;
	struct pinctrl_devinfo *ndi;
	uint32_t *reg, *intr, icells;
	uint64_t phys, size;
	phandle_t iparent;
	int i, j, k;
	int nintr;
	int nreg;
	sc = device_get_softc(dev);
	ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO);
	if (ofw_bus_gen_setup_devinfo(&ndi->obdinfo, node) != 0) {
		free(ndi, M_DEVBUF);
		return (NULL);
	}
	resource_list_init(&ndi->rl);
	nreg = OF_getencprop_alloc(node, "reg", sizeof(*reg), (void **)&reg);
	if (nreg == -1)
		nreg = 0;
	if (nreg % (sc->acells + sc->scells) != 0) {
			device_printf(dev, "Malformed reg property on <%s>\n",
			    ndi->obdinfo.obd_name);
		nreg = 0;
	}
	for (i = 0, k = 0; i < nreg; i += sc->acells + sc->scells, k++) {
		phys = size = 0;
		for (j = 0; j < sc->acells; j++) {
			phys <<= 32;
			phys |= reg[i + j];
		}
		for (j = 0; j < sc->scells; j++) {
			size <<= 32;
			size |= reg[i + sc->acells + j];
		}
		resource_list_add(&ndi->rl, SYS_RES_MEMORY, k,
		    phys, phys + size - 1, size);
	}
	OF_prop_free(reg);
	nintr = OF_getencprop_alloc(node, "interrupts",  sizeof(*intr),
	    (void **)&intr);
	if (nintr > 0) {
		if (OF_searchencprop(node, "interrupt-parent", &iparent,
		    sizeof(iparent)) == -1) {
			device_printf(dev, "No interrupt-parent found, "
			    "assuming direct parent\n");
			iparent = OF_parent(node);
		}
		if (OF_searchencprop(OF_node_from_xref(iparent), 
		    "#interrupt-cells", &icells, sizeof(icells)) == -1) {
			device_printf(dev, "Missing #interrupt-cells property,"
			    " assuming <1>\n");
			icells = 1;
		}
		if (icells < 1 || icells > nintr) {
			device_printf(dev, "Invalid #interrupt-cells property "
			    "value <%d>, assuming <1>\n", icells);
			icells = 1;
		}
		for (i = 0, k = 0; i < nintr; i += icells, k++) {
			intr[i] = ofw_bus_map_intr(dev, iparent, icells,
			    &intr[i]);
			resource_list_add(&ndi->rl, SYS_RES_IRQ, k, intr[i],
			    intr[i], 1);
		}
		OF_prop_free(intr);
	}
	return (ndi);
}
static struct pinctrl_devinfo * at91_pinctrl_setup_dinfo ( device_t dev , phandle_t node ) { struct pinctrl_softc * sc ; struct pinctrl_devinfo * ndi ; uint32_t * reg , * intr , icells ; uint64_t phys , size ; phandle_t iparent ; int i , j , k ; int nintr ; int nreg ; sc = device_get_softc ( dev ) ; ndi = malloc ( sizeof ( * ndi ) , M_DEVBUF , M_WAITOK | M_ZERO ) ; if ( ofw_bus_gen_setup_devinfo ( & ndi -> obdinfo , node ) != 0 ) { free ( ndi , M_DEVBUF ) ; return ( NULL ) ; } resource_list_init ( & ndi -> rl ) ; nreg = OF_getencprop_alloc ( node , " " , sizeof ( * reg ) , ( void * * ) & reg ) ; if ( nreg == -1 ) nreg = 0 ; if ( nreg % ( sc -> acells + sc -> scells ) != 0 ) { device_printf ( dev , " \n " , ndi -> obdinfo . obd_name ) ; nreg = 0 ; } for ( i = 0 , k = 0 ; i < nreg ; i += sc -> acells + sc -> scells , k ++ ) { phys = size = 0 ; for ( j = 0 ; j < sc -> acells ; j ++ ) { phys <<= 32 ; phys |= reg [ i + j ] ; } for ( j = 0 ; j < sc -> scells ; j ++ ) { size <<= 32 ; size |= reg [ i + sc -> acells + j ] ; } resource_list_add ( & ndi -> rl , SYS_RES_MEMORY , k , phys , phys + size - 1 , size ) ; } OF_prop_free ( reg ) ; nintr = OF_getencprop_alloc ( node , " " , sizeof ( * intr ) , ( void * * ) & intr ) ; if ( nintr > 0 ) { if ( OF_searchencprop ( node , " " , & iparent , sizeof ( iparent ) ) == -1 ) { device_printf ( dev , " " " \n " ) ; iparent = OF_parent ( node ) ; } if ( OF_searchencprop ( OF_node_from_xref ( iparent ) , " " , & icells , sizeof ( icells ) ) == -1 ) { device_printf ( dev , " " " \n " ) ; icells = 1 ; } if ( icells < 1 || icells > nintr ) { device_printf ( dev , " " " \n " , icells ) ; icells = 1 ; } for ( i = 0 , k = 0 ; i < nintr ; i += icells , k ++ ) { intr [ i ] = ofw_bus_map_intr ( dev , iparent , icells , & intr [ i ] ) ; resource_list_add ( & ndi -> rl , SYS_RES_IRQ , k , intr [ i ] , intr [ i ] , 1 ) ; } OF_prop_free ( intr ) ; } return ( ndi ) ; }
XXX Make this a subclass of simplebus
XXX Make this a subclass of simplebus
//		if (bootverbose)