203 is calling this function during the transition to the A_PERIPHERAL state, |
209 is calling this function during the transition to the A_PERIPHERAL state, |
204 i.e. when acting as an A-device. |
210 i.e. when acting as an A-device. |
205 */ |
211 */ |
206 EXPORT_C void DUsbClientController::EnableClientStack() |
212 EXPORT_C void DUsbClientController::EnableClientStack() |
207 { |
213 { |
208 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnableClientStack()")); |
214 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK, "DUsbClientController::EnableClientStack()" ); |
209 if (iStackIsActive) |
215 if (iStackIsActive) |
210 { |
216 { |
211 __KTRACE_OPT(KUSB, Kern::Printf(" Already enabled - returning")); |
217 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP1, " Already enabled - returning" ); |
212 return; |
218 return; |
213 } |
219 } |
214 iStackIsActive = ETrue; |
220 iStackIsActive = ETrue; |
215 // If the UDC is still off, we switch it on here. |
221 // If the UDC is still off, we switch it on here. |
216 TInt r = ActivateHardwareController(); |
222 TInt r = ActivateHardwareController(); |
217 if (r != KErrNone) |
223 if (r != KErrNone) |
218 { |
224 { |
219 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: ActivateHardwareController() failed: %d", r)); |
225 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP2, " Error: ActivateHardwareController() failed: %d", r); |
220 } |
226 } |
221 iOtgClientConnect = ETrue; |
227 iOtgClientConnect = ETrue; |
222 r = EvaluateOtgConnectFlags(); // may connect UDC |
228 r = EvaluateOtgConnectFlags(); // may connect UDC |
223 if (r != KErrNone) |
229 if (r != KErrNone) |
224 { |
230 { |
225 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: EvaluateOtgConnectFlags() failed: %d", r)); |
231 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP3, " Error: EvaluateOtgConnectFlags() failed: %d", r); |
226 } |
232 } |
227 } |
233 } |
228 |
234 |
229 |
235 |
230 /** Called by LDD to see if controller is usable. |
236 /** Called by LDD to see if controller is usable. |
231 |
237 |
232 @return ETrue if controller is in normal state, EFalse if it is disabled. |
238 @return ETrue if controller is in normal state, EFalse if it is disabled. |
233 */ |
239 */ |
234 EXPORT_C TBool DUsbClientController::IsActive() |
240 EXPORT_C TBool DUsbClientController::IsActive() |
235 { |
241 { |
236 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::IsActive()")); |
242 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ISACTIVE, "DUsbClientController::IsActive()" ); |
237 return iStackIsActive; |
243 return iStackIsActive; |
238 } |
244 } |
239 |
245 |
240 |
246 |
241 /** Called by LDD to register client callbacks. |
247 /** Called by LDD to register client callbacks. |
242 |
248 |
243 @return KErrNone if successful, KErrAlreadyExists callback exists. |
249 @return KErrNone if successful, KErrAlreadyExists callback exists. |
244 */ |
250 */ |
245 EXPORT_C TInt DUsbClientController::RegisterClientCallback(TUsbcClientCallback& aCallback) |
251 EXPORT_C TInt DUsbClientController::RegisterClientCallback(TUsbcClientCallback& aCallback) |
246 { |
252 { |
247 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterClientCallback()")); |
253 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK, "DUsbClientController::RegisterClientCallback()" ); |
248 if (iClientCallbacks.Elements() == KUsbcMaxListLength) |
254 if (iClientCallbacks.Elements() == KUsbcMaxListLength) |
249 { |
255 { |
250 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Maximum list length reached: %d", |
256 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK_DUP1, " Error: Maximum list length reached: %d", |
251 KUsbcMaxListLength)); |
257 KUsbcMaxListLength); |
|
258 |
252 return KErrGeneral; |
259 return KErrGeneral; |
253 } |
260 } |
254 TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
261 TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
255 TUsbcClientCallback* p; |
262 TUsbcClientCallback* p; |
256 while ((p = iter++) != NULL) |
263 while ((p = iter++) != NULL) |
257 if (p == &aCallback) |
264 if (p == &aCallback) |
258 { |
265 { |
259 __KTRACE_OPT(KUSB, Kern::Printf(" Error: ClientCallback @ 0x%x already registered", &aCallback)); |
266 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK_DUP2, " Error: ClientCallback @ 0x%x already registered", &aCallback); |
260 return KErrAlreadyExists; |
267 return KErrAlreadyExists; |
261 } |
268 } |
262 iClientCallbacks.AddLast(aCallback); |
269 iClientCallbacks.AddLast(aCallback); |
263 return KErrNone; |
270 return KErrNone; |
264 } |
271 } |
295 TUsbcEndpointData elements; there are TUsbDeviceCaps::iTotalEndpoints elements in the array; |
302 TUsbcEndpointData elements; there are TUsbDeviceCaps::iTotalEndpoints elements in the array; |
296 call DeviceCaps() to get the number of elements required. |
303 call DeviceCaps() to get the number of elements required. |
297 */ |
304 */ |
298 EXPORT_C void DUsbClientController::EndpointCaps(const DBase* aClientId, TDes8& aCapsBuf) const |
305 EXPORT_C void DUsbClientController::EndpointCaps(const DBase* aClientId, TDes8& aCapsBuf) const |
299 { |
306 { |
300 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EndpointCaps()")); |
307 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENDPOINTCAPS, "DUsbClientController::EndpointCaps()" ); |
301 // Here we do not simply call DUsbClientController::DeviceEndpointCaps(), |
308 // Here we do not simply call DUsbClientController::DeviceEndpointCaps(), |
302 // because that function fills an array which comprises of _all_ endpoints, |
309 // because that function fills an array which comprises of _all_ endpoints, |
303 // whereas this function omits ep0 and all unusable endpoints. |
310 // whereas this function omits ep0 and all unusable endpoints. |
304 // Apart from that, we have to fill an array of TUsbcEndpointData, not TUsbcEndpointCaps. |
311 // Apart from that, we have to fill an array of TUsbcEndpointData, not TUsbcEndpointCaps. |
305 TUsbcEndpointData data[KUsbcMaxEndpoints]; |
312 TUsbcEndpointData data[KUsbcMaxEndpoints]; |
306 const TInt ifcset_num = ClientId2InterfaceNumber(aClientId); |
313 const TInt ifcset_num = ClientId2InterfaceNumber(aClientId); |
307 for (TInt i = 2, j = 0; i < iDeviceTotalEndpoints; ++i) |
314 for (TInt i = 2, j = 0; i < iDeviceTotalEndpoints; ++i) |
308 { |
315 { |
309 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Caps: RealEndpoint #%d", i)); |
316 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTCAPS_DUP1, "DUsbClientController::Caps: RealEndpoint #%d", i); |
310 if (iRealEndpoints[i].iCaps.iTypesAndDir != KUsbEpNotAvailable) |
317 if (iRealEndpoints[i].iCaps.iTypesAndDir != KUsbEpNotAvailable) |
311 { |
318 { |
312 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Caps: --> UsableEndpoint #%d", j)); |
319 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTCAPS_DUP2, "DUsbClientController::Caps: --> UsableEndpoint #%d", j); |
313 data[j].iCaps = iRealEndpoints[i].iCaps; |
320 data[j].iCaps = iRealEndpoints[i].iCaps; |
314 if (ifcset_num < 0) |
321 if (ifcset_num < 0) |
315 { |
322 { |
316 // If this LDD doesn't own an interface, but the Ep points to one, |
323 // If this LDD doesn't own an interface, but the Ep points to one, |
317 // then that must be the interface of a different LDD. Hence the Ep |
324 // then that must be the interface of a different LDD. Hence the Ep |
433 TInt aInterfaceNum, TUsbcClassInfo& aClass, |
440 TInt aInterfaceNum, TUsbcClassInfo& aClass, |
434 TDesC8* aString, TInt aTotalEndpointsUsed, |
441 TDesC8* aString, TInt aTotalEndpointsUsed, |
435 const TUsbcEndpointInfoArray aEndpointData, |
442 const TUsbcEndpointInfoArray aEndpointData, |
436 TInt aRealEpNumbers[], TUint32 aFeatureWord) |
443 TInt aRealEpNumbers[], TUint32 aFeatureWord) |
437 { |
444 { |
438 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetInterface()")); |
445 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETINTERFACE, "DUsbClientController::SetInterface()" ); |
439 if (aInterfaceNum != 0) |
446 if (aInterfaceNum != 0) |
440 { |
447 { |
441 __KTRACE_OPT(KUSB, Kern::Printf(" alternate interface setting request: #%d", aInterfaceNum)); |
448 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP1, " alternate interface setting request: #%d", aInterfaceNum); |
|
449 |
442 } |
450 } |
443 #ifndef USB_SUPPORTS_CONTROLENDPOINTS |
451 #ifndef USB_SUPPORTS_CONTROLENDPOINTS |
444 for (TInt i = 0; i < aTotalEndpointsUsed; ++i) |
452 for (TInt i = 0; i < aTotalEndpointsUsed; ++i) |
445 { |
453 { |
446 if (aEndpointData[i].iType == KUsbEpTypeControl) |
454 if (aEndpointData[i].iType == KUsbEpTypeControl) |
447 { |
455 { |
448 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: control endpoints not supported")); |
456 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP2, " Error: control endpoints not supported"); |
449 return KErrNotSupported; |
457 return KErrNotSupported; |
450 } |
458 } |
451 } |
459 } |
452 #endif |
460 #endif |
453 // Check for endpoint availability & check those endpoint's capabilities |
461 // Check for endpoint availability & check those endpoint's capabilities |
454 const TInt ifcset_num = ClientId2InterfaceNumber(aClientId); |
462 const TInt ifcset_num = ClientId2InterfaceNumber(aClientId); |
455 // The passed-in ifcset_num may be -1 now, but that's intended. |
463 // The passed-in ifcset_num may be -1 now, but that's intended. |
456 if (!CheckEpAvailability(aTotalEndpointsUsed, aEndpointData, ifcset_num)) |
464 if (!CheckEpAvailability(aTotalEndpointsUsed, aEndpointData, ifcset_num)) |
457 { |
465 { |
458 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: endpoints not (all) available")); |
466 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP3, " Error: endpoints not (all) available"); |
459 return KErrInUse; |
467 return KErrInUse; |
460 } |
468 } |
461 // Create & setup new interface |
469 // Create & setup new interface |
462 TUsbcInterface* ifc = CreateInterface(aClientId, aInterfaceNum, aFeatureWord); |
470 TUsbcInterface* ifc = CreateInterface(aClientId, aInterfaceNum, aFeatureWord); |
463 if (ifc == NULL) |
471 if (ifc == NULL) |
464 { |
472 { |
465 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: ifc == NULL")); |
473 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP4, " Error: ifc == NULL"); |
466 return KErrGeneral; |
474 return KErrGeneral; |
467 } |
475 } |
468 // Create logical endpoints |
476 // Create logical endpoints |
469 TInt r = CreateEndpoints(ifc, aTotalEndpointsUsed, aEndpointData, aRealEpNumbers); |
477 TInt r = CreateEndpoints(ifc, aTotalEndpointsUsed, aEndpointData, aRealEpNumbers); |
470 if (r != KErrNone) |
478 if (r != KErrNone) |
471 { |
479 { |
472 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: CreateEndpoints() != KErrNone")); |
480 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP5, " Error: CreateEndpoints() != KErrNone"); |
473 DeleteInterface(ifc->iInterfaceSet->iInterfaceNumber, aInterfaceNum); |
481 DeleteInterface(ifc->iInterfaceSet->iInterfaceNumber, aInterfaceNum); |
474 return r; |
482 return r; |
475 } |
483 } |
476 // Create & setup interface, string, and endpoint descriptors |
484 // Create & setup interface, string, and endpoint descriptors |
477 r = SetupIfcDescriptor(ifc, aClass, aThread, aString, aEndpointData); |
485 r = SetupIfcDescriptor(ifc, aClass, aThread, aString, aEndpointData); |
494 invalid interface setting number is specified (not existing or existing but too small), KErrNone if |
502 invalid interface setting number is specified (not existing or existing but too small), KErrNone if |
495 interface successfully released or if this client doesn't own any interface. |
503 interface successfully released or if this client doesn't own any interface. |
496 */ |
504 */ |
497 EXPORT_C TInt DUsbClientController::ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum) |
505 EXPORT_C TInt DUsbClientController::ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum) |
498 { |
506 { |
499 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ReleaseInterface(..., %d)", aInterfaceNum)); |
507 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE, "DUsbClientController::ReleaseInterface(..., %d)", aInterfaceNum); |
|
508 |
500 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
509 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
501 if (ifcset < 0) |
510 if (ifcset < 0) |
502 { |
511 { |
503 __KTRACE_OPT(KUSB, Kern::Printf(" interface not found")); // no error |
512 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP1, " interface not found"); |
504 return KErrNone; |
513 return KErrNone; |
505 } |
514 } |
506 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
515 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
507 if (!ifcset_ptr) |
516 if (!ifcset_ptr) |
508 { |
517 { |
509 __KTRACE_OPT(KUSB, Kern::Printf(" Error: interface number %d doesn't exist", ifcset)); |
518 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP2, "Error: interface number %d doesn't exist", ifcset); |
510 return KErrNotFound; |
519 return KErrNotFound; |
511 } |
520 } |
512 const TInt setting_count = ifcset_ptr->iInterfaces.Count(); |
521 const TInt setting_count = ifcset_ptr->iInterfaces.Count(); |
513 if ((setting_count - 1) != aInterfaceNum) |
522 if ((setting_count - 1) != aInterfaceNum) |
514 { |
523 { |
515 __KTRACE_OPT(KUSB, |
524 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP3, "> Error: interface settings must be released in descending order:\n\r" |
516 Kern::Printf(" > Error: interface settings must be released in descending order:\n\r" |
525 " %d setting(s) exist, #%d was requested to be released.\n\r" |
517 " %d setting(s) exist, #%d was requested to be released.\n\r" |
526 " (#%d has to be released first)", |
518 " (#%d has to be released first)", |
527 setting_count, aInterfaceNum, setting_count - 1); |
519 setting_count, aInterfaceNum, setting_count - 1)); |
|
520 return KErrArgument; |
528 return KErrArgument; |
521 } |
529 } |
522 // Tear down current setting (invalidate configured state) |
530 // Tear down current setting (invalidate configured state) |
523 __KTRACE_OPT(KUSB, Kern::Printf(" > tearing down InterfaceSet %d", ifcset)); |
531 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP4, " > tearing down InterfaceSet %d", ifcset); |
524 // Cancel all transfers on the current setting of this interface and deconfigure all its endpoints. |
532 // Cancel all transfers on the current setting of this interface and deconfigure all its endpoints. |
525 InterfaceSetTeardown(ifcset_ptr); |
533 InterfaceSetTeardown(ifcset_ptr); |
526 // 'Setting 0' means: delete all existing settings. |
534 // 'Setting 0' means: delete all existing settings. |
527 if (aInterfaceNum == 0) |
535 if (aInterfaceNum == 0) |
528 { |
536 { |
586 |
594 |
587 This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue. |
595 This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue. |
588 */ |
596 */ |
589 EXPORT_C TInt DUsbClientController::ReEnumerate() |
597 EXPORT_C TInt DUsbClientController::ReEnumerate() |
590 { |
598 { |
591 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ReEnumerate()")); |
599 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REENUMERATE, "DUsbClientController::ReEnumerate()" ); |
592 // If, in an OTG setup, the client stack is disabled, there's no point in |
600 // If, in an OTG setup, the client stack is disabled, there's no point in |
593 // trying to reenumerate the device. In fact, we then don't even want to |
601 // trying to reenumerate the device. In fact, we then don't even want to |
594 // turn on the UDC via ActivateHardwareController(). |
602 // turn on the UDC via ActivateHardwareController(). |
595 if (!iStackIsActive) |
603 if (!iStackIsActive) |
596 { |
604 { |
597 __KTRACE_OPT(KUSB, Kern::Printf(" Client stack disabled -> returning here")); |
605 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP1, " Client stack disabled -> returning here" ); |
598 return KErrNotReady; |
606 return KErrNotReady; |
599 } |
607 } |
600 // We probably don't check here whether SoftConnectCaps() is ETrue, and |
608 // We probably don't check here whether SoftConnectCaps() is ETrue, and |
601 // return if not, because we might still want to execute |
609 // return if not, because we might still want to execute |
602 // ActivateHardwareController(). UsbConnect() and UsbDisconnect() should be |
610 // ActivateHardwareController(). UsbConnect() and UsbDisconnect() should be |
603 // no-ops if not supported by the PSL. |
611 // no-ops if not supported by the PSL. |
604 if (iConfigs[0]->iInterfaceSets.Count() == 0) |
612 if (iConfigs[0]->iInterfaceSets.Count() == 0) |
605 { |
613 { |
606 __KTRACE_OPT(KUSB, Kern::Printf(" > No interface registered -> no need to re-enumerate")); |
614 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP2, " > No interface registered -> no need to re-enumerate" ); |
607 return KErrNone;; |
615 return KErrNone;; |
608 } |
616 } |
609 if (!iHardwareActivated) |
617 if (!iHardwareActivated) |
610 { |
618 { |
611 // If the UDC is still off, we switch it on here. |
619 // If the UDC is still off, we switch it on here. |
612 const TInt r = ActivateHardwareController(); |
620 const TInt r = ActivateHardwareController(); |
613 if (r != KErrNone) |
621 if (r != KErrNone) |
614 { |
622 { |
615 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: ActivateHardwareController() failed: %d", r)); |
623 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP3, " Error: ActivateHardwareController() failed: %d", r); |
616 return r; |
624 return r; |
617 } |
625 } |
618 // Finally connect the device to the bus |
626 // Finally connect the device to the bus |
619 UsbConnect(); |
627 UsbConnect(); |
620 } |
628 } |
636 interfaces have been registered yet, KErrHardwareNotAvailable if UDC |
644 interfaces have been registered yet, KErrHardwareNotAvailable if UDC |
637 couldn't be activated. |
645 couldn't be activated. |
638 */ |
646 */ |
639 EXPORT_C TInt DUsbClientController::PowerUpUdc() |
647 EXPORT_C TInt DUsbClientController::PowerUpUdc() |
640 { |
648 { |
641 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerUpUdc()")); |
649 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUPUDC, "DUsbClientController::PowerUpUdc()" ); |
642 // If, in an OTG setup, the client stack is disabled, we mustn't turn on |
650 // If, in an OTG setup, the client stack is disabled, we mustn't turn on |
643 // the UDC via ActivateHardwareController() as that would already configure |
651 // the UDC via ActivateHardwareController() as that would already configure |
644 // Ep0. |
652 // Ep0. |
645 if (!iStackIsActive) |
653 if (!iStackIsActive) |
646 { |
654 { |
647 __KTRACE_OPT(KUSB, Kern::Printf(" Client stack disabled -> returning here")); |
655 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP1, " Client stack disabled -> returning here" ); |
648 return KErrNotReady; |
656 return KErrNotReady; |
649 } |
657 } |
650 if (iConfigs[0]->iInterfaceSets.Count() == 0) |
658 if (iConfigs[0]->iInterfaceSets.Count() == 0) |
651 { |
659 { |
652 __KTRACE_OPT(KUSB, Kern::Printf(" > No interface registered -> won't power up UDC")); |
660 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP2, " > No interface registered -> won't power up UDC" ); |
653 return KErrNotReady; |
661 return KErrNotReady; |
654 } |
662 } |
655 // If the UDC is still off, we switch it on here. |
663 // If the UDC is still off, we switch it on here. |
656 const TInt r = ActivateHardwareController(); |
664 const TInt r = ActivateHardwareController(); |
657 if (r != KErrNone) |
665 if (r != KErrNone) |
658 { |
666 { |
659 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: ActivateHardwareController() failed: %d", r)); |
667 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP3, " Error: ActivateHardwareController() failed: %d", r); |
660 } |
668 } |
661 return r; |
669 return r; |
662 } |
670 } |
663 |
671 |
664 |
672 |
759 |
767 |
760 @return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
768 @return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
761 */ |
769 */ |
762 EXPORT_C TInt DUsbClientController::DeRegisterForStatusChange(const DBase* aClientId) |
770 EXPORT_C TInt DUsbClientController::DeRegisterForStatusChange(const DBase* aClientId) |
763 { |
771 { |
764 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterForStatusChange()")); |
772 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE, "DUsbClientController::DeRegisterForStatusChange()" ); |
765 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
773 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
766 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
774 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
767 TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks); |
775 TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks); |
768 TUsbcStatusCallback* p; |
776 TUsbcStatusCallback* p; |
769 while ((p = iter++) != NULL) |
777 while ((p = iter++) != NULL) |
770 { |
778 { |
771 if (p->Owner() == aClientId) |
779 if (p->Owner() == aClientId) |
772 { |
780 { |
773 __KTRACE_OPT(KUSB, Kern::Printf(" removing StatusCallback @ 0x%x", p)); |
781 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE_DUP1, " removing StatusCallback @ 0x%x", p); |
774 iStatusCallbacks.Remove(*p); |
782 iStatusCallbacks.Remove(*p); |
775 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
783 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
776 return KErrNone; |
784 return KErrNone; |
777 } |
785 } |
778 } |
786 } |
779 __KTRACE_OPT(KUSB, Kern::Printf(" client not found")); |
787 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE_DUP2, " client not found"); |
780 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
788 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
781 return KErrNotFound; |
789 return KErrNotFound; |
782 } |
790 } |
783 |
791 |
784 |
792 |
797 @return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered |
805 @return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered |
798 (it won't be registered twice). |
806 (it won't be registered twice). |
799 */ |
807 */ |
800 EXPORT_C TInt DUsbClientController::RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback) |
808 EXPORT_C TInt DUsbClientController::RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback) |
801 { |
809 { |
802 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterForEndpointStatusChange()")); |
810 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE, "DUsbClientController::RegisterForEndpointStatusChange()" ); |
803 if (iEpStatusCallbacks.Elements() == KUsbcMaxListLength) |
811 if (iEpStatusCallbacks.Elements() == KUsbcMaxListLength) |
804 { |
812 { |
805 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Maximum list length reached: %d", |
813 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE_DUP1, " Error: Maximum list length reached: %d", |
806 KUsbcMaxListLength)); |
814 KUsbcMaxListLength); |
|
815 |
807 return KErrGeneral; |
816 return KErrGeneral; |
808 } |
817 } |
809 if (IsInTheEpStatusList(aCallback)) |
818 if (IsInTheEpStatusList(aCallback)) |
810 { |
819 { |
811 __KTRACE_OPT(KUSB, Kern::Printf(" Error: EpStatusCallback @ 0x%x already registered", &aCallback)); |
820 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE_DUP2, " Error: EpStatusCallback @ 0x%x already registered", &aCallback); |
812 return KErrGeneral; |
821 return KErrGeneral; |
813 } |
822 } |
814 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
823 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
815 iEpStatusCallbacks.AddLast(aCallback); |
824 iEpStatusCallbacks.AddLast(aCallback); |
816 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
825 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
825 |
834 |
826 @return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
835 @return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
827 */ |
836 */ |
828 EXPORT_C TInt DUsbClientController::DeRegisterForEndpointStatusChange(const DBase* aClientId) |
837 EXPORT_C TInt DUsbClientController::DeRegisterForEndpointStatusChange(const DBase* aClientId) |
829 { |
838 { |
830 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterForEndpointStatusChange()")); |
839 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE, "DUsbClientController::DeRegisterForEndpointStatusChange()" ); |
831 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
840 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
832 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
841 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
833 TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
842 TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
834 TUsbcEndpointStatusCallback* p; |
843 TUsbcEndpointStatusCallback* p; |
835 while ((p = iter++) != NULL) |
844 while ((p = iter++) != NULL) |
836 { |
845 { |
837 if (p->Owner() == aClientId) |
846 if (p->Owner() == aClientId) |
838 { |
847 { |
839 __KTRACE_OPT(KUSB, Kern::Printf(" removing EpStatusCallback @ 0x%x", p)); |
848 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE_DUP1, " removing EpStatusCallback @ 0x%x", p); |
840 iEpStatusCallbacks.Remove(*p); |
849 iEpStatusCallbacks.Remove(*p); |
841 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
850 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
842 return KErrNone; |
851 return KErrNone; |
843 } |
852 } |
844 } |
853 } |
845 __KTRACE_OPT(KUSB, Kern::Printf(" client not found")); |
854 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE_DUP2, " client not found"); |
846 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
855 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
847 return KErrNotFound; |
856 return KErrNotFound; |
848 } |
857 } |
849 |
858 |
850 |
859 |
1006 (but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if |
1018 (but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if |
1007 endpoint number invalid (PSL), KErrGeneral if something else goes wrong. |
1019 endpoint number invalid (PSL), KErrGeneral if something else goes wrong. |
1008 */ |
1020 */ |
1009 EXPORT_C TInt DUsbClientController::SetupReadBuffer(TUsbcRequestCallback& aCallback) |
1021 EXPORT_C TInt DUsbClientController::SetupReadBuffer(TUsbcRequestCallback& aCallback) |
1010 { |
1022 { |
1011 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetupReadBuffer()")); |
1023 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPREADBUFFER, "DUsbClientController::SetupReadBuffer()" ); |
1012 const TInt ep = aCallback.iRealEpNum; |
1024 const TInt ep = aCallback.iRealEpNum; |
1013 __KTRACE_OPT(KUSB, Kern::Printf(" logical ep: #%d", aCallback.iEndpointNum)); |
1025 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP1, " logical ep: #%d", aCallback.iEndpointNum); |
1014 __KTRACE_OPT(KUSB, Kern::Printf(" real ep: #%d", ep)); |
1026 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP2, " real ep: #%d", ep); |
1015 TInt err = KErrGeneral; |
1027 TInt err = KErrGeneral; |
1016 if (ep != 0) |
1028 if (ep != 0) |
1017 { |
1029 { |
1018 if (iRequestCallbacks[ep]) |
1030 if (iRequestCallbacks[ep]) |
1019 { |
1031 { |
1020 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: RequestCallback already registered for that ep")); |
1032 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP3, " Warning: RequestCallback already registered for that ep"); |
1021 if (iRequestCallbacks[ep] == &aCallback) |
1033 if (iRequestCallbacks[ep] == &aCallback) |
1022 { |
1034 { |
1023 __KTRACE_OPT(KPANIC, Kern::Printf(" (this same RequestCallback @ 0x%x)", &aCallback)); |
1035 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP4, " (this same RequestCallback @ 0x%x)", &aCallback); |
1024 } |
1036 } |
1025 else |
1037 else |
1026 { |
1038 { |
1027 __KTRACE_OPT(KPANIC, Kern::Printf(" (a different RequestCallback @ 0x%x)", &aCallback)); |
1039 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP5, " (a different RequestCallback @ 0x%x)", &aCallback); |
1028 } |
1040 } |
1029 return KErrNone; |
1041 return KErrNone; |
1030 } |
1042 } |
1031 // This may seem awkward: |
1043 // This may seem awkward: |
1032 // First we add a callback, and then, in case of an error, we remove it again. |
1044 // First we add a callback, and then, in case of an error, we remove it again. |
1033 // However this is necessary because the transfer request might complete (through |
1045 // However this is necessary because the transfer request might complete (through |
1034 // an ISR) _before_ the SetupEndpointRead function returns. Since we don't know the |
1046 // an ISR) _before_ the SetupEndpointRead function returns. Since we don't know the |
1035 // outcome, we have to provide the callback before making the setup call. |
1047 // outcome, we have to provide the callback before making the setup call. |
1036 // |
1048 // |
1037 __KTRACE_OPT(KUSB, Kern::Printf(" adding RequestCallback[%d] @ 0x%x", ep, &aCallback)); |
1049 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP6, " adding RequestCallback[%d] @ 0x%x", ep, (TUint)&aCallback); |
1038 iRequestCallbacks[ep] = &aCallback; |
1050 iRequestCallbacks[ep] = &aCallback; |
1039 if ((err = SetupEndpointRead(ep, aCallback)) != KErrNone) |
1051 if ((err = SetupEndpointRead(ep, aCallback)) != KErrNone) |
1040 { |
1052 { |
1041 __KTRACE_OPT(KPANIC, Kern::Printf(" removing RequestCallback @ 0x%x (due to error)", |
1053 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP7, " removing RequestCallback @ 0x%x (due to error)", |
1042 &aCallback)); |
1054 &aCallback); |
1043 iRequestCallbacks[ep] = NULL; |
1055 iRequestCallbacks[ep] = NULL; |
1044 } |
1056 } |
1045 } |
1057 } |
1046 else // (ep == 0) |
1058 else // (ep == 0) |
1047 { |
1059 { |
1048 if (iEp0ReadRequestCallbacks.Elements() == KUsbcMaxListLength) |
1060 if (iEp0ReadRequestCallbacks.Elements() == KUsbcMaxListLength) |
1049 { |
1061 { |
1050 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Maximum list length reached: %d", |
1062 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP8, " Error: Maximum list length reached: %d", |
1051 KUsbcMaxListLength)); |
1063 KUsbcMaxListLength); |
1052 return KErrGeneral; |
1064 return KErrGeneral; |
1053 } |
1065 } |
1054 if (IsInTheRequestList(aCallback)) |
1066 if (IsInTheRequestList(aCallback)) |
1055 { |
1067 { |
1056 __KTRACE_OPT(KUSB, Kern::Printf(" RequestCallback @ 0x%x already registered", &aCallback)); |
1068 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP9, " RequestCallback @ 0x%x already registered", &aCallback); |
1057 return KErrNone; |
1069 return KErrNone; |
1058 } |
1070 } |
1059 // Ep0 reads don't need to be prepared - there's always one pending |
1071 // Ep0 reads don't need to be prepared - there's always one pending |
1060 __KTRACE_OPT(KUSB, Kern::Printf(" adding RequestCallback @ 0x%x (ep0)", &aCallback)); |
1072 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP10, " adding RequestCallback @ 0x%x (ep0)", &aCallback); |
1061 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
1073 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
1062 iEp0ReadRequestCallbacks.AddLast(aCallback); |
1074 iEp0ReadRequestCallbacks.AddLast(aCallback); |
1063 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1075 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1064 err = KErrNone; |
1076 err = KErrNone; |
1065 if (iEp0_RxExtraData) |
1077 if (iEp0_RxExtraData) |
1066 { |
1078 { |
1067 __KTRACE_OPT(KUSB, Kern::Printf(" iEp0_RxExtraData: trying again...")); |
1079 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP11, " iEp0_RxExtraData: trying again..."); |
1068 const TBool rx_data = iEp0DataReceiving; |
1080 const TBool rx_data = iEp0DataReceiving; |
1069 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
1081 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
1070 err = ProcessEp0ReceiveDone(iEp0_RxExtraCount); |
1082 err = ProcessEp0ReceiveDone(iEp0_RxExtraCount); |
1071 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1083 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1072 if (err == KErrNone) |
1084 if (err == KErrNone) |
1104 (but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if |
1116 (but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if |
1105 endpoint number invalid (PSL), KErrGeneral if something else goes wrong. |
1117 endpoint number invalid (PSL), KErrGeneral if something else goes wrong. |
1106 */ |
1118 */ |
1107 EXPORT_C TInt DUsbClientController::SetupWriteBuffer(TUsbcRequestCallback& aCallback) |
1119 EXPORT_C TInt DUsbClientController::SetupWriteBuffer(TUsbcRequestCallback& aCallback) |
1108 { |
1120 { |
1109 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetupWriteBuffer()")); |
1121 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER, "DUsbClientController::SetupWriteBuffer()" ); |
1110 TInt ep = aCallback.iRealEpNum; |
1122 TInt ep = aCallback.iRealEpNum; |
1111 __KTRACE_OPT(KUSB, Kern::Printf(" logical ep: #%d", aCallback.iEndpointNum)); |
1123 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP1, " logical ep: #%d", aCallback.iEndpointNum); |
1112 __KTRACE_OPT(KUSB, Kern::Printf(" real ep: #%d", ep)); |
1124 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP2, " real ep: #%d", ep); |
|
1125 |
1113 if (iRequestCallbacks[ep]) |
1126 if (iRequestCallbacks[ep]) |
1114 { |
1127 { |
1115 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: RequestCallback already registered for that ep")); |
1128 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP3, " Warning: RequestCallback already registered for that ep"); |
1116 if (iRequestCallbacks[ep] == &aCallback) |
1129 if (iRequestCallbacks[ep] == &aCallback) |
1117 { |
1130 { |
1118 __KTRACE_OPT(KPANIC, Kern::Printf(" (this same RequestCallback @ 0x%x)", &aCallback)); |
1131 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP4, " (this same RequestCallback @ 0x%x)", &aCallback); |
1119 return KErrNone; |
1132 return KErrNone; |
1120 } |
1133 } |
1121 else |
1134 else |
1122 { |
1135 { |
1123 __KTRACE_OPT(KPANIC, Kern::Printf(" (a different RequestCallback @ 0x%x - poss. error)", |
1136 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP5, " (a different RequestCallback @ 0x%x - poss. error)", |
1124 &aCallback)); |
1137 &aCallback); |
1125 return KErrGeneral; |
1138 return KErrGeneral; |
1126 } |
1139 } |
1127 } |
1140 } |
1128 if (ep == 0) |
1141 if (ep == 0) |
1129 { |
1142 { |
1130 if (iEp0_TxNonStdCount) |
1143 if (iEp0_TxNonStdCount) |
1131 { |
1144 { |
1132 if (iEp0_TxNonStdCount > aCallback.iLength) |
1145 if (iEp0_TxNonStdCount > aCallback.iLength) |
1133 { |
1146 { |
1134 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: Ep0 is sending less data than requested")); |
1147 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP6, " Warning: Ep0 is sending less data than requested"); |
1135 if ((aCallback.iLength % iEp0MaxPacketSize == 0) && !aCallback.iZlpReqd) |
1148 if ((aCallback.iLength % iEp0MaxPacketSize == 0) && !aCallback.iZlpReqd) |
1136 { |
1149 { |
1137 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: Zlp should probably be requested")); |
1150 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP7, " Warning: Zlp should probably be requested"); |
1138 } |
1151 } |
1139 } |
1152 } |
1140 else if (iEp0_TxNonStdCount < aCallback.iLength) |
1153 else if (iEp0_TxNonStdCount < aCallback.iLength) |
1141 { |
1154 { |
1142 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: Ep0 is sending more data than requested")); |
1155 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP8, " Warning: Ep0 is sending more data than requested"); |
1143 } |
1156 } |
1144 iEp0_TxNonStdCount = 0; |
1157 iEp0_TxNonStdCount = 0; |
1145 } |
1158 } |
1146 // Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions. |
1159 // Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions. |
1147 ep = KEp0_Tx; |
1160 ep = KEp0_Tx; |
1149 // This may seem awkward: |
1162 // This may seem awkward: |
1150 // First we add a callback, and then, in case of an error, we remove it again. |
1163 // First we add a callback, and then, in case of an error, we remove it again. |
1151 // However this is necessary because the transfer request might complete (through |
1164 // However this is necessary because the transfer request might complete (through |
1152 // an ISR) _before_ the SetupEndpointWrite function returns. Since we don't know the |
1165 // an ISR) _before_ the SetupEndpointWrite function returns. Since we don't know the |
1153 // outcome, we have to provide the callback before making the setup call. |
1166 // outcome, we have to provide the callback before making the setup call. |
1154 // |
1167 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP9, " adding RequestCallback[%d] @ 0x%x", ep, (TUint)&aCallback); |
1155 __KTRACE_OPT(KUSB, Kern::Printf(" adding RequestCallback[%d] @ 0x%x", ep, &aCallback)); |
|
1156 iRequestCallbacks[ep] = &aCallback; |
1168 iRequestCallbacks[ep] = &aCallback; |
1157 if (ep == KEp0_Tx) |
1169 if (ep == KEp0_Tx) |
1158 { |
1170 { |
1159 iEp0ClientDataTransmitting = ETrue; // this must be set before calling SetupEndpointZeroWrite |
1171 iEp0ClientDataTransmitting = ETrue; // this must be set before calling SetupEndpointZeroWrite |
1160 if (SetupEndpointZeroWrite(aCallback.iBufferStart, aCallback.iLength, aCallback.iZlpReqd) != KErrNone) |
1172 if (SetupEndpointZeroWrite(aCallback.iBufferStart, aCallback.iLength, aCallback.iZlpReqd) != KErrNone) |
1161 { |
1173 { |
1162 __KTRACE_OPT(KPANIC, Kern::Printf(" removing RequestCallback @ 0x%x (due to error)", &aCallback)); |
1174 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP10, " removing RequestCallback @ 0x%x (due to error)", &aCallback); |
1163 iRequestCallbacks[ep] = NULL; |
1175 iRequestCallbacks[ep] = NULL; |
1164 iEp0ClientDataTransmitting = EFalse; |
1176 iEp0ClientDataTransmitting = EFalse; |
1165 } |
1177 } |
1166 } |
1178 } |
1167 else if (SetupEndpointWrite(ep, aCallback) != KErrNone) |
1179 else if (SetupEndpointWrite(ep, aCallback) != KErrNone) |
1168 { |
1180 { |
1169 __KTRACE_OPT(KPANIC, Kern::Printf(" removing RequestCallback @ 0x%x (due to error)", &aCallback)); |
1181 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP11, " removing RequestCallback @ 0x%x (due to error)", &aCallback); |
1170 iRequestCallbacks[ep] = NULL; |
1182 iRequestCallbacks[ep] = NULL; |
1171 } |
1183 } |
1172 return KErrNone; |
1184 return KErrNone; |
1173 } |
1185 } |
1174 |
1186 |
1360 @return KErrNotSupported if invalid size specified, KErrNone if new max packet size successfully set or |
1375 @return KErrNotSupported if invalid size specified, KErrNone if new max packet size successfully set or |
1361 requested size was already set. |
1376 requested size was already set. |
1362 */ |
1377 */ |
1363 EXPORT_C TInt DUsbClientController::SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize) |
1378 EXPORT_C TInt DUsbClientController::SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize) |
1364 { |
1379 { |
1365 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetEndpointZeroMaxPacketSize(%d)", |
1380 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE, "DUsbClientController::SetEndpointZeroMaxPacketSize(%d)", |
1366 aMaxPacketSize)); |
1381 aMaxPacketSize); |
|
1382 |
1367 |
1383 |
1368 if (DeviceHighSpeedCaps()) |
1384 if (DeviceHighSpeedCaps()) |
1369 { |
1385 { |
1370 // We're not going to mess with this on a HS device. |
1386 // We're not going to mess with this on a HS device. |
1371 return KErrNone; |
1387 return KErrNone; |
1372 } |
1388 } |
1373 |
1389 |
1374 if (!(iRealEndpoints[0].iCaps.iSizes & PacketSize2Mask(aMaxPacketSize))) |
1390 if (!(iRealEndpoints[0].iCaps.iSizes & PacketSize2Mask(aMaxPacketSize))) |
1375 { |
1391 { |
1376 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: invalid size")); |
1392 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE_DUP1, " Error: invalid size"); |
1377 return KErrNotSupported; |
1393 return KErrNotSupported; |
1378 } |
1394 } |
1379 if (iRealEndpoints[0].iLEndpoint->iEpSize_Fs == aMaxPacketSize) |
1395 if (iRealEndpoints[0].iLEndpoint->iEpSize_Fs == aMaxPacketSize) |
1380 { |
1396 { |
1381 __KTRACE_OPT(KUSB, Kern::Printf(" this packet size already set -> returning")); |
1397 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE_DUP2, " this packet size already set -> returning"); |
1382 return KErrNone; |
1398 return KErrNone; |
1383 } |
1399 } |
1384 const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint; |
1400 const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint; |
1385 const TUsbcLogicalEndpoint* const ep0_1 = iRealEndpoints[1].iLEndpoint; |
1401 const TUsbcLogicalEndpoint* const ep0_1 = iRealEndpoints[1].iLEndpoint; |
1386 const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iEpSize_Fs = aMaxPacketSize; |
1402 const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iEpSize_Fs = aMaxPacketSize; |
1546 return r; |
1562 return r; |
1547 } |
1563 } |
1548 // Check descriptor validity |
1564 // Check descriptor validity |
1549 if (otg[0] != KUsbDescSize_Otg || otg[1] != KUsbDescType_Otg || otg[2] > 3) |
1565 if (otg[0] != KUsbDescSize_Otg || otg[1] != KUsbDescType_Otg || otg[2] > 3) |
1550 { |
1566 { |
1551 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Invalid OTG descriptor")); |
1567 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP1, " Error: Invalid OTG descriptor" ); |
1552 return KErrGeneral; |
1568 return KErrGeneral; |
1553 } |
1569 } |
1554 __KTRACE_OPT(KUSB, Kern::Printf(" iOtgFuncMap before: 0x%x", iOtgFuncMap)); |
1570 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP2, " iOtgFuncMap before: 0x%x", iOtgFuncMap); |
1555 // Update value in controller as well |
1571 // Update value in controller as well |
1556 const TUint8 hnp = otg[2] & KUsbOtgAttr_HnpSupp; |
1572 const TUint8 hnp = otg[2] & KUsbOtgAttr_HnpSupp; |
1557 const TUint8 srp = otg[2] & KUsbOtgAttr_SrpSupp; |
1573 const TUint8 srp = otg[2] & KUsbOtgAttr_SrpSupp; |
1558 if (hnp && !srp) |
1574 if (hnp && !srp) |
1559 { |
1575 { |
1560 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: Invalid OTG attribute combination (HNP && !SRP")); |
1576 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP3, " Warning: Invalid OTG attribute combination (HNP && !SRP"); |
1561 } |
1577 } |
1562 if (hnp && !(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
1578 if (hnp && !(iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
1563 { |
1579 { |
1564 __KTRACE_OPT(KUSB, Kern::Printf(" Setting attribute KUsbOtgAttr_HnpSupp")); |
1580 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP4, " Setting attribute KUsbOtgAttr_HnpSupp"); |
1565 iOtgFuncMap |= KUsbOtgAttr_HnpSupp; |
1581 iOtgFuncMap |= KUsbOtgAttr_HnpSupp; |
1566 } |
1582 } |
1567 else if (!hnp && (iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
1583 else if (!hnp && (iOtgFuncMap & KUsbOtgAttr_HnpSupp)) |
1568 { |
1584 { |
1569 __KTRACE_OPT(KUSB, Kern::Printf(" Removing attribute KUsbOtgAttr_HnpSupp")); |
1585 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP5, " Removing attribute KUsbOtgAttr_HnpSupp"); |
1570 iOtgFuncMap &= ~KUsbOtgAttr_HnpSupp; |
1586 iOtgFuncMap &= ~KUsbOtgAttr_HnpSupp; |
1571 } |
1587 } |
1572 if (srp && !(iOtgFuncMap & KUsbOtgAttr_SrpSupp)) |
1588 if (srp && !(iOtgFuncMap & KUsbOtgAttr_SrpSupp)) |
1573 { |
1589 { |
1574 __KTRACE_OPT(KUSB, Kern::Printf(" Setting attribute KUsbOtgAttr_SrpSupp")); |
1590 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP6, " Setting attribute KUsbOtgAttr_SrpSupp"); |
1575 iOtgFuncMap |= KUsbOtgAttr_SrpSupp; |
1591 iOtgFuncMap |= KUsbOtgAttr_SrpSupp; |
1576 } |
1592 } |
1577 else if (!srp && (iOtgFuncMap & KUsbOtgAttr_SrpSupp)) |
1593 else if (!srp && (iOtgFuncMap & KUsbOtgAttr_SrpSupp)) |
1578 { |
1594 { |
1579 __KTRACE_OPT(KUSB, Kern::Printf(" Removing attribute KUsbOtgAttr_SrpSupp")); |
1595 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP7, " Removing attribute KUsbOtgAttr_SrpSupp"); |
1580 iOtgFuncMap &= ~KUsbOtgAttr_SrpSupp; |
1596 iOtgFuncMap &= ~KUsbOtgAttr_SrpSupp; |
1581 } |
1597 } |
1582 __KTRACE_OPT(KUSB, Kern::Printf(" iOtgFuncMap after: 0x%x", iOtgFuncMap)); |
1598 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP8, " iOtgFuncMap after: 0x%x", iOtgFuncMap); |
1583 return iDescriptors.SetOtgDescriptor(otg); |
1599 return iDescriptors.SetOtgDescriptor(otg); |
1584 } |
1600 } |
1585 |
1601 |
1586 |
1602 |
1587 /** Returns current OTG features of USB device. |
1603 /** Returns current OTG features of USB device. |
1659 |
1675 |
1660 @return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
1676 @return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found. |
1661 */ |
1677 */ |
1662 EXPORT_C TInt DUsbClientController::DeRegisterForOtgFeatureChange(const DBase* aClientId) |
1678 EXPORT_C TInt DUsbClientController::DeRegisterForOtgFeatureChange(const DBase* aClientId) |
1663 { |
1679 { |
1664 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterForOtgFeatureChange()")); |
1680 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE, "DUsbClientController::DeRegisterForOtgFeatureChange()" ); |
1665 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
1681 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
1666 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
1682 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
1667 TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks); |
1683 TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks); |
1668 TUsbcOtgFeatureCallback* p; |
1684 TUsbcOtgFeatureCallback* p; |
1669 while ((p = iter++) != NULL) |
1685 while ((p = iter++) != NULL) |
1670 { |
1686 { |
1671 if (!aClientId || p->Owner() == aClientId) |
1687 if (!aClientId || p->Owner() == aClientId) |
1672 { |
1688 { |
1673 __KTRACE_OPT(KUSB, Kern::Printf(" removing OtgFeatureCallback @ 0x%x", p)); |
1689 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE_DUP1, " removing OtgFeatureCallback @ 0x%x", p); |
1674 iOtgCallbacks.Remove(*p); |
1690 iOtgCallbacks.Remove(*p); |
1675 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1691 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1676 return KErrNone; |
1692 return KErrNone; |
1677 } |
1693 } |
1678 } |
1694 } |
1679 __KTRACE_OPT(KUSB, Kern::Printf(" client not found")); |
1695 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE_DUP2, " client not found"); |
1680 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1696 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
1681 return KErrNotFound; |
1697 return KErrNotFound; |
1682 } |
1698 } |
1683 |
1699 |
1684 |
1700 |
1729 if the new descriptor was successfully set. |
1746 if the new descriptor was successfully set. |
1730 */ |
1747 */ |
1731 EXPORT_C TInt DUsbClientController::SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, |
1748 EXPORT_C TInt DUsbClientController::SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, |
1732 TInt aSettingNum, const TDes8& aInterfaceDescriptor) |
1749 TInt aSettingNum, const TDes8& aInterfaceDescriptor) |
1733 { |
1750 { |
1734 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetInterfaceDescriptor(x, 0x%08x, %d, y)", |
1751 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR, "DUsbClientController::SetInterfaceDescriptor(x, 0x%08x, %d, y)", |
1735 aClientId, aSettingNum)); |
1752 (TUint)aClientId, aSettingNum); |
1736 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1753 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1737 if (ifcset < 0) |
1754 if (ifcset < 0) |
1738 { |
1755 { |
1739 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface not found from client ID")); |
1756 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
1740 return KErrNotFound; |
1757 return KErrNotFound; |
1741 } |
1758 } |
1742 TBuf8<KUsbDescSize_Interface> new_ifc; |
1759 TBuf8<KUsbDescSize_Interface> new_ifc; |
1743 TInt r = Kern::ThreadDesRead(aThread, &aInterfaceDescriptor, new_ifc, 0); |
1760 TInt r = Kern::ThreadDesRead(aThread, &aInterfaceDescriptor, new_ifc, 0); |
1744 if (r != KErrNone) |
1761 if (r != KErrNone) |
1745 { |
1762 { |
1746 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Copying interface descriptor buffer failed (%d)", r)); |
1763 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP2, " Error: Copying interface descriptor buffer failed (%d)", r); |
1747 return r; |
1764 return r; |
1748 } |
1765 } |
1749 const TInt ifcset_new = new_ifc[2]; |
1766 const TInt ifcset_new = new_ifc[2]; |
1750 const TBool ifc_num_changes = (ifcset != ifcset_new); |
1767 const TBool ifc_num_changes = (ifcset != ifcset_new); |
1751 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
1768 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
1752 if (!ifcset_ptr) |
1769 if (!ifcset_ptr) |
1753 { |
1770 { |
1754 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: interface number %d doesn't exist", ifcset)); |
1771 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP3, " Error: interface number %d doesn't exist", ifcset); |
1755 return KErrNotFound; |
1772 return KErrNotFound; |
1756 } |
1773 } |
1757 if (ifc_num_changes) |
1774 if (ifc_num_changes) |
1758 { |
1775 { |
1759 // If the user wants to change the interface number, we need to do some sanity checks: |
1776 // If the user wants to change the interface number, we need to do some sanity checks: |
1760 if (InterfaceExists(ifcset_new)) |
1777 if (InterfaceExists(ifcset_new)) |
1761 { |
1778 { |
1762 // Obviously we cannot accept a number that is already used by another interface. |
1779 // Obviously we cannot accept a number that is already used by another interface. |
1763 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: interface number %d already in use", ifcset_new)); |
1780 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP4, " Error: interface number %d already in use", ifcset_new); |
1764 return KErrArgument; |
1781 return KErrArgument; |
1765 } |
1782 } |
1766 if (ifcset_ptr->iInterfaces.Count() > 1) |
1783 if (ifcset_ptr->iInterfaces.Count() > 1) |
1767 { |
1784 { |
1768 // We allow the interface number to be changed only when it's the only setting. |
1785 // We allow the interface number to be changed only when it's the only setting. |
1769 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: interface has more than one alternate setting")); |
1786 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP5, " Error: interface has more than one alternate setting"); |
1770 return KErrArgument; |
1787 return KErrArgument; |
1771 } |
1788 } |
1772 if (aSettingNum != 0) |
1789 if (aSettingNum != 0) |
1773 { |
1790 { |
1774 // We allow the interface number to be changed only when it's the default setting. |
1791 // We allow the interface number to be changed only when it's the default setting. |
1775 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: interface number can only be changed for setting 0")); |
1792 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP6, " Error: interface number can only be changed for setting 0"); |
1776 return KErrArgument; |
1793 return KErrArgument; |
1777 } |
1794 } |
1778 } |
1795 } |
1779 if ((r = iDescriptors.SetInterfaceDescriptor(new_ifc, ifcset, aSettingNum)) != KErrNone) |
1796 if ((r = iDescriptors.SetInterfaceDescriptor(new_ifc, ifcset, aSettingNum)) != KErrNone) |
1780 { |
1797 { |
1781 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: iDescriptors.SetInterfaceDescriptorfailed")); |
1798 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP7, " Error: iDescriptors.SetInterfaceDescriptorfailed"); |
1782 return r; |
1799 return r; |
1783 } |
1800 } |
1784 if (ifc_num_changes) |
1801 if (ifc_num_changes) |
1785 { |
1802 { |
1786 // Alright then, let's do it... |
1803 // Alright then, let's do it... |
1787 __KTRACE_OPT(KUSB, Kern::Printf(" about to change interface number from %d to %d", |
1804 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP8, " about to change interface number from %d to %d", |
1788 ifcset, ifcset_new)); |
1805 ifcset, ifcset_new); |
1789 ifcset_ptr->iInterfaceNumber = ifcset_new; |
1806 ifcset_ptr->iInterfaceNumber = ifcset_new; |
1790 } |
1807 } |
1791 return KErrNone; |
1808 return KErrNone; |
1792 } |
1809 } |
1793 |
1810 |
1835 */ |
1852 */ |
1836 EXPORT_C TInt DUsbClientController::GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, |
1853 EXPORT_C TInt DUsbClientController::GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, |
1837 TInt aSettingNum, TInt aEndpointNum, |
1854 TInt aSettingNum, TInt aEndpointNum, |
1838 TDes8& aEndpointDescriptor) |
1855 TDes8& aEndpointDescriptor) |
1839 { |
1856 { |
1840 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetEndpointDescriptor(x, 0x%08x, %d, %d, y)", |
1857 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTOR, "DUsbClientController::GetEndpointDescriptor(x, 0x%08x, %d, %d, y)", |
1841 aClientId, aSettingNum, aEndpointNum)); |
1858 (TUint)aClientId, aSettingNum, aEndpointNum); |
1842 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1859 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1843 if (ifcset < 0) |
1860 if (ifcset < 0) |
1844 { |
1861 { |
1845 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface not found from client ID")); |
1862 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
1846 return KErrNotFound; |
1863 return KErrNotFound; |
1847 } |
1864 } |
1848 return iDescriptors.GetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
1865 return iDescriptors.GetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
1849 aSettingNum, EpIdx2Addr(aEndpointNum)); |
1866 aSettingNum, EpIdx2Addr(aEndpointNum)); |
1850 } |
1867 } |
1866 */ |
1883 */ |
1867 EXPORT_C TInt DUsbClientController::SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, |
1884 EXPORT_C TInt DUsbClientController::SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, |
1868 TInt aSettingNum, TInt aEndpointNum, |
1885 TInt aSettingNum, TInt aEndpointNum, |
1869 const TDes8& aEndpointDescriptor) |
1886 const TDes8& aEndpointDescriptor) |
1870 { |
1887 { |
1871 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetEndpointDescriptor(x, 0x%08x, %d, %d, y)", |
1888 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTDESCRIPTOR, "DUsbClientController::SetEndpointDescriptor(x, 0x%08x, %d, %d, y)", |
1872 aClientId, aSettingNum, aEndpointNum)); |
1889 (TUint)aClientId, aSettingNum, aEndpointNum); |
1873 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1890 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
1874 if (ifcset < 0) |
1891 if (ifcset < 0) |
1875 { |
1892 { |
1876 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface not found from client ID")); |
1893 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETENDPOINTDESCRIPTOR_DUP1, " Error: Interface not found from client ID"); |
1877 return KErrNotFound; |
1894 return KErrNotFound; |
1878 } |
1895 } |
1879 return iDescriptors.SetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
1896 return iDescriptors.SetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
1880 aSettingNum, EpIdx2Addr(aEndpointNum)); |
1897 aSettingNum, EpIdx2Addr(aEndpointNum)); |
1881 } |
1898 } |
2046 */ |
2063 */ |
2047 EXPORT_C TInt DUsbClientController::SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, |
2064 EXPORT_C TInt DUsbClientController::SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, |
2048 TInt aSettingNum, |
2065 TInt aSettingNum, |
2049 const TDes8& aInterfaceDescriptor, TInt aSize) |
2066 const TDes8& aInterfaceDescriptor, TInt aSize) |
2050 { |
2067 { |
2051 __KTRACE_OPT(KUSB, |
2068 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK, "DUsbClientController::SetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y, %d)", |
2052 Kern::Printf("DUsbClientController::SetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y, %d)", |
2069 (TUint)aClientId, aSettingNum, aSize); |
2053 aClientId, aSettingNum, aSize)); |
|
2054 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2070 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2055 if (ifcset < 0) |
2071 if (ifcset < 0) |
2056 { |
2072 { |
2057 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface not found from client ID")); |
2073 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK_DUP1, " Error: Interface not found from client ID"); |
2058 return KErrNotFound; |
2074 return KErrNotFound; |
2059 } |
2075 } |
2060 if (aSize < 2) |
2076 if (aSize < 2) |
2061 { |
2077 { |
2062 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: aSize < 2 (%d)", aSize)); |
2078 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK_DUP2, " Error: aSize < 2 (%d)", aSize); |
2063 return KErrArgument; |
2079 return KErrArgument; |
2064 } |
2080 } |
2065 return iDescriptors.SetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum, aSize); |
2081 return iDescriptors.SetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum, aSize); |
2066 } |
2082 } |
2067 |
2083 |
2120 */ |
2135 */ |
2121 EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, |
2136 EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, |
2122 TInt aSettingNum, TInt aEndpointNum, |
2137 TInt aSettingNum, TInt aEndpointNum, |
2123 TDes8& aEndpointDescriptor) |
2138 TDes8& aEndpointDescriptor) |
2124 { |
2139 { |
2125 __KTRACE_OPT(KUSB, |
2140 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCK, "DUsbClientController::GetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)", |
2126 Kern::Printf("DUsbClientController::GetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)", |
2141 (TUint)aClientId, aSettingNum, aEndpointNum); |
2127 aClientId, aSettingNum, aEndpointNum)); |
|
2128 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2142 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2129 if (ifcset < 0) |
2143 if (ifcset < 0) |
2130 { |
2144 { |
2131 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface not found from client ID")); |
2145 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCK_DUP1, " Error: Interface not found from client ID"); |
2132 return KErrNotFound; |
2146 return KErrNotFound; |
2133 } |
2147 } |
2134 return iDescriptors.GetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
2148 return iDescriptors.GetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
2135 aSettingNum, EpIdx2Addr(aEndpointNum)); |
2149 aSettingNum, EpIdx2Addr(aEndpointNum)); |
2136 } |
2150 } |
2155 */ |
2169 */ |
2156 EXPORT_C TInt DUsbClientController::SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, |
2170 EXPORT_C TInt DUsbClientController::SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, |
2157 TInt aSettingNum, TInt aEndpointNum, |
2171 TInt aSettingNum, TInt aEndpointNum, |
2158 const TDes8& aEndpointDescriptor, TInt aSize) |
2172 const TDes8& aEndpointDescriptor, TInt aSize) |
2159 { |
2173 { |
2160 __KTRACE_OPT(KUSB, |
2174 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK, "DUsbClientController::SetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)", |
2161 Kern::Printf("DUsbClientController::SetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)", |
2175 (TUint)aClientId, aSettingNum, aEndpointNum); |
2162 aClientId, aSettingNum, aEndpointNum)); |
|
2163 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2176 const TInt ifcset = ClientId2InterfaceNumber(aClientId); |
2164 if (ifcset < 0) |
2177 if (ifcset < 0) |
2165 { |
2178 { |
2166 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Interface not found from client ID")); |
2179 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK_DUP1, " Error: Interface not found from client ID"); |
2167 return KErrNotFound; |
2180 return KErrNotFound; |
2168 } |
2181 } |
2169 if (aSize < 2) |
2182 if (aSize < 2) |
2170 { |
2183 { |
2171 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: aSize < 2 (%d)", aSize)); |
2184 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK_DUP2, " Error: aSize < 2 (%d)", aSize); |
2172 return KErrArgument; |
2185 return KErrArgument; |
2173 } |
2186 } |
2174 return iDescriptors.SetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
2187 return iDescriptors.SetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset, |
2175 aSettingNum, EpIdx2Addr(aEndpointNum), aSize); |
2188 aSettingNum, EpIdx2Addr(aEndpointNum), aSize); |
2176 } |
2189 } |
2562 during the execution of the function. |
2577 during the execution of the function. |
2563 */ |
2578 */ |
2564 EXPORT_C TBool DUsbClientController::QueryEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum, |
2579 EXPORT_C TBool DUsbClientController::QueryEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum, |
2565 TUsbcEndpointResource aResource) |
2580 TUsbcEndpointResource aResource) |
2566 { |
2581 { |
2567 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::QueryEndpointResource()")); |
2582 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_QUERYENDPOINTRESOURCE, "DUsbClientController::QueryEndpointResource()" ); |
2568 return QueryEndpointResource(aEndpointNum, aResource); |
2583 return QueryEndpointResource(aEndpointNum, aResource); |
2569 } |
2584 } |
2570 |
2585 |
2571 |
2586 |
2572 EXPORT_C TInt DUsbClientController::EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum) |
2587 EXPORT_C TInt DUsbClientController::EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum) |
2573 { |
2588 { |
2574 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EndpointPacketSize(0x%08x, %d)", |
2589 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE, "DUsbClientController::EndpointPacketSize(0x%08x, %d)", |
2575 aClientId, aEndpointNum)); |
2590 (TUint)aClientId, aEndpointNum); |
2576 |
|
2577 const TUsbcInterfaceSet* const ifcset_ptr = ClientId2InterfacePointer(aClientId); |
2591 const TUsbcInterfaceSet* const ifcset_ptr = ClientId2InterfacePointer(aClientId); |
2578 if (!ifcset_ptr) |
2592 if (!ifcset_ptr) |
2579 { |
2593 { |
2580 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: interface or clientid not found")); |
2594 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP1, " Error: interface or clientid not found"); |
2581 return -1; |
2595 return -1; |
2582 } |
2596 } |
2583 const TUsbcInterface* const ifc_ptr = ifcset_ptr->iInterfaces[ifcset_ptr->iCurrentInterface]; |
2597 const TUsbcInterface* const ifc_ptr = ifcset_ptr->iInterfaces[ifcset_ptr->iCurrentInterface]; |
2584 const RPointerArray<TUsbcLogicalEndpoint>& ep_array = ifc_ptr->iEndpoints; |
2598 const RPointerArray<TUsbcLogicalEndpoint>& ep_array = ifc_ptr->iEndpoints; |
2585 const TInt n = ep_array.Count(); |
2599 const TInt n = ep_array.Count(); |
2586 for (TInt i = 0; i < n; i++) |
2600 for (TInt i = 0; i < n; i++) |
2587 { |
2601 { |
2588 const TUsbcLogicalEndpoint* const ep = ep_array[i]; |
2602 const TUsbcLogicalEndpoint* const ep = ep_array[i]; |
2589 if (EpAddr2Idx(ep->iPEndpoint->iEndpointAddr) == static_cast<TUint>(aEndpointNum)) |
2603 if (EpAddr2Idx(ep->iPEndpoint->iEndpointAddr) == static_cast<TUint>(aEndpointNum)) |
2590 { |
2604 { |
2591 __KTRACE_OPT(KUSB, Kern::Printf(" Endpoint packet sizes: FS = %d HS = %d", |
2605 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP2, " Endpoint packet sizes: FS = %d HS = %d", |
2592 ep->iEpSize_Fs, ep->iEpSize_Hs)); |
2606 ep->iEpSize_Fs, ep->iEpSize_Hs); |
2593 const TInt size = iHighSpeed ? ep->iEpSize_Hs : ep->iEpSize_Fs; |
2607 const TInt size = iHighSpeed ? ep->iEpSize_Hs : ep->iEpSize_Fs; |
2594 __KTRACE_OPT(KUSB, Kern::Printf(" Returning %d", size)); |
2608 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP3, " Returning %d", size); |
2595 return size; |
2609 return size; |
2596 } |
2610 } |
2597 } |
2611 } |
2598 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: endpoint not found")); |
2612 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP4, " Error: endpoint not found"); |
2599 return -1; |
2613 return -1; |
2600 } |
2614 } |
2601 |
2615 |
2602 |
2616 |
2603 // |
2617 // |
2604 // === USB Controller member function implementations - LDD API (public) =========================== |
2618 // === USB Controller member function implementations - LDD API (public) =========================== |
2605 // |
2619 // |
2606 |
2620 |
2607 EXPORT_C TBool DUsbClientController::CurrentlyUsingHighSpeed() |
2621 EXPORT_C TBool DUsbClientController::CurrentlyUsingHighSpeed() |
2608 { |
2622 { |
2609 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CurrentlyUsingHighSpeed()")); |
2623 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CURRENTLYUSINGHIGHSPEED, "DUsbClientController::CurrentlyUsingHighSpeed()" ); |
2610 return EFalse; |
2624 return EFalse; |
2611 } |
2625 } |
2612 |
2626 |
2613 |
2627 |
2614 // |
2628 // |
2759 TUsbcEndpointInfo info(KUsbEpTypeControl, KUsbEpDirOut, 0); |
2773 TUsbcEndpointInfo info(KUsbEpTypeControl, KUsbEpDirOut, 0); |
2760 TUsbcLogicalEndpoint* ep = NULL; |
2774 TUsbcLogicalEndpoint* ep = NULL; |
2761 |
2775 |
2762 // Initialise the array of physical endpoints |
2776 // Initialise the array of physical endpoints |
2763 iDeviceTotalEndpoints = DeviceTotalEndpoints(); |
2777 iDeviceTotalEndpoints = DeviceTotalEndpoints(); |
2764 __KTRACE_OPT(KUSB, Kern::Printf(" DeviceTotalEndpoints: %d", iDeviceTotalEndpoints)); |
2778 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP2, " DeviceTotalEndpoints: %d", iDeviceTotalEndpoints); |
2765 // KUsbcMaxEndpoints doesn't include ep 0 |
2779 // KUsbcMaxEndpoints doesn't include ep 0 |
2766 if ((iDeviceTotalEndpoints > (KUsbcMaxEndpoints + 2)) || |
2780 if ((iDeviceTotalEndpoints > (KUsbcMaxEndpoints + 2)) || |
2767 ((iDeviceTotalEndpoints * sizeof(TUsbcPhysicalEndpoint)) > sizeof(iRealEndpoints))) |
2781 ((iDeviceTotalEndpoints * sizeof(TUsbcPhysicalEndpoint)) > sizeof(iRealEndpoints))) |
2768 { |
2782 { |
2769 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: too many endpoints! (change KUsbcMaxEndpoints: %d)", |
2783 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP3, " Error: too many endpoints! (change KUsbcMaxEndpoints: %d)", |
2770 KUsbcMaxEndpoints)); |
2784 KUsbcMaxEndpoints); |
2771 goto exit_1; |
2785 goto exit_1; |
2772 } |
2786 } |
2773 caps = DeviceEndpointCaps(); |
2787 caps = DeviceEndpointCaps(); |
2774 for (TInt i = 0; i < iDeviceTotalEndpoints; ++i) |
2788 for (TInt i = 0; i < iDeviceTotalEndpoints; ++i) |
2775 { |
2789 { |
2776 iRealEndpoints[i].iEndpointAddr = EpIdx2Addr(i); |
2790 iRealEndpoints[i].iEndpointAddr = EpIdx2Addr(i); |
2777 __KTRACE_OPT(KUSB, Kern::Printf(" Caps[%02d] - iTypes: 0x%08x iSizes: 0x%08x", |
2791 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP4, " Caps[%02d] - iTypes: 0x%08x iSizes: 0x%08x", |
2778 i, caps[i].iTypesAndDir, caps[i].iSizes)); |
2792 i, caps[i].iTypesAndDir, caps[i].iSizes); |
2779 iRealEndpoints[i].iCaps = caps[i]; |
2793 iRealEndpoints[i].iCaps = caps[i]; |
2780 iRealEndpoints[i].iCaps.iReserved[0] = 0; |
2794 iRealEndpoints[i].iCaps.iReserved[0] = 0; |
2781 iRealEndpoints[i].iCaps.iReserved[1] = 0; |
2795 iRealEndpoints[i].iCaps.iReserved[1] = 0; |
2782 if ((i > 1) && (caps[i].iTypesAndDir != KUsbEpNotAvailable)) |
2796 if ((i > 1) && (caps[i].iTypesAndDir != KUsbEpNotAvailable)) |
2783 { |
2797 { |
2784 __KTRACE_OPT(KUSB, Kern::Printf(" --> UsableEndpoint: #%d", i)); |
2798 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP5, " --> UsableEndpoint: #%d", i); |
2785 iDeviceUsableEndpoints++; |
2799 iDeviceUsableEndpoints++; |
2786 } |
2800 } |
2787 } |
2801 } |
2788 |
2802 |
2789 // Initialise Ep0 structures (logical endpoints are numbered 1..KMaxEndpointsPerClient, |
2803 // Initialise Ep0 structures (logical endpoints are numbered 1..KMaxEndpointsPerClient, |
2790 // and virtual 0 is real 0): |
2804 // and virtual 0 is real 0): |
2791 // -- Ep0 OUT |
2805 // -- Ep0 OUT |
2792 iEp0MaxPacketSize = caps[0].MaxPacketSize(); |
2806 iEp0MaxPacketSize = caps[0].MaxPacketSize(); |
2793 __KTRACE_OPT(KUSB, Kern::Printf(" using Ep0 maxpacketsize of %d bytes", iEp0MaxPacketSize)); |
2807 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP6, " using Ep0 maxpacketsize of %d bytes", iEp0MaxPacketSize); |
2794 info.iSize = iEp0MaxPacketSize; |
2808 info.iSize = iEp0MaxPacketSize; |
2795 ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_Out]); |
2809 ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_Out]); |
2796 if (!ep) |
2810 if (!ep) |
2797 { |
2811 { |
2798 goto exit_1; |
2812 goto exit_1; |
2799 } |
2813 } |
2800 __KTRACE_OPT(KUSB, Kern::Printf(" creating ep: mapping real ep %d --> logical ep 0", KEp0_Out)); |
2814 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP7, " creating ep: mapping real ep %d --> logical ep 0", KEp0_Out); |
2801 iRealEndpoints[KEp0_Out].iLEndpoint = ep; |
2815 iRealEndpoints[KEp0_Out].iLEndpoint = ep; |
2802 // -- Ep0 IN |
2816 // -- Ep0 IN |
2803 info.iDir = KUsbEpDirIn; |
2817 info.iDir = KUsbEpDirIn; |
2804 ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_In]); |
2818 ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_In]); |
2805 if (!ep) |
2819 if (!ep) |
2806 { |
2820 { |
2807 goto exit_2; |
2821 goto exit_2; |
2808 } |
2822 } |
2809 __KTRACE_OPT(KUSB, Kern::Printf(" creating ep: mapping real ep %d --> logical ep 0", KEp0_In)); |
2823 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP8, " creating ep: mapping real ep %d --> logical ep 0", KEp0_In); |
2810 iRealEndpoints[KEp0_In].iLEndpoint = ep; |
2824 iRealEndpoints[KEp0_In].iLEndpoint = ep; |
2811 |
2825 |
2812 // Create the power handler |
2826 // Create the power handler |
2813 iPowerHandler = new DUsbcPowerHandler(this); |
2827 iPowerHandler = new DUsbcPowerHandler(this); |
2814 if (!iPowerHandler) |
2828 if (!iPowerHandler) |
3042 |
3057 |
3043 @publishedPartner @released |
3058 @publishedPartner @released |
3044 */ |
3059 */ |
3045 TInt DUsbClientController::Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError) |
3060 TInt DUsbClientController::Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError) |
3046 { |
3061 { |
3047 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Ep0RequestComplete(%d)", aRealEndpoint)); |
3062 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE, "DUsbClientController::Ep0RequestComplete(%d)", aRealEndpoint); |
3048 |
3063 |
3049 // This function may be called by the PSL from within an ISR -- so we have |
3064 // This function may be called by the PSL from within an ISR -- so we have |
3050 // to take care what we do here (and also in all functions that get called |
3065 // to take care what we do here (and also in all functions that get called |
3051 // from here). |
3066 // from here). |
3052 |
3067 |
3053 __ASSERT_DEBUG((aRealEndpoint < 2), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3068 __ASSERT_DEBUG((aRealEndpoint < 2), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3054 if (aError != KErrNone && aError != KErrPrematureEnd) |
3069 if (aError != KErrNone && aError != KErrPrematureEnd) |
3055 { |
3070 { |
3056 __KTRACE_OPT(KUSB, Kern::Printf(" Error: Ep0 request failed (code %d). " |
3071 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP1, " Error: Ep0 request failed (code %d). " |
3057 "Setting up new Read request.", aError)); |
3072 "Setting up new Read request.", aError); |
|
3073 |
3058 if (aRealEndpoint == KEp0_Rx) |
3074 if (aRealEndpoint == KEp0_Rx) |
3059 { |
3075 { |
3060 __KTRACE_OPT(KUSB, Kern::Printf(" (RX request failed)")); |
3076 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP2, " (RX request failed)"); |
3061 StallEndpoint(KEp0_Out); |
3077 StallEndpoint(KEp0_Out); |
3062 } |
3078 } |
3063 else |
3079 else |
3064 { |
3080 { |
3065 __KTRACE_OPT(KUSB, Kern::Printf(" (TX request failed)")); |
3081 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP3, " (TX request failed)"); |
3066 iEp0WritePending = EFalse; |
3082 iEp0WritePending = EFalse; |
3067 StallEndpoint(KEp0_In); |
3083 StallEndpoint(KEp0_In); |
3068 } |
3084 } |
3069 // our only remedy: set up a new read request |
3085 // our only remedy: set up a new read request |
3070 SetupEndpointZeroRead(); |
3086 SetupEndpointZeroRead(); |
3135 // === Platform Specific Layer (PSL) - private/virtual ============================================= |
3151 // === Platform Specific Layer (PSL) - private/virtual ============================================= |
3136 // |
3152 // |
3137 |
3153 |
3138 TInt DUsbClientController::OpenDmaChannel(TInt aRealEndpoint) |
3154 TInt DUsbClientController::OpenDmaChannel(TInt aRealEndpoint) |
3139 { |
3155 { |
3140 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OpenDmaChannel(%d)", aRealEndpoint)); |
3156 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_OPENDMACHANNEL, "DUsbClientController::OpenDmaChannel(%d)", aRealEndpoint); |
|
3157 |
3141 return KErrNone; |
3158 return KErrNone; |
3142 } |
3159 } |
3143 |
3160 |
3144 |
3161 |
3145 void DUsbClientController::CloseDmaChannel(TInt aRealEndpoint) |
3162 void DUsbClientController::CloseDmaChannel(TInt aRealEndpoint) |
3146 { |
3163 { |
3147 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CloseDmaChannel(%d)", aRealEndpoint)); |
3164 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CLOSEDMACHANNEL, "DUsbClientController::CloseDmaChannel(%d)", aRealEndpoint); |
3148 } |
3165 } |
3149 |
3166 |
3150 |
3167 |
3151 TBool DUsbClientController::CableDetectWithoutPowerCaps() const |
3168 TBool DUsbClientController::CableDetectWithoutPowerCaps() const |
3152 { |
3169 { |
3153 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CableDetectWithoutPowerCaps()")); |
3170 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CABLEDETECTWITHOUTPOWERCAPS, "DUsbClientController::CableDetectWithoutPowerCaps()" ); |
3154 // Should be overridden in PSL if applicable. |
3171 // Should be overridden in PSL if applicable. |
3155 return EFalse; |
3172 return EFalse; |
3156 } |
3173 } |
3157 |
3174 |
3158 |
3175 |
3159 TBool DUsbClientController::DeviceHighSpeedCaps() const |
3176 TBool DUsbClientController::DeviceHighSpeedCaps() const |
3160 { |
3177 { |
3161 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceHighSpeedCaps()")); |
3178 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEHIGHSPEEDCAPS, "DUsbClientController::DeviceHighSpeedCaps()" ); |
3162 // Should be overridden in PSL if applicable. |
3179 // Should be overridden in PSL if applicable. |
3163 return EFalse; |
3180 return EFalse; |
3164 } |
3181 } |
3165 |
3182 |
3166 |
3183 |
3167 TBool DUsbClientController::DeviceResourceAllocV2Caps() const |
3184 TBool DUsbClientController::DeviceResourceAllocV2Caps() const |
3168 { |
3185 { |
3169 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceResourceAllocV2Caps()")); |
3186 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICERESOURCEALLOCV2CAPS, "DUsbClientController::DeviceResourceAllocV2Caps()" ); |
3170 // Should be overridden in PSL if applicable. |
3187 // Should be overridden in PSL if applicable. |
3171 return EFalse; |
3188 return EFalse; |
3172 } |
3189 } |
3173 |
3190 |
3174 |
3191 |
3175 TBool DUsbClientController::DeviceHnpHandledByHardwareCaps() const |
3192 TBool DUsbClientController::DeviceHnpHandledByHardwareCaps() const |
3176 { |
3193 { |
3177 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceHnpHandledByHardwareCaps()")); |
3194 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEHNPHANDLEDBYHARDWARECAPS, "DUsbClientController::DeviceHnpHandledByHardwareCaps()" ); |
3178 // Should be overridden in PSL if applicable. |
3195 // Should be overridden in PSL if applicable. |
3179 return EFalse; |
3196 return EFalse; |
3180 } |
3197 } |
3181 |
3198 |
3182 |
3199 |
3183 TInt DUsbClientController::EnterTestMode(TInt aTestSelector) |
3200 TInt DUsbClientController::EnterTestMode(TInt aTestSelector) |
3184 { |
3201 { |
3185 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnterTestMode(%d)", aTestSelector)); |
3202 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENTERTESTMODE, "DUsbClientController::EnterTestMode(%d)", aTestSelector); |
|
3203 |
3186 // Should be overridden in PSL if applicable. |
3204 // Should be overridden in PSL if applicable. |
3187 return KErrNotSupported; |
3205 return KErrNotSupported; |
3188 } |
3206 } |
3189 |
3207 |
3190 |
3208 |
3191 TBool DUsbClientController::PowerDownWhenActive() const |
3209 TBool DUsbClientController::PowerDownWhenActive() const |
3192 { |
3210 { |
3193 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerDownWhenActive()")); |
3211 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWNWHENACTIVE, "DUsbClientController::PowerDownWhenActive()" ); |
3194 return EFalse; |
3212 return EFalse; |
3195 } |
3213 } |
3196 |
3214 |
3197 |
3215 |
3198 TInt DUsbClientController::PowerDown() |
3216 TInt DUsbClientController::PowerDown() |
3199 { |
3217 { |
3200 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerDown()")); |
3218 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWN, "DUsbClientController::PowerDown()" ); |
3201 return KErrNone; |
3219 return KErrNone; |
3202 } |
3220 } |
3203 |
3221 |
3204 |
3222 |
3205 TInt DUsbClientController::PowerUp() |
3223 TInt DUsbClientController::PowerUp() |
3206 { |
3224 { |
3207 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerUp()")); |
3225 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUP, "DUsbClientController::PowerUp()" ); |
3208 return KErrNone; |
3226 return KErrNone; |
3209 } |
3227 } |
3210 |
3228 |
3211 |
3229 |
3212 TInt DUsbClientController::OtgEnableUdc() |
3230 TInt DUsbClientController::OtgEnableUdc() |
3213 { |
3231 { |
3214 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OtgEnableUdc()")); |
3232 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGENABLEUDC, "DUsbClientController::OtgEnableUdc()" ); |
3215 return KErrNone; |
3233 return KErrNone; |
3216 } |
3234 } |
3217 |
3235 |
3218 |
3236 |
3219 TInt DUsbClientController::OtgDisableUdc() |
3237 TInt DUsbClientController::OtgDisableUdc() |
3220 { |
3238 { |
3221 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OtgDisableUdc()")); |
3239 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGDISABLEUDC, "DUsbClientController::OtgDisableUdc()" ); |
3222 return KErrNone; |
3240 return KErrNone; |
3223 } |
3241 } |
3224 |
3242 |
3225 |
3243 |
3226 // |
3244 // |
3227 // === USB Controller member function implementations - Internal utility functions (private) ======= |
3245 // === USB Controller member function implementations - Internal utility functions (private) ======= |
3228 // |
3246 // |
3229 |
3247 |
3230 TInt DUsbClientController::DeRegisterClientCallback(const DBase* aClientId) |
3248 TInt DUsbClientController::DeRegisterClientCallback(const DBase* aClientId) |
3231 { |
3249 { |
3232 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterClientCallback()")); |
3250 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK, "DUsbClientController::DeRegisterClientCallback()" ); |
3233 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3251 __ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3234 TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
3252 TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks); |
3235 TUsbcClientCallback* p; |
3253 TUsbcClientCallback* p; |
3236 while ((p = iter++) != NULL) |
3254 while ((p = iter++) != NULL) |
3237 if (p->Owner() == aClientId) |
3255 if (p->Owner() == aClientId) |
3238 { |
3256 { |
3239 __KTRACE_OPT(KUSB, Kern::Printf(" removing ClientCallback @ 0x%x", p)); |
3257 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK_DUP1, " removing ClientCallback @ 0x%x", p); |
3240 iClientCallbacks.Remove(*p); |
3258 iClientCallbacks.Remove(*p); |
3241 return KErrNone; |
3259 return KErrNone; |
3242 } |
3260 } |
3243 __KTRACE_OPT(KUSB, Kern::Printf(" Client not found")); |
3261 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK_DUP2, " Client not found"); |
3244 return KErrNotFound; |
3262 return KErrNotFound; |
3245 } |
3263 } |
3246 |
3264 |
3247 |
3265 |
3248 TBool DUsbClientController::CheckEpAvailability(TInt aEndpointsUsed, |
3266 TBool DUsbClientController::CheckEpAvailability(TInt aEndpointsUsed, |
3249 const TUsbcEndpointInfoArray& aEndpointData, |
3267 const TUsbcEndpointInfoArray& aEndpointData, |
3250 TInt aIfcNumber) const |
3268 TInt aIfcNumber) const |
3251 { |
3269 { |
3252 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CheckEpAvailability()")); |
3270 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY, "DUsbClientController::CheckEpAvailability()" ); |
3253 if (aEndpointsUsed > KMaxEndpointsPerClient) |
3271 if (aEndpointsUsed > KMaxEndpointsPerClient) |
3254 { |
3272 { |
3255 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: too many endpoints claimed (%d)", aEndpointsUsed)); |
3273 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP1, " Error: too many endpoints claimed (%d)", aEndpointsUsed); |
3256 return EFalse; |
3274 return EFalse; |
3257 } |
3275 } |
3258 TBool reserve[KUsbcEpArraySize]; // iDeviceTotalEndpoints can be equal to 32 |
3276 TBool reserve[KUsbcEpArraySize]; // iDeviceTotalEndpoints can be equal to 32 |
3259 memset(reserve, EFalse, sizeof(reserve)); // reset the array |
3277 memset(reserve, EFalse, sizeof(reserve)); // reset the array |
3260 for (TInt i = 0; i < aEndpointsUsed; ++i) |
3278 for (TInt i = 0; i < aEndpointsUsed; ++i) |
3261 { |
3279 { |
3262 __KTRACE_OPT(KUSB, Kern::Printf(" checking for (user) endpoint #%d availability...", i + 1)); |
3280 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP2, " checking for (user) endpoint #%d availability...", i + 1); |
3263 TInt j = 2; |
3281 TInt j = 2; |
3264 while (j < iDeviceTotalEndpoints) |
3282 while (j < iDeviceTotalEndpoints) |
3265 { |
3283 { |
3266 if ((iRealEndpoints[j].EndpointSuitable(&aEndpointData[i], aIfcNumber)) && |
3284 if ((iRealEndpoints[j].EndpointSuitable(&aEndpointData[i], aIfcNumber)) && |
3267 (reserve[j] == EFalse)) |
3285 (reserve[j] == EFalse)) |
3268 { |
3286 { |
3269 __KTRACE_OPT(KUSB, Kern::Printf(" ---> found suitable endpoint: RealEndpoint #%d", j)); |
3287 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP3, " ---> found suitable endpoint: RealEndpoint #%d", j); |
3270 reserve[j] = ETrue; // found one: mark this ep as reserved |
3288 reserve[j] = ETrue; // found one: mark this ep as reserved |
3271 break; |
3289 break; |
3272 } |
3290 } |
3273 __KTRACE_OPT(KUSB, Kern::Printf(" -> endpoint not suitable: RealEndpoint #%d", j)); |
3291 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP4, " -> endpoint not suitable: RealEndpoint #%d", j); |
3274 j++; |
3292 j++; |
3275 } |
3293 } |
3276 if (j == iDeviceTotalEndpoints) |
3294 if (j == iDeviceTotalEndpoints) |
3277 { |
3295 { |
3278 return EFalse; |
3296 return EFalse; |
3285 TUsbcInterface* DUsbClientController::CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord) |
3303 TUsbcInterface* DUsbClientController::CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord) |
3286 // We know that 9.2.3 says: "Interfaces are numbered from zero to one less than the number of |
3304 // We know that 9.2.3 says: "Interfaces are numbered from zero to one less than the number of |
3287 // concurrent interfaces supported by the configuration." But since we permit the user to |
3305 // concurrent interfaces supported by the configuration." But since we permit the user to |
3288 // change interface numbers, we can neither assume nor enforce anything about them here. |
3306 // change interface numbers, we can neither assume nor enforce anything about them here. |
3289 { |
3307 { |
3290 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CreateInterface(x, aIfc=%d)", aIfc)); |
3308 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE, "DUsbClientController::CreateInterface(x, aIfc=%d)", aIfc); |
|
3309 |
3291 TUsbcInterfaceSet* ifcset_ptr = NULL; |
3310 TUsbcInterfaceSet* ifcset_ptr = NULL; |
3292 TInt ifcset = ClientId2InterfaceNumber(aClientId); |
3311 TInt ifcset = ClientId2InterfaceNumber(aClientId); |
3293 TBool new_ifc; |
3312 TBool new_ifc; |
3294 if (ifcset < 0) |
3313 if (ifcset < 0) |
3295 { |
3314 { |
3296 // New interface(set), so we need to find a number for it. |
3315 // New interface(set), so we need to find a number for it. |
3297 new_ifc = ETrue; |
3316 new_ifc = ETrue; |
3298 const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
3317 const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count(); |
3299 if (num_ifcsets == 255) |
3318 if (num_ifcsets == 255) |
3300 { |
3319 { |
3301 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Too many interfaces already exist: 255")); |
3320 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP1, " Error: Too many interfaces already exist: 255"); |
3302 return NULL; |
3321 return NULL; |
3303 } |
3322 } |
3304 // Find the smallest interface number that has not yet been used. |
3323 // Find the smallest interface number that has not yet been used. |
3305 for (ifcset = 0; ifcset < 256; ++ifcset) |
3324 for (ifcset = 0; ifcset < 256; ++ifcset) |
3306 { |
3325 { |
3307 TBool n_used = EFalse; |
3326 TBool n_used = EFalse; |
3308 for (TInt i = 0; i < num_ifcsets; ++i) |
3327 for (TInt i = 0; i < num_ifcsets; ++i) |
3309 { |
3328 { |
3310 if ((iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber) == ifcset) |
3329 if ((iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber) == ifcset) |
3311 { |
3330 { |
3312 __KTRACE_OPT(KUSB, Kern::Printf(" interface number %d already used", ifcset)); |
3331 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP2, " interface number %d already used", ifcset); |
3313 n_used = ETrue; |
3332 n_used = ETrue; |
3314 break; |
3333 break; |
3315 } |
3334 } |
3316 } |
3335 } |
3317 if (!n_used) |
3336 if (!n_used) |
3319 break; |
3338 break; |
3320 } |
3339 } |
3321 } |
3340 } |
3322 if (ifcset == 256) |
3341 if (ifcset == 256) |
3323 { |
3342 { |
3324 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: no available interface number found")); |
3343 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP3, " Error: no available interface number found"); |
3325 return NULL; |
3344 return NULL; |
3326 } |
3345 } |
3327 // append the ifcset |
3346 // append the ifcset |
3328 __KTRACE_OPT(KUSB, Kern::Printf(" creating new InterfaceSet %d first", ifcset)); |
3347 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP4, " creating new InterfaceSet %d first", ifcset); |
3329 if (aIfc != 0) |
3348 if (aIfc != 0) |
3330 { |
3349 { |
3331 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: invalid interface setting number (1): %d", aIfc)); |
3350 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP5, " Error: invalid interface setting number (1): %d", aIfc); |
3332 return NULL; |
3351 return NULL; |
3333 } |
3352 } |
3334 if ((ifcset_ptr = new TUsbcInterfaceSet(aClientId, ifcset)) == NULL) |
3353 if ((ifcset_ptr = new TUsbcInterfaceSet(aClientId, ifcset)) == NULL) |
3335 { |
3354 { |
3336 __KTRACE_OPT(KPANIC, |
3355 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP6, " Error: new TUsbcInterfaceSet(aClientId, ifcset_num) failed"); |
3337 Kern::Printf(" Error: new TUsbcInterfaceSet(aClientId, ifcset_num) failed")); |
|
3338 return NULL; |
3356 return NULL; |
3339 } |
3357 } |
3340 iConfigs[0]->iInterfaceSets.Append(ifcset_ptr); |
3358 iConfigs[0]->iInterfaceSets.Append(ifcset_ptr); |
3341 } |
3359 } |
3342 else /* if (ifcset_num >= 0) */ |
3360 else /* if (ifcset_num >= 0) */ |
3343 { |
3361 { |
3344 // use an existent ifcset |
3362 // use an existent ifcset |
3345 new_ifc = EFalse; |
3363 new_ifc = EFalse; |
3346 __KTRACE_OPT(KUSB, Kern::Printf(" using existing InterfaceSet %d", ifcset)); |
3364 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP7, " using existing InterfaceSet %d", ifcset); |
3347 ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
3365 ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
3348 if (aIfc != ifcset_ptr->iInterfaces.Count()) |
3366 if (aIfc != ifcset_ptr->iInterfaces.Count()) |
3349 { |
3367 { |
3350 // 9.2.3: "Alternate settings range from zero to one less than the number of alternate |
3368 // 9.2.3: "Alternate settings range from zero to one less than the number of alternate |
3351 // settings for a specific interface." (Thus we can here only append a setting.) |
3369 // settings for a specific interface." (Thus we can here only append a setting.) |
3352 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: invalid interface setting number (2): %d", aIfc)); |
3370 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP8, " Error: invalid interface setting number (2): %d", aIfc); |
3353 return NULL; |
3371 return NULL; |
3354 } |
3372 } |
3355 // Check whether the existing interface belongs indeed to this client |
3373 // Check whether the existing interface belongs indeed to this client |
3356 if (ifcset_ptr->iClientId != aClientId) |
3374 if (ifcset_ptr->iClientId != aClientId) |
3357 { |
3375 { |
3358 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: iClientId (%p) != aClientId (%p)", |
3376 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP9, " Error: iClientId (%p) != aClientId (%p)", |
3359 ifcset_ptr->iClientId, aClientId)); |
3377 ifcset_ptr->iClientId, aClientId); |
3360 return NULL; |
3378 return NULL; |
3361 } |
3379 } |
3362 } |
3380 } |
3363 const TBool no_ep0_requests = aFeatureWord & KUsbcInterfaceInfo_NoEp0RequestsPlease; |
3381 const TBool no_ep0_requests = aFeatureWord & KUsbcInterfaceInfo_NoEp0RequestsPlease; |
3364 TUsbcInterface* const ifc_ptr = new TUsbcInterface(ifcset_ptr, aIfc, no_ep0_requests); |
3382 TUsbcInterface* const ifc_ptr = new TUsbcInterface(ifcset_ptr, aIfc, no_ep0_requests); |
3365 if (!ifc_ptr) |
3383 if (!ifc_ptr) |
3366 { |
3384 { |
3367 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: new TUsbcInterface(ifcset, aIfc) failed")); |
3385 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP10, " Error: new TUsbcInterface(ifcset, aIfc) failed"); |
3368 if (new_ifc) |
3386 if (new_ifc) |
3369 { |
3387 { |
3370 DeleteInterfaceSet(ifcset); |
3388 DeleteInterfaceSet(ifcset); |
3371 } |
3389 } |
3372 return NULL; |
3390 return NULL; |
3411 if (aIfc->iSettingCode == 0) |
3429 if (aIfc->iSettingCode == 0) |
3412 { |
3430 { |
3413 // For details see last paragraph of 5.7.3 "Interrupt Transfer Packet Size Constraints". |
3431 // For details see last paragraph of 5.7.3 "Interrupt Transfer Packet Size Constraints". |
3414 if ((ep->iInfo.iType == KUsbEpTypeInterrupt) && (ep->iEpSize_Hs > 64)) |
3432 if ((ep->iInfo.iType == KUsbEpTypeInterrupt) && (ep->iEpSize_Hs > 64)) |
3415 { |
3433 { |
3416 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: INT ep HS size = %d on default ifc setting", |
3434 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP2, " Warning: INT ep HS size = %d on default ifc setting", |
3417 ep->iEpSize_Hs)); |
3435 ep->iEpSize_Hs); |
3418 __KTRACE_OPT(KPANIC, Kern::Printf(" (should be <= 64)")); |
3436 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP3, " (should be <= 64)"); |
3419 } |
3437 } |
3420 // For details see last paragraph of 5.6.3 "Isochronous Transfer Packet Size Constraints". |
3438 // For details see last paragraph of 5.6.3 "Isochronous Transfer Packet Size Constraints". |
3421 else if ((ep->iInfo.iType == KUsbEpTypeIsochronous) && (ep->iInfo.iSize > 0)) |
3439 else if ((ep->iInfo.iType == KUsbEpTypeIsochronous) && (ep->iInfo.iSize > 0)) |
3422 { |
3440 { |
3423 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: ISO ep size = %d on default ifc setting", |
3441 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP4, " Warning: ISO ep size = %d on default ifc setting", |
3424 ep->iInfo.iSize)); |
3442 ep->iInfo.iSize); |
3425 __KTRACE_OPT(KPANIC, Kern::Printf(" (should be zero or ep non-existent)")); |
3443 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP5, " (should be zero or ep non-existent)"); |
3426 } |
3444 } |
3427 } |
3445 } |
3428 // If the endpoint doesn't support DMA (now or never) the next operation |
3446 // If the endpoint doesn't support DMA (now or never) the next operation |
3429 // will be a successful no-op. |
3447 // will be a successful no-op. |
3430 const TInt r = OpenDmaChannel(j); |
3448 const TInt r = OpenDmaChannel(j); |
3431 if (r != KErrNone) |
3449 if (r != KErrNone) |
3432 { |
3450 { |
3433 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Opening of DMA channel failed")); |
3451 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP6, " Error: Opening of DMA channel failed"); |
3434 aIfc->iEndpoints.ResetAndDestroy(); |
3452 aIfc->iEndpoints.ResetAndDestroy(); |
3435 RESET_SETTINGRESERVE; |
3453 RESET_SETTINGRESERVE; |
3436 return r; |
3454 return r; |
3437 } |
3455 } |
3438 __KTRACE_OPT(KUSB, Kern::Printf(" creating ep: mapping real ep %d -> logical ep %d", |
3456 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP7, " creating ep: mapping real ep %d -> logical ep %d", |
3439 j, i + 1)); |
3457 j, i + 1); |
3440 iRealEndpoints[j].iIfcNumber = &aIfc->iInterfaceSet->iInterfaceNumber; |
3458 iRealEndpoints[j].iIfcNumber = &aIfc->iInterfaceSet->iInterfaceNumber; |
3441 iRealEndpoints[j].iSettingReserve = ETrue; |
3459 iRealEndpoints[j].iSettingReserve = ETrue; |
3442 __KTRACE_OPT(KUSB, |
3460 OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP8, " ep->iInfo: iType=0x%x iDir=0x%x iSize=%d iInterval=%d", |
3443 Kern::Printf(" ep->iInfo: iType=0x%x iDir=0x%x iSize=%d iInterval=%d", |
3461 ep->iInfo.iType, ep->iInfo.iDir, ep->iInfo.iSize, |
3444 ep->iInfo.iType, ep->iInfo.iDir, ep->iInfo.iSize, |
3462 ep->iInfo.iInterval); |
3445 ep->iInfo.iInterval)); |
3463 OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP9, " ep->iInfo: iInterval_Hs=%d iTransactions=%d iExtra=%d", |
3446 __KTRACE_OPT(KUSB, |
3464 ep->iInfo.iInterval_Hs, ep->iInfo.iTransactions, |
3447 Kern::Printf(" ep->iInfo: iInterval_Hs=%d iTransactions=%d iExtra=%d", |
3465 ep->iInfo.iExtra); |
3448 ep->iInfo.iInterval_Hs, ep->iInfo.iTransactions, |
|
3449 ep->iInfo.iExtra)); |
|
3450 // Store real endpoint numbers: |
3466 // Store real endpoint numbers: |
3451 // array[x] holds the number for logical ep x. |
3467 // array[x] holds the number for logical ep x. |
3452 aRealEpNumbers[i + 1] = j; |
3468 aRealEpNumbers[i + 1] = j; |
3453 break; |
3469 break; |
3454 } |
3470 } |
3455 } |
3471 } |
3456 } |
3472 } |
3457 aRealEpNumbers[0] = 0; // ep0: 0. |
3473 aRealEpNumbers[0] = 0; // ep0: 0. |
3458 __KTRACE_OPT(KUSB,{ |
3474 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP10, " Endpoint Mapping for Interface %d / Setting %d:", ifc_num, aIfc->iSettingCode); |
3459 Kern::Printf(" Endpoint Mapping for Interface %d / Setting %d:", ifc_num, aIfc->iSettingCode); |
3475 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP11, "Logical | Real"); |
3460 Kern::Printf("Logical | Real"); |
3476 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP12, "Endpoint | Endpoint"); |
3461 Kern::Printf("Endpoint | Endpoint"); |
3477 for (TInt ep = 0; ep <= aEndpointsUsed; ++ep) |
3462 for (TInt ep = 0; ep <= aEndpointsUsed; ++ep) Kern::Printf(" %2d %3d",ep, aRealEpNumbers[ep]); |
3478 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP13, " %2d %3d",ep, aRealEpNumbers[ep]); |
3463 }); |
3479 |
3464 RESET_SETTINGRESERVE; |
3480 RESET_SETTINGRESERVE; |
3465 return KErrNone; |
3481 return KErrNone; |
3466 } |
3482 } |
3467 |
3483 |
3468 |
3484 |
3469 TInt DUsbClientController::SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, |
3485 TInt DUsbClientController::SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, |
3470 TDesC8* aString, const TUsbcEndpointInfoArray& aEndpointData) |
3486 TDesC8* aString, const TUsbcEndpointInfoArray& aEndpointData) |
3471 { |
3487 { |
3472 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetupIfcDescriptor()")); |
3488 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR, "DUsbClientController::SetupIfcDescriptor()" ); |
3473 |
3489 |
3474 // Interface descriptor |
3490 // Interface descriptor |
3475 TUsbcDescriptorBase* d = TUsbcInterfaceDescriptor::New(aIfc->iInterfaceSet->iInterfaceNumber, |
3491 TUsbcDescriptorBase* d = TUsbcInterfaceDescriptor::New(aIfc->iInterfaceSet->iInterfaceNumber, |
3476 aIfc->iSettingCode, |
3492 aIfc->iSettingCode, |
3477 aIfc->iEndpoints.Count(), |
3493 aIfc->iEndpoints.Count(), |
3478 aClass); |
3494 aClass); |
3479 if (!d) |
3495 if (!d) |
3480 { |
3496 { |
3481 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for ifc desc failed.")); |
3497 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP1, " Error: Memory allocation for ifc desc failed." ); |
3482 return KErrNoMemory; |
3498 return KErrNoMemory; |
3483 } |
3499 } |
3484 iDescriptors.InsertDescriptor(d); |
3500 iDescriptors.InsertDescriptor(d); |
3485 |
3501 |
3486 // Interface string descriptor |
3502 // Interface string descriptor |
3488 { |
3504 { |
3489 // we don't know the length of the string, so we have to allocate memory dynamically |
3505 // we don't know the length of the string, so we have to allocate memory dynamically |
3490 TUint strlen = Kern::ThreadGetDesLength(aThread, aString); |
3506 TUint strlen = Kern::ThreadGetDesLength(aThread, aString); |
3491 if (strlen > KUsbStringDescStringMaxSize) |
3507 if (strlen > KUsbStringDescStringMaxSize) |
3492 { |
3508 { |
3493 __KTRACE_OPT(KPANIC, Kern::Printf(" Warning: $ descriptor too long - string will be truncated")); |
3509 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP2, " Warning: $ descriptor too long - string will be truncated" ); |
3494 strlen = KUsbStringDescStringMaxSize; |
3510 strlen = KUsbStringDescStringMaxSize; |
3495 } |
3511 } |
3496 HBuf8* const stringbuf = HBuf8::New(strlen); |
3512 HBuf8* const stringbuf = HBuf8::New(strlen); |
3497 if (!stringbuf) |
3513 if (!stringbuf) |
3498 { |
3514 { |
3499 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for ifc $ desc string failed.")); |
3515 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP3, " Error: Memory allocation for ifc $ desc string failed." ); |
3500 iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3516 iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3501 aIfc->iSettingCode); |
3517 aIfc->iSettingCode); |
3502 return KErrNoMemory; |
3518 return KErrNoMemory; |
3503 } |
3519 } |
3504 stringbuf->SetMax(); |
3520 stringbuf->SetMax(); |
3505 // the aString points to data that lives in user memory, so we have to copy it: |
3521 // the aString points to data that lives in user memory, so we have to copy it: |
3506 TInt r = Kern::ThreadDesRead(aThread, aString, *stringbuf, 0); |
3522 TInt r = Kern::ThreadDesRead(aThread, aString, *stringbuf, 0); |
3507 if (r != KErrNone) |
3523 if (r != KErrNone) |
3508 { |
3524 { |
3509 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Thread read error")); |
3525 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP4, " Error: Thread read error" ); |
3510 iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3526 iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3511 aIfc->iSettingCode); |
3527 aIfc->iSettingCode); |
3512 delete stringbuf; |
3528 delete stringbuf; |
3513 return r; |
3529 return r; |
3514 } |
3530 } |
3515 TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*stringbuf); |
3531 TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*stringbuf); |
3516 if (!sd) |
3532 if (!sd) |
3517 { |
3533 { |
3518 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Memory allocation for ifc $ desc failed.")); |
3534 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP5, " Error: Memory allocation for ifc $ desc failed." ); |
3519 iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3535 iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber, |
3520 aIfc->iSettingCode); |
3536 aIfc->iSettingCode); |
3521 delete stringbuf; |
3537 delete stringbuf; |
3522 return KErrNoMemory; |
3538 return KErrNoMemory; |
3523 } |
3539 } |
3671 } |
3687 } |
3672 |
3688 |
3673 |
3689 |
3674 void DUsbClientController::DeActivateHardwareController() |
3690 void DUsbClientController::DeActivateHardwareController() |
3675 { |
3691 { |
3676 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeActivateHardwareController()")); |
3692 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER, "DUsbClientController::DeActivateHardwareController()" ); |
3677 if (!iHardwareActivated) |
3693 if (!iHardwareActivated) |
3678 { |
3694 { |
3679 __KTRACE_OPT(KUSB, Kern::Printf(" not active -> returning")); |
3695 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP1, " not active -> returning" ); |
3680 return; |
3696 return; |
3681 } |
3697 } |
3682 // Deconfigure & disable endpoint zero |
3698 // Deconfigure & disable endpoint zero |
3683 DeConfigureEndpoint(KEp0_Out); |
3699 DeConfigureEndpoint(KEp0_Out); |
3684 DeConfigureEndpoint(KEp0_In); |
3700 DeConfigureEndpoint(KEp0_In); |
3685 // Stop HW |
3701 // Stop HW |
3686 TInt r = OtgDisableUdc(); // turn off UDC (OTG flavour) |
3702 TInt r = OtgDisableUdc(); // turn off UDC (OTG flavour) |
3687 if (r != KErrNone) |
3703 if (r != KErrNone) |
3688 { |
3704 { |
3689 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: OtgDisableUdc() failed: %d", r)); |
3705 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP2, " Error: OtgDisableUdc() failed: %d", r); |
3690 } |
3706 } |
3691 StopUdc(); |
3707 StopUdc(); |
3692 iHardwareActivated = EFalse; |
3708 iHardwareActivated = EFalse; |
3693 __KTRACE_OPT(KUSB, Kern::Printf(" Controller deactivated.")); |
3709 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP3, " Controller deactivated."); |
3694 if (UsbConnectionStatus()) |
3710 if (UsbConnectionStatus()) |
3695 { |
3711 { |
3696 NextDeviceState(EUsbcDeviceStateAttached); |
3712 NextDeviceState(EUsbcDeviceStateAttached); |
3697 } |
3713 } |
3698 return; |
3714 return; |
3699 } |
3715 } |
3700 |
3716 |
3701 |
3717 |
3702 void DUsbClientController::DeleteInterfaceSet(TInt aIfcSet) |
3718 void DUsbClientController::DeleteInterfaceSet(TInt aIfcSet) |
3703 { |
3719 { |
3704 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeleteInterfaceSet(%d)", aIfcSet)); |
3720 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET, "DUsbClientController::DeleteInterfaceSet(%d)", aIfcSet); |
|
3721 |
3705 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet); |
3722 TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet); |
3706 if (!ifcset_ptr) |
3723 if (!ifcset_ptr) |
3707 { |
3724 { |
3708 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: invalid interface number: %d", aIfcSet)); |
3725 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET_DUP1, " Error: invalid interface number: %d", aIfcSet); |
3709 return; |
3726 return; |
3710 } |
3727 } |
3711 const TInt idx = iConfigs[0]->iInterfaceSets.Find(ifcset_ptr); |
3728 const TInt idx = iConfigs[0]->iInterfaceSets.Find(ifcset_ptr); |
3712 if (idx == KErrNotFound) |
3729 if (idx == KErrNotFound) |
3713 { |
3730 { |
3714 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: interface not found in array")); |
3731 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET_DUP2, " Error: interface not found in array"); |
3715 return; |
3732 return; |
3716 } |
3733 } |
3717 //Add this mutex to protect the interface set data structure |
3734 //Add this mutex to protect the interface set data structure |
3718 if (NKern::CurrentContext() == EThread) |
3735 if (NKern::CurrentContext() == EThread) |
3719 { |
3736 { |
3808 TUsbcRequestCallback* const p = iRequestCallbacks[aEndpointNum]; |
3827 TUsbcRequestCallback* const p = iRequestCallbacks[aEndpointNum]; |
3809 if (p) |
3828 if (p) |
3810 { |
3829 { |
3811 __ASSERT_DEBUG((p->Owner() == aClientId), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3830 __ASSERT_DEBUG((p->Owner() == aClientId), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3812 __ASSERT_DEBUG((p->iTransferDir == aTransferDir), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3831 __ASSERT_DEBUG((p->iTransferDir == aTransferDir), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3813 __KTRACE_OPT(KUSB, Kern::Printf(" removing RequestCallback @ 0x%x", p)); |
3832 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK_DUP2, " removing RequestCallback @ 0x%x", p); |
3814 iRequestCallbacks[aEndpointNum] = NULL; |
3833 iRequestCallbacks[aEndpointNum] = NULL; |
3815 } |
3834 } |
3816 } |
3835 } |
3817 |
3836 |
3818 |
3837 |
3819 void DUsbClientController::DeleteRequestCallbacks(const DBase* aClientId) |
3838 void DUsbClientController::DeleteRequestCallbacks(const DBase* aClientId) |
3820 { |
3839 { |
3821 // aClientId being NULL means: delete all requests for *all* clients. |
3840 // aClientId being NULL means: delete all requests for *all* clients. |
3822 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeleteRequestCallbacks()")); |
3841 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS, "DUsbClientController::DeleteRequestCallbacks()" ); |
3823 // Ep0 OUT |
3842 // Ep0 OUT |
3824 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
3843 const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock); |
3825 TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
3844 TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks); |
3826 TUsbcRequestCallback* p; |
3845 TUsbcRequestCallback* p; |
3827 while ((p = iter++) != NULL) |
3846 while ((p = iter++) != NULL) |
3828 { |
3847 { |
3829 if (!aClientId || p->Owner() == aClientId) |
3848 if (!aClientId || p->Owner() == aClientId) |
3830 { |
3849 { |
3831 __KTRACE_OPT(KUSB, Kern::Printf(" removing RequestCallback @ 0x%x (ep0)", p)); |
3850 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS_DUP1, " removing RequestCallback @ 0x%x (ep0)", p); |
3832 iEp0ReadRequestCallbacks.Remove(*p); |
3851 iEp0ReadRequestCallbacks.Remove(*p); |
3833 } |
3852 } |
3834 } |
3853 } |
3835 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
3854 __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq); |
3836 // Other endpoints |
3855 // Other endpoints |
3837 for (TInt i = 1; i < KUsbcEpArraySize; i++) |
3856 for (TInt i = 1; i < KUsbcEpArraySize; i++) |
3838 { |
3857 { |
3839 TUsbcRequestCallback* const p = iRequestCallbacks[i]; |
3858 TUsbcRequestCallback* const p = iRequestCallbacks[i]; |
3840 if (p && (!aClientId || p->Owner() == aClientId)) |
3859 if (p && (!aClientId || p->Owner() == aClientId)) |
3841 { |
3860 { |
3842 __KTRACE_OPT(KUSB, Kern::Printf(" removing RequestCallback @ 0x%x", p)); |
3861 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS_DUP2, " removing RequestCallback @ 0x%x", p); |
3843 iRequestCallbacks[i] = NULL; |
3862 iRequestCallbacks[i] = NULL; |
3844 } |
3863 } |
3845 } |
3864 } |
3846 } |
3865 } |
3847 |
3866 |
3848 |
3867 |
3849 void DUsbClientController::StatusNotify(TUsbcDeviceState aState, const DBase* aClientId) |
3868 void DUsbClientController::StatusNotify(TUsbcDeviceState aState, const DBase* aClientId) |
3850 { |
3869 { |
3851 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::StatusNotify()")); |
3870 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_STATUSNOTIFY, "DUsbClientController::StatusNotify()" ); |
3852 |
3871 |
3853 // This function may be called by the PSL (via chapter9.cpp) from within an |
3872 // This function may be called by the PSL (via chapter9.cpp) from within an |
3854 // ISR -- so we have to take care what we do here (and also in all |
3873 // ISR -- so we have to take care what we do here (and also in all |
3855 // functions that get called from here). |
3874 // functions that get called from here). |
3856 |
3875 |
3858 TUsbcStatusCallback* p; |
3877 TUsbcStatusCallback* p; |
3859 while ((p = iter++) != NULL) |
3878 while ((p = iter++) != NULL) |
3860 { |
3879 { |
3861 if (!aClientId || aClientId == p->Owner()) |
3880 if (!aClientId || aClientId == p->Owner()) |
3862 { |
3881 { |
3863 __KTRACE_OPT(KUSB, Kern::Printf(" notifying LDD @ 0x%x about %d", p->Owner(), aState)); |
3882 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_STATUSNOTIFY_DUP1, " notifying LDD @ 0x%x about %d", (TUint)p->Owner(), (TUint)aState); |
3864 p->SetState(aState); |
3883 p->SetState(aState); |
3865 p->DoCallback(); |
3884 p->DoCallback(); |
3866 } |
3885 } |
3867 } |
3886 } |
3868 } |
3887 } |
3869 |
3888 |
3870 |
3889 |
3871 void DUsbClientController::EpStatusNotify(TInt aRealEndpoint) |
3890 void DUsbClientController::EpStatusNotify(TInt aRealEndpoint) |
3872 { |
3891 { |
3873 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EpStatusNotify()")); |
3892 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY, "DUsbClientController::EpStatusNotify()" ); |
3874 |
3893 |
3875 // This function may be called by the PSL (via chapter9.cpp) from within an |
3894 // This function may be called by the PSL (via chapter9.cpp) from within an |
3876 // ISR -- so we have to take care what we do here (and also in all |
3895 // ISR -- so we have to take care what we do here (and also in all |
3877 // functions that get called from here). |
3896 // functions that get called from here). |
3878 |
3897 |
3879 const DBase* const client_id = PEndpoint2ClientId(aRealEndpoint); |
3898 const DBase* const client_id = PEndpoint2ClientId(aRealEndpoint); |
3880 if (!client_id) |
3899 if (!client_id) |
3881 { |
3900 { |
3882 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Client not found for real ep %d", aRealEndpoint)); |
3901 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP1, " Error: Client not found for real ep %d", aRealEndpoint); |
3883 return; |
3902 return; |
3884 } |
3903 } |
3885 // Check if there is a notification request queued for that client (if not, we can return here). |
3904 // Check if there is a notification request queued for that client (if not, we can return here). |
3886 TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
3905 TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks); |
3887 TUsbcEndpointStatusCallback* p; |
3906 TUsbcEndpointStatusCallback* p; |
3892 break; |
3911 break; |
3893 } |
3912 } |
3894 } |
3913 } |
3895 if (!p) |
3914 if (!p) |
3896 { |
3915 { |
3897 __KTRACE_OPT(KUSB, Kern::Printf(" No notification request for that client, returning")); |
3916 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP2, " No notification request for that client, returning"); |
3898 return; |
3917 return; |
3899 } |
3918 } |
3900 const TInt ifcset = ClientId2InterfaceNumber(client_id); |
3919 const TInt ifcset = ClientId2InterfaceNumber(client_id); |
3901 if (ifcset < 0) |
3920 if (ifcset < 0) |
3902 { |
3921 { |
3903 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ifcset not found for clientid %d", client_id)); |
3922 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP3, " Error: Ifcset not found for clientid %d", client_id); |
3904 return; |
3923 return; |
3905 } |
3924 } |
3906 const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
3925 const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset); |
3907 if (!ifcset_ptr) |
3926 if (!ifcset_ptr) |
3908 { |
3927 { |
3909 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Ifcset pointer not found for ifcset %d", ifcset)); |
3928 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP4, " Error: Ifcset pointer not found for ifcset %d", ifcset); |
3910 return; |
3929 return; |
3911 } |
3930 } |
3912 const TUsbcInterface* const ifc_ptr = ifcset_ptr->CurrentInterface(); |
3931 const TUsbcInterface* const ifc_ptr = ifcset_ptr->CurrentInterface(); |
3913 if (!ifc_ptr) |
3932 if (!ifc_ptr) |
3914 { |
3933 { |
3915 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Current ifc pointer not found for ifcset %d", ifcset)); |
3934 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP5, " Error: Current ifc pointer not found for ifcset %d", ifcset); |
3916 return; |
3935 return; |
3917 } |
3936 } |
3918 TUint state = 0; |
3937 TUint state = 0; |
3919 const TInt eps = ifc_ptr->iEndpoints.Count(); |
3938 const TInt eps = ifc_ptr->iEndpoints.Count(); |
3920 for (TInt i = 0; i < eps; i++) |
3939 for (TInt i = 0; i < eps; i++) |
3921 { |
3940 { |
3922 const TUsbcLogicalEndpoint* const ep_ptr = ifc_ptr->iEndpoints[i]; |
3941 const TUsbcLogicalEndpoint* const ep_ptr = ifc_ptr->iEndpoints[i]; |
3923 __KTRACE_OPT(KUSB, Kern::Printf(" checking logical ep #%d for stall state...", |
3942 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP6, " checking logical ep #%d for stall state...", |
3924 ep_ptr->iLEndpointNum)); |
3943 ep_ptr->iLEndpointNum); |
3925 if (ep_ptr->iPEndpoint->iHalt) |
3944 if (ep_ptr->iPEndpoint->iHalt) |
3926 { |
3945 { |
3927 __KTRACE_OPT(KUSB, Kern::Printf(" -- stalled")); |
3946 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP7, " -- stalled"); |
3928 // set the bit n to 1, where n is the logical endpoint number minus one |
3947 // set the bit n to 1, where n is the logical endpoint number minus one |
3929 state |= (1 << (ep_ptr->iLEndpointNum - 1)); |
3948 state |= (1 << (ep_ptr->iLEndpointNum - 1)); |
3930 } |
3949 } |
3931 else |
3950 else |
3932 { |
3951 { |
3933 __KTRACE_OPT(KUSB, Kern::Printf(" -- not stalled")); |
3952 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP8, " -- not stalled"); |
3934 } |
3953 } |
3935 } |
3954 } |
3936 __KTRACE_OPT(KUSB, Kern::Printf(" passing ep state 0x%x on to LDD @ 0x%x", state, client_id)); |
3955 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP9, " passing ep state 0x%x on to LDD @ 0x%x", (TUint)state, (TUint)client_id); |
3937 p->SetState(state); |
3956 p->SetState(state); |
3938 p->DoCallback(); |
3957 p->DoCallback(); |
3939 } |
3958 } |
3940 |
3959 |
3941 |
3960 |
3942 void DUsbClientController::OtgFeaturesNotify() |
3961 void DUsbClientController::OtgFeaturesNotify() |
3943 { |
3962 { |
3944 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OtgFeaturesNotify()")); |
3963 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGFEATURESNOTIFY, "DUsbClientController::OtgFeaturesNotify()" ); |
3945 |
3964 |
3946 // This function may be called from the PSL (via PIL's chapter9.cpp) from |
3965 // This function may be called from the PSL (via PIL's chapter9.cpp) from |
3947 // within an ISR -- so we have to take care what we do here (and also in |
3966 // within an ISR -- so we have to take care what we do here (and also in |
3948 // all functions that get called from here). |
3967 // all functions that get called from here). |
3949 |
3968 |
3991 } |
4010 } |
3992 } |
4011 } |
3993 if (ep > 0) // not 'else'! |
4012 if (ep > 0) // not 'else'! |
3994 { |
4013 { |
3995 __ASSERT_DEBUG((iRequestCallbacks[ep] == &aRcb), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
4014 __ASSERT_DEBUG((iRequestCallbacks[ep] == &aRcb), Kern::Fault(KUsbPILPanicCat, __LINE__)); |
3996 __KTRACE_OPT(KUSB, Kern::Printf(" > removing RequestCallback[%d] @ 0x%x", ep, &aRcb)); |
4015 OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSDATATRANSFERDONE_DUP1, " > removing RequestCallback[%d] @ 0x%x", ep, (TUint)&aRcb); |
3997 iRequestCallbacks[ep] = NULL; |
4016 iRequestCallbacks[ep] = NULL; |
3998 } |
4017 } |
3999 aRcb.DoCallback(); |
4018 aRcb.DoCallback(); |
4000 } |
4019 } |
4001 |
4020 |
4002 |
4021 |
4003 void DUsbClientController::NextDeviceState(TUsbcDeviceState aNextState) |
4022 void DUsbClientController::NextDeviceState(TUsbcDeviceState aNextState) |
4004 { |
4023 { |
4005 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::NextDeviceState()")); |
4024 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE, "DUsbClientController::NextDeviceState()" ); |
|
4025 |
4006 #ifdef _DEBUG |
4026 #ifdef _DEBUG |
|
4027 #ifdef OST_TRACE_COMPILER_IN_USE |
4007 const char* const states[] = {"Undefined", "Attached", "Powered", "Default", |
4028 const char* const states[] = {"Undefined", "Attached", "Powered", "Default", |
4008 "Address", "Configured", "Suspended"}; |
4029 "Address", "Configured", "Suspended"}; |
|
4030 #endif |
4009 if ((aNextState >= EUsbcDeviceStateUndefined) && |
4031 if ((aNextState >= EUsbcDeviceStateUndefined) && |
4010 (aNextState <= EUsbcDeviceStateSuspended)) |
4032 (aNextState <= EUsbcDeviceStateSuspended)) |
4011 { |
4033 { |
4012 __KTRACE_OPT(KUSB, Kern::Printf(" next device state: %s", states[aNextState])); |
4034 OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP1, " next device state: %s", states[aNextState]); |
4013 } |
4035 } |
4014 else |
4036 else |
4015 { |
4037 { |
4016 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown next device state: %d", aNextState)); |
4038 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP2, " Error: Unknown next device state: %d", aNextState); |
4017 } |
4039 } |
4018 // Print a warning when an invalid state transition is detected |
4040 // Print a warning when an invalid state transition is detected |
4019 // 'Undefined' is not a state that is mentioned in the USB spec, but |
4041 // 'Undefined' is not a state that is mentioned in the USB spec, but |
4020 // that's what we're in once the cable gets pulled (for instance). |
4042 // that's what we're in once the cable gets pulled (for instance). |
4021 switch (iDeviceState) |
4043 switch (iDeviceState) |
4074 (aNextState != EUsbcDeviceStateAddress) && |
4096 (aNextState != EUsbcDeviceStateAddress) && |
4075 (aNextState != EUsbcDeviceStateConfigured)) |
4097 (aNextState != EUsbcDeviceStateConfigured)) |
4076 break; |
4098 break; |
4077 goto OK; |
4099 goto OK; |
4078 default: |
4100 default: |
4079 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: Unknown current device state: %d", iDeviceState)); |
4101 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP3, " Error: Unknown current device state: %d", iDeviceState); |
4080 goto OK; |
4102 goto OK; |
4081 } |
4103 } |
4082 // KUSB only (instead of KPANIC) so as not to worry people too much where |
4104 // KUSB only (instead of KPANIC) so as not to worry people too much where |
4083 // a particular h/w regularly enforces invalid (but harmless) transitions |
4105 // a particular h/w regularly enforces invalid (but harmless) transitions |
4084 __KTRACE_OPT(KUSB, Kern::Printf(" Warning: Invalid next state from %s", states[iDeviceState])); |
4106 OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP4, " Warning: Invalid next state from %s", states[iDeviceState]); |
4085 OK: |
4107 OK: |
4086 #endif // _DEBUG |
4108 #endif // _DEBUG |
4087 |
4109 |
4088 iDeviceState = aNextState; |
4110 iDeviceState = aNextState; |
4089 StatusNotify(iDeviceState); |
4111 StatusNotify(iDeviceState); |
4090 } |
4112 } |
4091 |
4113 |
4092 |
4114 |
4093 TInt DUsbClientController::ProcessSuspendEvent() |
4115 TInt DUsbClientController::ProcessSuspendEvent() |
4094 { |
4116 { |
4095 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSuspendEvent()")); |
4117 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENT, "DUsbClientController::ProcessSuspendEvent()" ); |
4096 // A suspend interrupt has been received and needs attention. |
4118 // A suspend interrupt has been received and needs attention. |
4097 iDeviceStateB4Suspend = iDeviceState; |
4119 iDeviceStateB4Suspend = iDeviceState; |
4098 // We have to move to the Suspend state immediately (in case it's a genuine Suspend) |
4120 // We have to move to the Suspend state immediately (in case it's a genuine Suspend) |
4099 // because 7.1.7.6 says: "The device must actually be suspended, [...] after no more |
4121 // because 7.1.7.6 says: "The device must actually be suspended, [...] after no more |
4100 // than 10ms of bus inactivity [...]." Assuming we got the interrupt 3ms after the |
4122 // than 10ms of bus inactivity [...]." Assuming we got the interrupt 3ms after the |
4193 // Check whether there's a speed change |
4214 // Check whether there's a speed change |
4194 const TBool was_hs = iHighSpeed; |
4215 const TBool was_hs = iHighSpeed; |
4195 iHighSpeed = CurrentlyUsingHighSpeed(); |
4216 iHighSpeed = CurrentlyUsingHighSpeed(); |
4196 if (!was_hs && iHighSpeed) |
4217 if (!was_hs && iHighSpeed) |
4197 { |
4218 { |
4198 __KTRACE_OPT(KUSB, Kern::Printf(" Moving to High-speed")); |
4219 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP3, " Moving to High-speed" ); |
4199 EnterHighSpeed(); |
4220 EnterHighSpeed(); |
4200 } |
4221 } |
4201 else if (was_hs && !iHighSpeed) |
4222 else if (was_hs && !iHighSpeed) |
4202 { |
4223 { |
4203 __KTRACE_OPT(KUSB, Kern::Printf(" Moving to Full-speed")); |
4224 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP4, " Moving to Full-speed" ); |
4204 EnterFullSpeed(); |
4225 EnterFullSpeed(); |
4205 } |
4226 } |
4206 |
4227 |
4207 // Setup initial Ep0 read (SetupEndpointZeroRead never called from thread) |
4228 // Setup initial Ep0 read (SetupEndpointZeroRead never called from thread) |
4208 if (SetupEndpointZeroRead() != KErrNone) |
4229 if (SetupEndpointZeroRead() != KErrNone) |
4209 { |
4230 { |
4210 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: while setting up Ep0 read")); |
4231 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP5, " Error: while setting up Ep0 read" ); |
4211 return KErrGeneral; |
4232 return KErrGeneral; |
4212 } |
4233 } |
4213 |
4234 |
4214 return KErrNone; |
4235 return KErrNone; |
4215 } |
4236 } |
4216 |
4237 |
4217 |
4238 |
4218 TInt DUsbClientController::ProcessCableInsertEvent() |
4239 TInt DUsbClientController::ProcessCableInsertEvent() |
4219 { |
4240 { |
4220 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessCableInsertEvent()")); |
4241 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSCABLEINSERTEVENT, "DUsbClientController::ProcessCableInsertEvent()" ); |
|
4242 |
4221 #ifdef USB_OTG_CLIENT |
4243 #ifdef USB_OTG_CLIENT |
4222 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: EUsbEventCableInsert shouldn't be sent by an OTG Client PSL")); |
4244 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSCABLEINSERTEVENT_DUP1, " Error: EUsbEventCableInsert shouldn't be sent by an OTG Client PSL" ); |
4223 return KErrArgument; |
4245 return KErrArgument; |
4224 #else |
4246 #else |
4225 NextDeviceState(EUsbcDeviceStateAttached); |
4247 NextDeviceState(EUsbcDeviceStateAttached); |
4226 if (iHardwareActivated) |
4248 if (iHardwareActivated) |
4227 { |
4249 { |
4319 NextDeviceState(iDeviceState); |
4341 NextDeviceState(iDeviceState); |
4320 } |
4342 } |
4321 r = (*iEnablePullUpOnDPlus)(iOtgContext); |
4343 r = (*iEnablePullUpOnDPlus)(iOtgContext); |
4322 if (r != KErrNone) |
4344 if (r != KErrNone) |
4323 { |
4345 { |
4324 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: iEnablePullUpOnDPlus() = %d", r)); |
4346 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP3, " Error: iEnablePullUpOnDPlus() = %d", r); |
4325 } |
4347 } |
4326 } |
4348 } |
4327 else |
4349 else |
4328 { |
4350 { |
4329 __KTRACE_OPT(KUSB, Kern::Printf(" Warning: iEnablePullUpOnDPlus pointer not ready")); |
4351 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP4, " Warning: iEnablePullUpOnDPlus pointer not ready"); |
4330 // We cannot enforce the presence of the pointer (via an ASSERT) |
4352 // We cannot enforce the presence of the pointer (via an ASSERT) |
4331 // since it might only be available at a later point. |
4353 // since it might only be available at a later point. |
4332 // We shouldn't return an error at this point either, since the |
4354 // We shouldn't return an error at this point either, since the |
4333 // problem will be a systematic one. |
4355 // problem will be a systematic one. |
4334 } |
4356 } |
4335 } |
4357 } |
4336 else |
4358 else |
4337 { |
4359 { |
4338 __KTRACE_OPT(KUSB, Kern::Printf(" calling (*iDisablePullUpOnDPlus)()")); |
4360 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP5, " calling (*iDisablePullUpOnDPlus)()"); |
4339 if (iDisablePullUpOnDPlus != NULL) |
4361 if (iDisablePullUpOnDPlus != NULL) |
4340 { |
4362 { |
4341 iDPlusEnabled = enableDPlus; |
4363 iDPlusEnabled = enableDPlus; |
4342 r = (*iDisablePullUpOnDPlus)(iOtgContext); |
4364 r = (*iDisablePullUpOnDPlus)(iOtgContext); |
4343 if (r != KErrNone) |
4365 if (r != KErrNone) |
4344 { |
4366 { |
4345 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: iDisablePullUpOnDPlus() = %d", r)); |
4367 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP6, " Error: iDisablePullUpOnDPlus() = %d", r); |
4346 } |
4368 } |
4347 } |
4369 } |
4348 else |
4370 else |
4349 { |
4371 { |
4350 __KTRACE_OPT(KUSB, Kern::Printf(" Warning: iDisablePullUpOnDPlus pointer not ready")); |
4372 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP7, " Warning: iDisablePullUpOnDPlus pointer not ready"); |
4351 // We cannot enforce the presence of the pointer (via an ASSERT) |
4373 // We cannot enforce the presence of the pointer (via an ASSERT) |
4352 // since it might only be available at a later point. |
4374 // since it might only be available at a later point. |
4353 // We shouldn't return an error at this point either, since the |
4375 // We shouldn't return an error at this point either, since the |
4354 // problem will be a systematic one. |
4376 // problem will be a systematic one. |
4355 } |
4377 } |
4412 // |
4434 // |
4413 // static |
4435 // static |
4414 // |
4436 // |
4415 void DUsbClientController::PowerDownDfc(TAny* aPtr) |
4437 void DUsbClientController::PowerDownDfc(TAny* aPtr) |
4416 { |
4438 { |
4417 __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerDownDfc")); |
4439 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWNDFC, "DUsbClientController::PowerDownDfc" ); |
4418 if (!aPtr) |
4440 if (!aPtr) |
4419 { |
4441 { |
4420 __KTRACE_OPT(KPANIC, Kern::Printf(" Error: !aPtr")); |
4442 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP1, " Error: !aPtr" ); |
4421 return; |
4443 return; |
4422 } |
4444 } |
4423 DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr); |
4445 DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr); |
4424 __PM_ASSERT(!ptr->iStandby); |
4446 __PM_ASSERT(!ptr->iStandby); |
4425 ptr->iStandby = ETrue; |
4447 ptr->iStandby = ETrue; |
4426 // We might not want to power down when the UDC is active: |
4448 // We might not want to power down when the UDC is active: |
4427 if (!ptr->iHardwareActivated || ptr->PowerDownWhenActive()) |
4449 if (!ptr->iHardwareActivated || ptr->PowerDownWhenActive()) |
4428 { |
4450 { |
4429 (void) ptr->PowerDown(); |
4451 (void) ptr->PowerDown(); |
4430 __KTRACE_OPT(KUSB, Kern::Printf("Calling PowerHandler->PowerDownDone()")); |
4452 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP2, "Calling PowerHandler->PowerDownDone()" ); |
4431 ptr->iPowerHandler->PowerDownDone(); |
4453 ptr->iPowerHandler->PowerDownDone(); |
4432 } |
4454 } |
4433 else |
4455 else |
4434 { |
4456 { |
4435 __KTRACE_OPT(KUSB, Kern::Printf("Not calling PowerHandler->PowerDownDone()")); |
4457 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP3, "Not calling PowerHandler->PowerDownDone()" ); |
4436 __KTRACE_OPT(KUSB, Kern::Printf(" because UDC is active.")); |
4458 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP4, " because UDC is active." ); |
4437 } |
4459 } |
4438 } |
4460 } |
4439 |
4461 |
4440 |
4462 |
4441 // -EOF- |
4463 // -EOF- |