diff --git a/cgminer.c b/cgminer.c index 3c702576..910bce5d 100644 --- a/cgminer.c +++ b/cgminer.c @@ -2842,6 +2842,16 @@ static void __kill_work(void) applog(LOG_DEBUG, "Killing off API thread"); thr = &control_thr[api_thr_id]; thr_info_cancel(thr); + +#if defined(USE_MODMINER) || defined(USE_BITFORCE) + /* Release USB resources in case it's a restart + * and not a QUIT */ + if (!opt_scrypt) { + applog(LOG_DEBUG, "Releasing all USB devices"); + usb_cleanup(); + } +#endif + } /* This should be the common exit path */ diff --git a/usbutils.c b/usbutils.c index f0dd7c77..27c67cea 100644 --- a/usbutils.c +++ b/usbutils.c @@ -184,6 +184,7 @@ static const char *C_SETFLOW_S = "SetFlowCtrl"; static const char *C_SETMODEM_S = "SetModemCtrl"; static const char *C_PURGERX_S = "PurgeRx"; static const char *C_PURGETX_S = "PurgeTx"; +static const char *C_FLASHREPLY_S = "FlashReply"; #ifdef EOL #undef EOL @@ -572,6 +573,7 @@ static void cgusb_check_init() usb_commands[C_SETMODEM] = C_SETMODEM_S; usb_commands[C_PURGERX] = C_PURGERX_S; usb_commands[C_PURGETX] = C_PURGETX_S; + usb_commands[C_FLASHREPLY] = C_FLASHREPLY_S; stats_initialised = true; } @@ -1522,5 +1524,17 @@ int _usb_transfer(struct cgpu_info *cgpu, uint8_t request_type, uint8_t bRequest void usb_cleanup() { - // TODO: + int i; + + mutex_lock(&devices_lock); + for (i = 0; i < total_devices; i++) { + switch (devices[i]->drv->drv_id) { + case DRIVER_BITFORCE: + case DRIVER_MODMINER: + release_cgpu(devices[i]); + default: + break; + } + } + mutex_unlock(&devices_lock); } diff --git a/usbutils.h b/usbutils.h index 1ec19360..fc6340f0 100644 --- a/usbutils.h +++ b/usbutils.h @@ -122,6 +122,7 @@ enum usb_cmds { C_SETMODEM, C_PURGERX, C_PURGETX, + C_FLASHREPLY, C_MAX };