FreeBSD/sys/arm/ti/usb/omap_ehci.c
/**
 *	omap_ehci_attach - driver entry point, sets up the ECHI controller/driver
 *	@dev: the new device handle
 *	
 *	Sets up bus spaces, interrupt handles, etc for the EHCI controller.  It also
 *	parses the resource hints and calls omap_ehci_init() to initialise the
 *	H/W.
 *
 *	LOCKING:
 *	none
 *
 *	RETURNS:
 *	0 on success or a positive error code on failure.
 */
driver entry point, sets up the ECHI controller/driver
@dev: the new device handle

Sets up bus spaces, interrupt handles, etc for the EHCI controller.  It also
parses the resource hints and calls omap_ehci_init() to initialise the
H/W.

none

0 on success or a positive error code on failure.
driver entry point sets up the ECHI controller / driver @dev : the new device handle Sets up bus spaces interrupt handles etc for the EHCI controller . It also parses the resource hints and calls omap_ehci_init () to initialise the H / W . none 0 on success or a positive error code on failure .
static int
omap_ehci_attach(device_t dev)
{
	struct omap_ehci_softc *isc = device_get_softc(dev);
	ehci_softc_t *sc = &isc->base;
	int err;
	int rid;
	sc->sc_bus.parent = dev;
	sc->sc_bus.devices = sc->sc_devices;
	sc->sc_bus.devices_max = EHCI_MAX_DEVICES;
	sc->sc_bus.dma_bits = 32;
	sprintf(sc->sc_vendor, "Texas Instruments");
	isc->sc_dev = dev;
	if (usb_bus_mem_alloc_all(&sc->sc_bus, USB_GET_DMA_TAG(dev),
	                          &ehci_iterate_hw_softc)) {
		return (ENOMEM);
	}
	rid = 0;
	sc->sc_io_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
	if (!sc->sc_io_res) {
		device_printf(dev, "Error: Could not map EHCI memory\n");
		goto error;
	}
	rid = 0;
	sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
	if (sc->sc_irq_res == NULL) {
		device_printf(dev, "Error: could not allocate irq\n");
		goto error;
	}
	sc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
	if (!sc->sc_bus.bdev) {
		device_printf(dev, "Error: could not add USB device\n");
		goto error;
	}
	device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
	device_set_desc(sc->sc_bus.bdev, OMAP_EHCI_HC_DEVSTR);
	err = omap_ehci_init(isc);
	if (err) {
		device_printf(dev, "Error: could not setup OMAP EHCI, %d\n", err);
		goto error;
	}
	sc->sc_io_hdl = rman_get_bushandle(sc->sc_io_res);
	sc->sc_io_tag = rman_get_bustag(sc->sc_io_res);
	sc->sc_io_size = rman_get_size(sc->sc_io_res);
	err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
						 NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl);
	if (err) {
		device_printf(dev, "Error: could not setup irq, %d\n", err);
		sc->sc_intr_hdl = NULL;
		goto error;
	}
	err = ehci_init(sc);
	if (err == 0) {
		err = device_probe_and_attach(sc->sc_bus.bdev);
	}
	if (err) {
		device_printf(dev, "Error: USB init failed err=%d\n", err);
		goto error;
	}
	return (0);
error:
	omap_ehci_detach(dev);
	return (ENXIO);
}
static int omap_ehci_attach ( device_t dev ) { struct omap_ehci_softc * isc = device_get_softc ( dev ) ; ehci_softc_t * sc = & isc -> base ; int err ; int rid ; sc -> sc_bus . parent = dev ; sc -> sc_bus . devices = sc -> sc_devices ; sc -> sc_bus . devices_max = EHCI_MAX_DEVICES ; sc -> sc_bus . dma_bits = 32 ; sprintf ( sc -> sc_vendor , " " ) ; isc -> sc_dev = dev ; if ( usb_bus_mem_alloc_all ( & sc -> sc_bus , USB_GET_DMA_TAG ( dev ) , & ehci_iterate_hw_softc ) ) { return ( ENOMEM ) ; } rid = 0 ; sc -> sc_io_res = bus_alloc_resource_any ( dev , SYS_RES_MEMORY , & rid , RF_ACTIVE ) ; if ( ! sc -> sc_io_res ) { device_printf ( dev , " \n " ) ; goto error ; } rid = 0 ; sc -> sc_irq_res = bus_alloc_resource_any ( dev , SYS_RES_IRQ , & rid , RF_ACTIVE ) ; if ( sc -> sc_irq_res == NULL ) { device_printf ( dev , " \n " ) ; goto error ; } sc -> sc_bus . bdev = device_add_child ( dev , " " , -1 ) ; if ( ! sc -> sc_bus . bdev ) { device_printf ( dev , " \n " ) ; goto error ; } device_set_ivars ( sc -> sc_bus . bdev , & sc -> sc_bus ) ; device_set_desc ( sc -> sc_bus . bdev , OMAP_EHCI_HC_DEVSTR ) ; err = omap_ehci_init ( isc ) ; if ( err ) { device_printf ( dev , " \n " , err ) ; goto error ; } sc -> sc_io_hdl = rman_get_bushandle ( sc -> sc_io_res ) ; sc -> sc_io_tag = rman_get_bustag ( sc -> sc_io_res ) ; sc -> sc_io_size = rman_get_size ( sc -> sc_io_res ) ; err = bus_setup_intr ( dev , sc -> sc_irq_res , INTR_TYPE_BIO | INTR_MPSAFE , NULL , ( driver_intr_t * ) ehci_interrupt , sc , & sc -> sc_intr_hdl ) ; if ( err ) { device_printf ( dev , " \n " , err ) ; sc -> sc_intr_hdl = NULL ; goto error ; } err = ehci_init ( sc ) ; if ( err == 0 ) { err = device_probe_and_attach ( sc -> sc_bus . bdev ) ; } if ( err ) { device_printf ( dev , " \n " , err ) ; goto error ; } return ( 0 ) ; error : omap_ehci_detach ( dev ) ; return ( ENXIO ) ; }
omap_ehci_attach - driver entry point, sets up the ECHI controller/driver
      @dev: the new device handle
omap_ehci_attach - driver entry point sets up the ECHI controller / driver @dev : the new device handle
/* initialise some bus fields */ /* save the device */ /* get all DMA memory */ /* Allocate resource for the EHCI register set */ /* Request an interrupt resource */ /* Add this device as a child of the USBus device */ /* Initialise the ECHI registers */ /* Set the tag and size of the register set in the EHCI context */ /* Setup the interrupt */ /* Finally we are ready to kick off the ECHI host controller */