sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: @prototype sl@0: sl@0: The driver's name sl@0: sl@0: @return The name of the driver sl@0: sl@0: @internalComponent sl@0: */ sl@0: inline const TDesC& RUsbOtgDriver::Name() sl@0: { sl@0: _LIT( KDriverName, "USBOTGDRIVER" ); sl@0: return KDriverName; sl@0: } sl@0: sl@0: /** sl@0: The driver's version sl@0: sl@0: @return The version number of the driver sl@0: sl@0: @internalComponent sl@0: */ sl@0: inline TVersion RUsbOtgDriver::VersionRequired() sl@0: { sl@0: const TInt KBuildVersionNumber = KE32BuildVersionNumber; sl@0: sl@0: return TVersion( KMajorVersionNumber, KMinorVersionNumber, KBuildVersionNumber ); sl@0: } sl@0: sl@0: #ifndef __KERNEL_MODE__ sl@0: sl@0: /** sl@0: Open a a logical channel to the OTG driver sl@0: sl@0: @return System-wide error code giving status of connection attempt. sl@0: */ sl@0: inline TInt RUsbOtgDriver::Open() sl@0: { sl@0: TInt rc = KErrNone; sl@0: sl@0: // Check to see if this object has already been opened - if it has, sl@0: // there will be a handle set. sl@0: sl@0: if ( Handle() ) sl@0: { sl@0: User::Panic(OtgdiPanics::KUsbOtgDriverPanicCat, OtgdiPanics::EUsbOtgDriverAlreadyOpened); sl@0: } sl@0: sl@0: rc = DoCreate( Name(), VersionRequired(), KNullUnit, NULL, NULL, EOwnerThread ); sl@0: sl@0: // We expect back KErrNone - any other problem indicates an attempt by sl@0: // the caller to double-open the driver, which is forbidden sl@0: sl@0: if ( rc != KErrNone ) sl@0: { sl@0: RDebug::Print(_L("********************************")); sl@0: RDebug::Print(_L("* RUsbOtgDriver::Open() Fault! *")); sl@0: RDebug::Print(_L("********************************")); sl@0: } sl@0: sl@0: return rc; sl@0: } sl@0: sl@0: /** sl@0: Special method to alter the default behaviour of the stack: sl@0: sl@0: Test mode is activated (special) sl@0: sl@0: @return Driver-specific error code or system-wide success sl@0: */ sl@0: inline TInt RUsbOtgDriver::ActivateOptTestMode() sl@0: { sl@0: return DoControl( EActivateOptTestMode ); sl@0: } sl@0: sl@0: /** sl@0: Overall command to start USB stacks sl@0: sl@0: @return Driver-specific error code or system-wide success sl@0: */ sl@0: inline TInt RUsbOtgDriver::StartStacks() sl@0: { sl@0: return DoControl( EStartStacks ); sl@0: } sl@0: sl@0: /** sl@0: Overall command to stop USB stacks sl@0: */ sl@0: inline void RUsbOtgDriver::StopStacks() sl@0: { sl@0: static_cast(DoControl( EStopStacks )); sl@0: } sl@0: sl@0: /** sl@0: Generic event-reporting mechanism, provided in the form of a standard sl@0: watcher which registers and allows user to block until notification. sl@0: sl@0: To cater for rapidly-occurring events, this function will return the sl@0: earliest event code (assuming a FIFO stack model for recording such sl@0: events) sl@0: sl@0: The notification function does not support multiple instances, it is expected sl@0: to be limited solely to ownership by USBMAN sl@0: sl@0: @param aOldestEvent parameter to collect the TOtgEvent sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgEventRequest(TOtgEvent& aOldestEvent, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgEventRequest, aStatus, &aOldestEvent ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for event notification sl@0: sl@0: Note that the 'cancel' function does not return an error code in the event sl@0: that there is no registered watcher: it is assumed that the code sl@0: within will contain an ASSERT_DEBUG check to confirm watcher validity. sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgEventRequest() sl@0: { sl@0: static_cast(DoControl( ECancelOtgEventRequest )); sl@0: } sl@0: sl@0: /** sl@0: Generic state-reporting mechanism, provided in the form of a standard sl@0: watcher which registers and allows user to block until notification. sl@0: sl@0: To cater for rapidly-occurring changes, this function will return the sl@0: earliest state code (assuming a FIFO stack model for recording such sl@0: States) sl@0: sl@0: The notification function does not support multiple instances, it is expected sl@0: to be limited solely to ownership by USBMAN sl@0: sl@0: @param aState parameter to collect the TOtgState sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgStateRequest(TOtgState& aState, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgStateRequest, aStatus, &aState ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for state notification sl@0: sl@0: Note that the 'cancel' function does not return an error code in the event sl@0: that there is no registered watcher: it is assumed that the code sl@0: within will contain an ASSERT_DEBUG check to confirm watcher validity. sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgStateRequest() sl@0: { sl@0: static_cast(DoControl( ECancelOtgStateRequest )); sl@0: } sl@0: sl@0: /** sl@0: Generic message-reporting mechanism, provided in the form of a standard sl@0: watcher which registers and allows user to block until notification. sl@0: sl@0: To cater for rapidly-occurring changes, this function will return the sl@0: earliest message code (assuming a FIFO stack model for recording such sl@0: Messages) sl@0: sl@0: The notification function does not support multiple instances, it is expected sl@0: to be limited solely to ownership by USBMAN sl@0: sl@0: @param aMessage parameter to collect the TOtgMessage sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgMessageRequest(TOtgMessage& aMessage, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgMessageRequest, aStatus, &aMessage ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for message notification sl@0: sl@0: Note that the 'cancel' function does not return an error code in the event sl@0: that there is no registered watcher: it is assumed that the code sl@0: within will contain an ASSERT_DEBUG check to confirm watcher validity. sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgMessageRequest() sl@0: { sl@0: static_cast(DoControl( ECancelOtgMessageRequest )); sl@0: } sl@0: sl@0: /** sl@0: Single-purpose instant-report mechanism to return the current state sl@0: of the ID-Pin on the MIni/Micro-AB connector. sl@0: sl@0: This method is expected to complete immediately and return the sl@0: *current* state of the ID-Pin, it will omit any intermediate sl@0: changes that may have occurred since it was last called. sl@0: sl@0: @param aCurrentIdPin parameter to collect the ID-Pin state sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgIdPinNotification(TOtgIdPin& aCurrentIdPin, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgIdPinNotification, aStatus, &aCurrentIdPin ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for ID-Pin notification sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgIdPinNotification() sl@0: { sl@0: static_cast(DoControl( ECancelOtgIdPinNotification )); sl@0: } sl@0: sl@0: /** sl@0: Single-purpose instant-report mechanism to return the current state sl@0: of the Voltage level on the Mini/Micro-AB connector. sl@0: sl@0: This method is expected to complete immediately and return the sl@0: *current* state of the voltage, it will omit any intermediate sl@0: changes that may have occurred since it was last called. sl@0: sl@0: @param aCurrentVbus parameter to collect the voltage state sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgVbusNotification(TOtgVbus& aCurrentVbus, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgVbusNotification, aStatus, &aCurrentVbus ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for Vbus notification sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgVbusNotification() sl@0: { sl@0: static_cast(DoControl( ECancelOtgVbusNotification )); sl@0: } sl@0: sl@0: /** sl@0: Single-purpose instant-report mechanism to return the current state sl@0: of the permissive/advisory that indicates 'idle' state where it is sl@0: deemed safe to drop VBUS. sl@0: sl@0: This method is expected to complete immediately and return the sl@0: *current* state of the idleness, it will omit any intermediate sl@0: changes that may have occurred since it was last called. sl@0: sl@0: @param aCurrentIdle parameter to collect the idle state sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgConnectionNotification(TOtgConnection& aCurrentIdle, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgConnectionNotification, aStatus, &aCurrentIdle ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for Idle notification sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgConnectionNotification() sl@0: { sl@0: static_cast(DoControl( ECancelOtgConnectionNotification )); sl@0: } sl@0: sl@0: /** sl@0: Single-purpose instant-report mechanism to return the current state sl@0: of the OTG state machine sl@0: sl@0: This method is expected to complete immediately and return the sl@0: *current* state, it will omit any intermediate changes that may sl@0: have occurred since it was last called. sl@0: sl@0: @param aCurrentState parameter to collect the state sl@0: @param aStatus standard request completion sl@0: */ sl@0: inline void RUsbOtgDriver::QueueOtgStateNotification(TOtgState& aCurrentState, TRequestStatus& aStatus) sl@0: { sl@0: DoRequest( EQueueOtgStateNotification, aStatus, &aCurrentState ); sl@0: } sl@0: sl@0: /** sl@0: Cancellation method for State notification sl@0: */ sl@0: inline void RUsbOtgDriver::CancelOtgStateNotification() sl@0: { sl@0: static_cast(DoControl( ECancelOtgStateNotification )); sl@0: } sl@0: sl@0: /** sl@0: USBMAN wants to assert bus request for 'Host' or 'Peripheral' duty sl@0: sl@0: Default-Host: this will result in an attempt to raise Vbus sl@0: sl@0: Default-Device: this will result in an attempt to use SRP(+HNP) sl@0: sl@0: The bus request is asserted until BusDrop() is called. sl@0: sl@0: @return Error code returns are related to the current OTG state context sl@0: at the time of calling, and not to the asynchronous result sl@0: (which is reported via event notification) sl@0: */ sl@0: inline TInt RUsbOtgDriver::BusRequest() sl@0: { sl@0: return DoControl( EBusRequest ); sl@0: } sl@0: sl@0: /** sl@0: USBMAN wants to permit use of the bus, in response to a request from sl@0: the other (B) end of the link to make use of it. sl@0: sl@0: @return Error code returns are related to the current OTG state context sl@0: at the time of calling, and not to the asynchronous result sl@0: (which is reported via event notification) sl@0: */ sl@0: inline TInt RUsbOtgDriver::BusRespondSrp() sl@0: { sl@0: return DoControl( EBusRespondSrp ); sl@0: } sl@0: sl@0: /** sl@0: USBMAN wants to stop using the bus. sl@0: sl@0: This function can only be called from the A-Device and will result in sl@0: the voltage drive being removed from the Vbus line. sl@0: sl@0: @return Error code returns are related to the current OTG state context sl@0: at the time of calling, and not to the asynchronous result sl@0: (which is reported via event notification) sl@0: sl@0: In particular, this function will return an error code if it sl@0: is called in any 'B' state sl@0: */ sl@0: inline TInt RUsbOtgDriver::BusDrop() sl@0: { sl@0: return DoControl( EBusDrop ); sl@0: } sl@0: sl@0: /** sl@0: USBMAN wants to clear the bus error state. sl@0: sl@0: This function can only be called from the A-Device and will result in sl@0: the OTG state machine being moved out of the A_VBUS_ERR state. sl@0: sl@0: @return Error code returns are related to the current OTG state context sl@0: at the time of calling, and not to the asynchronous result sl@0: (which is reported via event notification) sl@0: sl@0: In particular, this function will return an error code if it sl@0: is called in any 'B' state sl@0: */ sl@0: inline TInt RUsbOtgDriver::BusClearError() sl@0: { sl@0: return DoControl( EBusClearError ); sl@0: } sl@0: sl@0: #endif // !__KERNEL_MODE__