void usbc_core_notify_func_wk_ability(kal_uint8 class_device_id, kal_bool ability) { usbc_core_t *pUsbCore = usbc_core_get_instance(); kal_bool isCapableWk = KAL_FALSE; // check the capability of the class device if ( NULL != pUsbCore->class_device[class_device_id].query_func_wk_status) { isCapableWk = ((pUsbCore->class_device[class_device_id].query_func_wk_status(class_device_id) & (kal_uint8)0x01) == 0x01)? KAL_TRUE:KAL_FALSE; } if( ability && !isCapableWk ) { usbc_trace_error(USBCORE_NOTIFY_WK_ABILITY_INVALID, pUsbCore->class_device[class_device_id].class_type); ASSERT(0); return; } if ( USBC_CORE_CLASS_DEVICE_STATE_REGISTERED == pUsbCore->class_device[class_device_id].state && NULL != pUsbCore->class_device[class_device_id].notify_func_wk_ability ) { usbc_trace_info(USBCORE_NOTIFY_WK_ABILITY_START, pUsbCore->class_device[class_device_id].class_type); pUsbCore->class_device[class_device_id].notify_func_wk_ability(class_device_id, ability); usbc_trace_info(USBCORE_NOTIFY_WK_ABILITY_END, pUsbCore->class_device[class_device_id].class_type); } }
kal_bool usbc_class_device_func_remote_wk(kal_uint8 class_device_id) { usbc_core_t* pUsbCore = usbc_core_get_instance(); kal_bool isDeviceSuspend; usbc_ind_t ind_to_enqueue; usbc_func_state_e state; usbc_trace_info(USBCORE_REMOTE_WK_START, class_device_id); USBC_NON_EXCEPTION_MODE_CHECK(); USBC_CLASS_DEVICE_CONTEXT_CHECK(); /* Check whether the requested function is capable to wakeup the host and remote wakeup is enabled. Return KAL_FALSE if the function is not valid to wakeup host */ if ( pUsbCore->class_device[class_device_id].query_func_wk_status(class_device_id) != 0x03 ) { usbc_trace_error(USBCORE_REMOTE_WK_INVALID, class_device_id, pUsbCore->class_device[class_device_id].query_func_wk_status(class_device_id)); ASSERT(0); return KAL_FALSE; } // check for the remote wakeup once a function at the same time USBC_CLASS_REMOTE_WK_LOCK(pUsbCore->usbc_class_remote_wk_mutex); // reset the status of function accessing of class device id USBC_CLASS_REMOTE_WK_LOCK(pUsbCore->usbc_class_func_access_mutex); pUsbCore->is_func_be_accessed[class_device_id] = KAL_FALSE; USBC_CLASS_REMOTE_WK_UNLOCK(pUsbCore->usbc_class_func_access_mutex); isDeviceSuspend = (pUsbCore->state == USBC_USB_STATE_SUSPENDED)? KAL_TRUE:KAL_FALSE; /* If it is resumed from device suspend, then send hifusb_remote_wakeup first and wait for the resume callback to know LPM state to U0. If it is resumed from function suspend, then send notification to resume the suspended function in USB Core context. */ if ( isDeviceSuspend ) { usbc_trace_info(USBCORE_REMOTE_WK_DEVICE, class_device_id); usb_idle_set_clockGating(KAL_FALSE); // nofity USBIDLE that it does not have to gate the clock of USB IP usbc_normal_hif_remote_wakeup(); } //else if ( pUsbCore->class_device[class_device_id].is_func_suspend ) if ( pUsbCore->class_device[class_device_id].is_func_suspend ) { // block until device resume while ( isDeviceSuspend ) { kal_sleep_task(USBC_DEV_RESUME_DURATION_TICK); isDeviceSuspend = (pUsbCore->state == USBC_USB_STATE_SUSPENDED)? KAL_TRUE:KAL_FALSE; usbc_trace_warn(USBCORE_REMOTE_WK_DEVICE_WAIT, class_device_id); } usbc_trace_info(USBCORE_REMOTE_WK_FUNC, class_device_id); // send callback to notify class device of resuming state = USBC_FUNC_STATE_RESUME; // Enqueue USB function state which will be handled in USB context later. ind_to_enqueue.type = USBC_IND_FUNC_EVENT; ind_to_enqueue.ext = class_device_id; ind_to_enqueue.data = (kal_uint8)state; usbc_enqueue_ind(&ind_to_enqueue); // Wake up USBCORE task to process indications. hmu_hifeg_set(HIF_DRV_EG_USBC_IND_EVENT); } // release for the remote wakeup of a function USBC_CLASS_REMOTE_WK_UNLOCK(pUsbCore->usbc_class_remote_wk_mutex); // call HIF driver API to send function wakeup notification, and resend if needed if ( pUsbCore->speed == USBC_USB_SPEED_USB30 ) { usbc_set_wk_notify_timer(class_device_id); } return KAL_TRUE; }