void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t * dma_addr) { void *buf = DWC_ALLOC(size); if (!buf) { return NULL; } *dma_addr = (dwc_dma_t) buf; DWC_MEMSET(buf, 0, size); return buf; }
/* * This function is called when an lm_device is bound to a * dwc_otg_driver. It creates the driver components required to * control the device (CIL, HCD, and PCD) and it initializes the * device. The driver components are stored in a dwc_otg_device * structure. A reference to the dwc_otg_device is saved in the * lm_device. This allows the driver to access the dwc_otg_device * structure on subsequent calls to driver methods for this device. * */ int usb_driver_init(uint32_t base_addr) { int retval = 0; __DWC_WARN("dwc_otg_driver_init\n"); dwc_otg_device = &static_data->dwc_otg_device_inst; DWC_MEMSET(dwc_otg_device, 0, sizeof(*dwc_otg_device)); /* * Initialize driver data to point to the global DWC_otg * Device structure. */ __DWC_ERROR("dwc_otg_device addr = 0x%p\n", dwc_otg_device); dwc_otg_device->core_if = dwc_otg_cil_init(base_addr); if (!dwc_otg_device->core_if) { __DWC_ERROR("CIL initialization failed!\n"); retval = -DWC_E_NO_MEMORY; goto fail; } #ifdef USB_DEBUG /* * Attempt to ensure this device is really a DWC_otg Controller. * Read and verify the SNPSID register contents. The value should be * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3", * as in "OTG version 2.XX" or "OTG version 3.XX". */ if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) && ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) { __DWC_WARN("Bad value for SNPSID: 0x%x\n", dwc_otg_get_gsnpsid(dwc_otg_device->core_if)); retval = -DWC_E_INVALID; goto fail; } #endif /* USB_DEBUG */ /* * Disable the global interrupt until all the interrupt * handlers are installed. */ __DWC_WARN("USB INIT: Disabling global IRQ\n"); dwc_otg_disable_global_interrupts(dwc_otg_device->core_if); /* * Initialize the DWC_otg core. */ __DWC_WARN("USB INIT: Initializing OTG core\n"); dwc_otg_core_init(dwc_otg_device->core_if); /* * Initialize the PCD */ __DWC_WARN("USB INIT: Initializing PCD\n"); retval = pcd_init(dwc_otg_device); if (retval != 0) { __DWC_ERROR("pcd_init failed\n"); dwc_otg_device->pcd = NULL; goto fail; } __DWC_WARN("USB INIT: Enabling global IRQ\n"); dwc_otg_enable_global_interrupts(dwc_otg_device->core_if); __DWC_WARN("DWC core initialized! \n"); return 0; fail: __DWC_ERROR("ERROR! unable to init USB driver\n"); return retval; }