s32 WBFS_Init(u32 device, u32 timeout) { u32 cnt; s32 ret; /* Wrong timeout */ if (!timeout) return -1; /* Try to mount device */ for (cnt = 0; cnt < timeout; cnt++) { switch (device) { case WBFS_DEVICE_USB: { /* Initialize USB storage */ ret = USBStorage_Init(); if (ret >= 0) { /* Setup callbacks */ readCallback = __WBFS_ReadUSB; writeCallback = __WBFS_WriteUSB; /* Device info */ nb_sectors = USBStorage_GetCapacity(§or_size); goto out; } } case WBFS_DEVICE_SDHC: { /* Initialize SDHC */ ret = SDHC_Init(); if (ret) { /* Setup callbacks */ readCallback = __WBFS_ReadSDHC; writeCallback = __WBFS_WriteSDHC; /* Device info */ nb_sectors = 0; sector_size = SDHC_SECTOR_SIZE; goto out; } else ret = -1; } default: return -1; } /* Sleep 1 second */ sleep(1); } out: return ret; }
DSTATUS disk_initialize(BYTE drv, WORD *ss) { s32 r; int i; while(1) { dbgprintf("FFS:Initializing TinyEHCI...\n"); tiny_ehci_init(); udelay(50000); dbgprintf("FFS:Discovering EHCI devices...\n"); i = 1; while(ehci_discover() == -ENODEV) { dbgprintf("FFS:Waiting for device to become ready (%d)\n", i); udelay(4000); i++; } r = USBStorage_Init(); if(r == 0) break; } s_cnt = USBStorage_Get_Capacity(&s_size); *ss = s_size; dbgprintf("FFS:Drive size: %dMB SectorSize:%d\n", s_cnt / 1024 * s_size / 1024, s_size); return r; }
s32 WBFS_Init_Dev(u32 device) { s32 ret = -1; if (wbfs_disc_mutex == LWP_MUTEX_NULL) { LWP_MutexInit(&wbfs_disc_mutex, true); } /* Try to mount device */ switch (device) { case WBFS_DEVICE_USB: { long long t1 = TIME_D(usb_init); long long t2; get_time(&TIME.usb_retry1); /* Initialize USB storage */ ret = USBStorage_Init(); if (ret >= 0) { /* Setup callbacks */ readCallback = __WBFS_ReadUSB; writeCallback = __WBFS_WriteUSB; /* Device info */ nb_sectors = USBStorage_GetCapacity(&wbfs_dev_sector_size); get_time(&TIME.usb_retry2); t2 = TIME_D(usb_init); TIME.usb_retry2 -= (t2 - t1); goto out; } } break; case WBFS_DEVICE_SDHC: { /* Initialize SDHC */ ret = SDHC_Init(); // returns true=ok false=error if (!ret && !sdhc_mode_sd) { // try normal SD sdhc_mode_sd = 1; ret = SDHC_Init(); } if (ret) { /* Setup callbacks */ readCallback = __WBFS_ReadSDHC; writeCallback = __WBFS_WriteSDHC; /* Device info */ nb_sectors = 0; wbfs_dev_sector_size = SDHC_SECTOR_SIZE; goto out; } ret = -1; } break; default: return -1; } out: return ret; }