FreeBSD/sys/powerpc/powermac/macgpio.c
/*
 * Scan Open Firmware child nodes, and attach these as children
 * of the macgpio bus
 */
Scan Open Firmware child nodes, and attach these as children
of the macgpio bus
Scan Open Firmware child nodes and attach these as children of the macgpio bus
static int 
macgpio_attach(device_t dev)
{
	struct macgpio_softc *sc;
        struct macgpio_devinfo *dinfo;
        phandle_t root, child, iparent;
        device_t cdev;
	uint32_t irq;
	sc = device_get_softc(dev);
	root = sc->sc_node = ofw_bus_get_node(dev);
	sc->sc_gpios = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
	    &sc->sc_gpios_rid, RF_ACTIVE);
	for (child = OF_child(root); child != 0; child = OF_peer(child)) {
		dinfo = malloc(sizeof(*dinfo), M_MACGPIO, M_WAITOK | M_ZERO);
		if (ofw_bus_gen_setup_devinfo(&dinfo->mdi_obdinfo, child) !=
		    0) {
			free(dinfo, M_MACGPIO);
			continue;
		}
		if (OF_getencprop(child, "reg", &dinfo->gpio_num,
		    sizeof(dinfo->gpio_num)) != sizeof(dinfo->gpio_num)) {
			dinfo->gpio_num = -1;
		}
		resource_list_init(&dinfo->mdi_resources);
		if (OF_getencprop(child, "interrupts", &irq, sizeof(irq)) == 
		    sizeof(irq)) {
			OF_searchencprop(child, "interrupt-parent", &iparent,
			    sizeof(iparent));
			resource_list_add(&dinfo->mdi_resources, SYS_RES_IRQ,
			    0, MAP_IRQ(iparent, irq), MAP_IRQ(iparent, irq),
			    1);
		}
		if (dinfo->gpio_num > 0x50)
			dinfo->gpio_num -= 0x50;
		cdev = device_add_child(dev, NULL, -1);
		if (cdev == NULL) {
			device_printf(dev, "<%s>: device_add_child failed\n",
			    dinfo->mdi_obdinfo.obd_name);
			ofw_bus_gen_destroy_devinfo(&dinfo->mdi_obdinfo);
			free(dinfo, M_MACGPIO);
			continue;
		}
		device_set_ivars(cdev, dinfo);
	}
	return (bus_generic_attach(dev));
}
static int macgpio_attach ( device_t dev ) { struct macgpio_softc * sc ; struct macgpio_devinfo * dinfo ; phandle_t root , child , iparent ; device_t cdev ; uint32_t irq ; sc = device_get_softc ( dev ) ; root = sc -> sc_node = ofw_bus_get_node ( dev ) ; sc -> sc_gpios = bus_alloc_resource_any ( dev , SYS_RES_MEMORY , & sc -> sc_gpios_rid , RF_ACTIVE ) ; for ( child = OF_child ( root ) ; child != 0 ; child = OF_peer ( child ) ) { dinfo = malloc ( sizeof ( * dinfo ) , M_MACGPIO , M_WAITOK | M_ZERO ) ; if ( ofw_bus_gen_setup_devinfo ( & dinfo -> mdi_obdinfo , child ) != 0 ) { free ( dinfo , M_MACGPIO ) ; continue ; } if ( OF_getencprop ( child , " " , & dinfo -> gpio_num , sizeof ( dinfo -> gpio_num ) ) != sizeof ( dinfo -> gpio_num ) ) { dinfo -> gpio_num = -1 ; } resource_list_init ( & dinfo -> mdi_resources ) ; if ( OF_getencprop ( child , " " , & irq , sizeof ( irq ) ) == sizeof ( irq ) ) { OF_searchencprop ( child , " " , & iparent , sizeof ( iparent ) ) ; resource_list_add ( & dinfo -> mdi_resources , SYS_RES_IRQ , 0 , MAP_IRQ ( iparent , irq ) , MAP_IRQ ( iparent , irq ) , 1 ) ; } if ( dinfo -> gpio_num > 0x50 ) dinfo -> gpio_num -= 0x50 ; cdev = device_add_child ( dev , NULL , -1 ) ; if ( cdev == NULL ) { device_printf ( dev , " \n " , dinfo -> mdi_obdinfo . obd_name ) ; ofw_bus_gen_destroy_devinfo ( & dinfo -> mdi_obdinfo ) ; free ( dinfo , M_MACGPIO ) ; continue ; } device_set_ivars ( cdev , dinfo ) ; } return ( bus_generic_attach ( dev ) ) ; }
Scan Open Firmware child nodes, and attach these as children
 of the macgpio bus
Scan Open Firmware child nodes and attach these as children of the macgpio bus
/*
	 * Iterate through the sub-devices
	 */ /*
			 * Some early GPIO controllers don't provide GPIO
			 * numbers for GPIOs designed only to provide
			 * interrupt resources.  We should still allow these
			 * to attach, but with caution.
			 */ /* Fix messed-up offsets */