usbmgmt/usbmgr/usbman/chargingplugin/src/CUsbBatteryChargingPlugin.cpp
changeset 54 320d509f1a12
parent 36 1a2a19ee918d
equal deleted inserted replaced
51:eaaed528d5fd 54:320d509f1a12
    16 */
    16 */
    17 
    17 
    18 /** @file
    18 /** @file
    19 @internalComponent
    19 @internalComponent
    20 */
    20 */
    21 #include "CUsbBatteryChargingPlugin.h"
       
    22 #include <e32debug.h> 
    21 #include <e32debug.h> 
    23 #include <e32def.h>
    22 #include <e32def.h>
    24 #include <usb/usblogger.h>
       
    25 #include <e32property.h>
    23 #include <e32property.h>
    26 #include <centralrepository.h>
       
    27 #include <usbotgdefs.h>
    24 #include <usbotgdefs.h>
    28 #include <musbmanextensionpluginobserver.h>
    25 #include <musbmanextensionpluginobserver.h>
    29 
    26 #include <centralrepository.h>
    30 
    27 
       
    28 #include "CUsbBatteryChargingPlugin.h"
    31 #include "chargingstates.h"
    29 #include "chargingstates.h"
    32 #include "cusbbatterycharginglicenseehooks.h"
       
    33 #include "reenumerator.h"
    30 #include "reenumerator.h"
    34 
    31 
    35 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV          // For host OTG enabled charging plug-in 
    32 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV          // For host OTG enabled charging plug-in 
    36 #include "idpinwatcher.h"
    33 #include "idpinwatcher.h"
    37 #include "otgstatewatcher.h"
    34 #include "otgstatewatcher.h"
    44 #endif
    41 #endif
    45 
    42 
    46 
    43 
    47 static const TInt KUsbBatteryChargingConfigurationDescriptorCurrentOffset = 8; // see bMaxPower in section 9.6.3 of USB Spec 2.0
    44 static const TInt KUsbBatteryChargingConfigurationDescriptorCurrentOffset = 8; // see bMaxPower in section 9.6.3 of USB Spec 2.0
    48 static const TInt KUsbBatteryChargingCurrentRequestTimeout = 3000000; // 3 seconds
    45 static const TInt KUsbBatteryChargingCurrentRequestTimeout = 3000000; // 3 seconds
       
    46 static const TUint8 KMinCurrent     = 8;    // See USB OTG specification , min current
       
    47 static const TUint8 KbmAttributes   = 7;    // see bmAttributes in section 9.6.3 of USB Spec 2.0
       
    48 static const TUint8 KSelfPowered    = 0x40; // Bitmask to bmAttributes (01000000)
       
    49 
       
    50 
    49 
    51 
    50 
    52 
    51 /**
    53 /**
    52 Factory function.
    54 Factory function.
    53 @return Ownership of a new CUsbBatteryChargingPlugin.
    55 @return Ownership of a new CUsbBatteryChargingPlugin.
    69     OstTraceFunctionEntry1( REF_CUSBBATTERYCHARGINGPLUGIN_CUSBBATTERYCHARGINGPLUGIN_DES_ENTRY, this );
    71     OstTraceFunctionEntry1( REF_CUSBBATTERYCHARGINGPLUGIN_CUSBBATTERYCHARGINGPLUGIN_DES_ENTRY, this );
    70     
    72     
    71     iCurrentValues.Close();
    73     iCurrentValues.Close();
    72     delete iDeviceReEnumerator;
    74     delete iDeviceReEnumerator;
    73     delete iDeviceStateTimer;
    75     delete iDeviceStateTimer;
    74     delete iRepositoryNotifier;
       
    75     delete iLicenseeHooks;
       
    76     
    76     
    77 // For host OTG enabled charging plug-in
    77 // For host OTG enabled charging plug-in
    78 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    78 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
    79     delete iIdPinWatcher;
    79     delete iIdPinWatcher;
    80     delete iOtgStateWatcher;
    80     delete iOtgStateWatcher;
    99 /**
    99 /**
   100 2nd-phase construction.
   100 2nd-phase construction.
   101 */
   101 */
   102 void CUsbBatteryChargingPlugin::ConstructL()
   102 void CUsbBatteryChargingPlugin::ConstructL()
   103     {
   103     {
   104    OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_ENTRY );
   104     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_ENTRY );
   105    
   105    
       
   106     iUsbSpeedType = EUsbFullSpeed;
       
   107 	iChargingInfo().iChargingPortType = EUsbChargingPortTypeStandardDownstreamPort;
       
   108 	iChargingInfo().iUsbConnStatus = EUsbConnectionStatusNone;
       
   109 	iChargingInfo().iMinAvailableVbusCurrent = 0;
       
   110 	iChargingInfo().iMaxVbusCurrent = 0;
       
   111 	iChargingInfo().iMinVbusVoltage = 0;	
       
   112 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1		
       
   113 	iChargingInfo().iChargingPortType = EUsbChargingPortTypeNone;
       
   114 	iChargerDetectotCaps.iCapabilities = 0;
       
   115 #endif
       
   116 	iLastPublishedInfo = iChargingInfo();
       
   117 
   106     // Create state objects
   118     // Create state objects
   107     iPluginStates[EPluginStateIdle] = 
   119     iPluginStates[EPluginStateIdle] = 
   108         new (ELeave) TUsbBatteryChargingPluginStateIdle(*this);
   120         new (ELeave) TUsbBatteryChargingPluginStateIdle(*this);
   109     iPluginStates[EPluginStateCurrentNegotiating] = 
   121     iPluginStates[EPluginStateCurrentNegotiating] = 
   110         new (ELeave) TUsbBatteryChargingPluginStateCurrentNegotiating(*this);
   122         new (ELeave) TUsbBatteryChargingPluginStateCurrentNegotiating(*this);
   111     iPluginStates[EPluginStateCharging] = 
       
   112         new (ELeave) TUsbBatteryChargingPluginStateCharging(*this);
       
   113     iPluginStates[EPluginStateNoValidCurrent] = 
   123     iPluginStates[EPluginStateNoValidCurrent] = 
   114         new (ELeave) TUsbBatteryChargingPluginStateNoValidCurrent(*this);
   124         new (ELeave) TUsbBatteryChargingPluginStateNoValidCurrent(*this);
   115     iPluginStates[EPluginStateIdleNegotiated] = 
   125     iPluginStates[EPluginStateIdleNegotiated] = 
   116         new (ELeave) TUsbBatteryChargingPluginStateIdleNegotiated(*this);
   126         new (ELeave) TUsbBatteryChargingPluginStateIdleNegotiated(*this);
   117     iPluginStates[EPluginStateUserDisabled] = 
       
   118         new (ELeave) TUsbBatteryChargingPluginStateUserDisabled(*this);
       
   119     iPluginStates[EPluginStateBEndedCableNotPresent] = 
   127     iPluginStates[EPluginStateBEndedCableNotPresent] = 
   120         new (ELeave) TUsbBatteryChargingPluginStateBEndedCableNotPresent(*this);
   128         new (ELeave) TUsbBatteryChargingPluginStateBEndedCableNotPresent(*this);
   121 
   129 
   122     // Set initial state to idle
   130     // Set initial state to idle
   123     SetState(EPluginStateIdle);
   131     SetState(EPluginStateIdle);
   124     
   132     
   125     TInt err = RProperty::Define(KPropertyUidUsbBatteryChargingCategory,
   133     TInt err = RProperty::Define(KPropertyUidUsbBatteryChargingCategory,
   126                       KPropertyUidUsbBatteryChargingAvailableCurrent,
   134                       KPropertyUidUsbBatteryChargingInfo,
   127                       RProperty::EInt,
   135                       RProperty::EByteArray,
   128                       ECapabilityReadDeviceData,
   136                       sizeof(TPublishedUsbChargingInfo));
   129                       ECapabilityCommDD);
       
   130 
   137 
   131     if(err == KErrNone || err == KErrAlreadyExists)
   138     if(err == KErrNone || err == KErrAlreadyExists)
   132         {
   139         {
   133 
       
   134         err = RProperty::Define(KPropertyUidUsbBatteryChargingCategory,
       
   135                           KPropertyUidUsbBatteryChargingChargingCurrent,
       
   136                           RProperty::EInt,
       
   137                           ECapabilityReadDeviceData,
       
   138                           ECapabilityCommDD);
       
   139         }
       
   140     else
       
   141         {
       
   142         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL, "CUsbBatteryChargingPlugin::ConstructL;leave with error=%d", err );
       
   143         User::Leave(err );
       
   144         }
       
   145 
       
   146     if(err == KErrNone || err == KErrAlreadyExists)
       
   147         {
       
   148         err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
   140         err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
   149                                         KPropertyUidUsbBatteryChargingAvailableCurrent,
   141                       KPropertyUidUsbBatteryChargingInfo,
   150                                         0);
   142                       iChargingInfo);
   151         }
   143         }
   152     else
   144 	else
       
   145 		{		
       
   146         User::Leave(err);
       
   147 		}
       
   148 
       
   149     if(err != KErrNone)
   153         {
   150         {
   154         static_cast<void> (RProperty::Delete (
   151         static_cast<void> (RProperty::Delete (
   155                 KPropertyUidUsbBatteryChargingCategory,
   152                 KPropertyUidUsbBatteryChargingCategory,
   156                 KPropertyUidUsbBatteryChargingAvailableCurrent ));
   153                 KPropertyUidUsbBatteryChargingInfo ));
   157         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_DUP1, "CUsbBatteryChargingPlugin::ConstructL;leave with error=%d", err );
       
   158         User::Leave(err);
   154         User::Leave(err);
   159         }
   155         }
   160     
       
   161     err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   162                                         KPropertyUidUsbBatteryChargingChargingCurrent,
       
   163                                         0);
       
   164 
       
   165     if(err != KErrNone)
       
   166         {
       
   167         static_cast<void> (RProperty::Delete (
       
   168                 KPropertyUidUsbBatteryChargingCategory,
       
   169                 KPropertyUidUsbBatteryChargingAvailableCurrent ));
       
   170         static_cast<void> (RProperty::Delete (
       
   171                 KPropertyUidUsbBatteryChargingCategory,
       
   172                 KPropertyUidUsbBatteryChargingChargingCurrent ));
       
   173         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_DUP2, "CUsbBatteryChargingPlugin::ConstructL;leave with error=%d", err );
       
   174         User::Leave(err );
       
   175         }
       
   176         
   156         
   177     iRepositoryNotifier = CUsbChargingRepositoryNotifier::NewL (*this,
       
   178             KUsbBatteryChargingCentralRepositoryUid,
       
   179             KUsbBatteryChargingKeyEnabledUserSetting );
       
   180     iDeviceStateTimer = CUsbChargingDeviceStateTimer::NewL(*this);
   157     iDeviceStateTimer = CUsbChargingDeviceStateTimer::NewL(*this);
   181 
   158 
   182     iDeviceReEnumerator = CUsbChargingReEnumerator::NewL(iLdd);
   159     iDeviceReEnumerator = CUsbChargingReEnumerator::NewL(iLdd);
   183 
   160 
   184     iPluginState = EPluginStateIdle;
   161     iPluginState = EPluginStateIdle;
   185     iPluginStateToRecovery = EPluginStateIdle;
       
   186     ReadCurrentRequestValuesL();
   162     ReadCurrentRequestValuesL();
   187     iVBusWatcher = CVBusWatcher::NewL(this);
   163     iVBusWatcher = CVBusWatcher::NewL(this);
   188     iVBusState = iVBusWatcher->VBusState();
   164     iVBusState = iVBusWatcher->VBusState();
   189     
   165     
   190 // For host OTG enabled charging plug-in
   166 // For host OTG enabled charging plug-in
   207         {
   183         {
   208         iPluginState = EPluginStateBEndedCableNotPresent;
   184         iPluginState = EPluginStateBEndedCableNotPresent;
   209         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_DUP3, "CUsbBatteryChargingPlugin::ConstructL;PluginState => EPluginStateADevice(%d)", iPluginState );
   185         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_DUP3, "CUsbBatteryChargingPlugin::ConstructL;PluginState => EPluginStateADevice(%d)", iPluginState );
   210         }
   186         }
   211 
   187 
   212     Observer().RegisterStateObserverL(*this);
   188     Observer().RegisterStateObserverL(*this);  
   213 
   189 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1		
   214     iLicenseeHooks = CUsbBatteryChargingLicenseeHooks::NewL();
   190 	MUsbChargingNotify* charging = static_cast<MUsbChargingNotify*>(this);
   215     OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_DUP4, "CUsbBatteryChargingPlugin::ConstructL;Created licensee specific hooks" );
   191     Observer().RegisterChargingObserverL(*charging);  
   216     
   192 #endif	
   217     // Set initial recovery state to idle
       
   218     PushRecoverState(EPluginStateIdle);
       
   219     
       
   220     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_EXIT );
   193     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_CONSTRUCTL_EXIT );
   221     }
   194     }
   222 
   195 
   223 // For host OTG enabled charging plug-in
   196 // For host OTG enabled charging plug-in
   224 TBool CUsbBatteryChargingPlugin::IsUsbChargingPossible()
   197 TBool CUsbBatteryChargingPlugin::IsUsbChargingPossible()
   225     {
   198     {
   226 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   199 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV
   227     // VBus is off, so there is no way to do charging
       
   228     if (0 == iVBusState)
       
   229         {
       
   230         return EFalse;
       
   231         }
       
   232     
       
   233     // 'A' end cable connected. I'm the power supplier, with no way to charge myself :-) 
   200     // 'A' end cable connected. I'm the power supplier, with no way to charge myself :-) 
   234     if (EUsbBatteryChargingIdPinARole == iIdPinState)
   201     if (EUsbBatteryChargingIdPinARole == iIdPinState)
   235         {
   202         {
   236         return EFalse;
   203         return EFalse;
   237         }
   204         }
   321     OstTrace1( TRACE_FLOW, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE, "CUsbBatteryChargingPlugin::GetInterface;this = [0x%08x]", this );
   288     OstTrace1( TRACE_FLOW, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE, "CUsbBatteryChargingPlugin::GetInterface;this = [0x%08x]", this );
   322     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP1, "CUsbBatteryChargingPlugin::GetInterface;aUid = 0x%08x", aUid.iUid );
   289     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP1, "CUsbBatteryChargingPlugin::GetInterface;aUid = 0x%08x", aUid.iUid );
   323     (void)aUid;
   290     (void)aUid;
   324 
   291 
   325     TAny* ret = NULL;
   292     TAny* ret = NULL;
   326 
       
   327     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP2, "CUsbBatteryChargingPlugin::GetInterface;ret = [0x%08x]", ret );
   293     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP2, "CUsbBatteryChargingPlugin::GetInterface;ret = [0x%08x]", ret );
   328     return ret;
   294     return ret;
   329     }
   295     }
   330 
   296 
   331 void CUsbBatteryChargingPlugin::Panic(TUsbBatteryChargingPanic aPanic)
   297 void CUsbBatteryChargingPlugin::Panic(TUsbBatteryChargingPanic aPanic)
   336     }
   302     }
   337 
   303 
   338 void CUsbBatteryChargingPlugin::UsbServiceStateChange(TInt /*aLastError*/, TUsbServiceState /*aOldState*/, TUsbServiceState /*aNewState*/)
   304 void CUsbBatteryChargingPlugin::UsbServiceStateChange(TInt /*aLastError*/, TUsbServiceState /*aOldState*/, TUsbServiceState /*aNewState*/)
   339     {
   305     {
   340     // not used
   306     // not used
   341     }
       
   342 
       
   343 void CUsbBatteryChargingPlugin::PushRecoverState(TUsbChargingPluginState aRecoverState)
       
   344     {
       
   345     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_PUSHRECOVERSTATE_ENTRY );
       
   346 
       
   347     if((aRecoverState == EPluginStateIdle)||
       
   348        (aRecoverState == EPluginStateIdleNegotiated) ||
       
   349        (aRecoverState == EPluginStateBEndedCableNotPresent) ||
       
   350        (aRecoverState == EPluginStateNoValidCurrent))
       
   351         {
       
   352         iPluginStateToRecovery = aRecoverState;
       
   353         }
       
   354     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_PUSHRECOVERSTATE_EXIT );
       
   355     }
       
   356 
       
   357 TUsbChargingPluginState CUsbBatteryChargingPlugin::PopRecoverState()
       
   358     {
       
   359     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_POPRECOVERSTATE_ENTRY );
       
   360     
       
   361     SetState(iPluginStateToRecovery);
       
   362     
       
   363     iPluginStateToRecovery = EPluginStateIdle;
       
   364     
       
   365     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_POPRECOVERSTATE_EXIT );
       
   366     return iPluginStateToRecovery;
       
   367     }
   307     }
   368 
   308 
   369 TUsbChargingPluginState CUsbBatteryChargingPlugin::SetState(TUsbChargingPluginState aState)
   309 TUsbChargingPluginState CUsbBatteryChargingPlugin::SetState(TUsbChargingPluginState aState)
   370     {
   310     {
   371     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE_ENTRY );
   311     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE_ENTRY );
   377             ResetPlugin();
   317             ResetPlugin();
   378             iCurrentState = iPluginStates[aState];
   318             iCurrentState = iPluginStates[aState];
   379             }
   319             }
   380             break;
   320             break;
   381         case EPluginStateCurrentNegotiating:
   321         case EPluginStateCurrentNegotiating:
   382         case EPluginStateCharging:
       
   383         case EPluginStateNoValidCurrent:
   322         case EPluginStateNoValidCurrent:
   384         case EPluginStateIdleNegotiated:
   323         case EPluginStateIdleNegotiated:
   385         case EPluginStateUserDisabled:
       
   386         case EPluginStateBEndedCableNotPresent:
   324         case EPluginStateBEndedCableNotPresent:
   387             {
       
   388             iPluginState = aState;
       
   389             iCurrentState = iPluginStates[aState];
   325             iCurrentState = iPluginStates[aState];
   390             }
   326 			break;			
   391             break;
       
   392         default:
   327         default:
   393             // Should never happen ...
   328             // Should never happen ...
   394             iPluginState = EPluginStateIdle;
   329             iPluginState = EPluginStateIdle;
   395             iCurrentState = iPluginStates[EPluginStateIdle];
   330             iCurrentState = iPluginStates[EPluginStateIdle];
   396     
   331     
   427         TUsbDeviceState aOldState, TUsbDeviceState aNewState)
   362         TUsbDeviceState aOldState, TUsbDeviceState aNewState)
   428     {
   363     {
   429     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_ENTRY );
   364     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_ENTRY );
   430     
   365     
   431     iCurrentState->UsbDeviceStateChange(aLastError, aOldState, aNewState);
   366     iCurrentState->UsbDeviceStateChange(aLastError, aOldState, aNewState);
       
   367 	UpdateChargingInfo();
   432     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_EXIT );
   368     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_EXIT );
   433     }
       
   434 
       
   435 void CUsbBatteryChargingPlugin::HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal)
       
   436     {
       
   437     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_HANDLEREPOSITORYVALUECHANGEDL_ENTRY );
       
   438 
       
   439     iCurrentState->HandleRepositoryValueChangedL(aRepository, aId, aVal);
       
   440     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_HANDLEREPOSITORYVALUECHANGEDL_EXIT );
       
   441     }
   369     }
   442 
   370 
   443 void CUsbBatteryChargingPlugin::DeviceStateTimeout()
   371 void CUsbBatteryChargingPlugin::DeviceStateTimeout()
   444     {
   372     {
   445     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_ENTRY );
   373     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_ENTRY );
   446         
   374         
   447     iCurrentState->DeviceStateTimeout();
   375     iCurrentState->DeviceStateTimeout();	
       
   376 	UpdateChargingInfo();
   448     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_EXIT );
   377     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_EXIT );
   449     }
   378     }
   450 
   379 
   451 void CUsbBatteryChargingPlugin::NegotiateNextCurrentValueL()
   380 void CUsbBatteryChargingPlugin::NegotiateNextCurrentValueL()
   452     {
   381     {
   465         {
   394         {
   466         // there are more current values left to try
   395         // there are more current values left to try
   467         iCurrentIndexRequested++;
   396         iCurrentIndexRequested++;
   468         newCurrent = iCurrentValues[iCurrentIndexRequested];    
   397         newCurrent = iCurrentValues[iCurrentIndexRequested];    
   469         }
   398         }
   470     else if(iRequestedCurrentValue != 0)
   399     else if(iRequestedCurrentValue != 0 && iRequestedCurrentValue != KMinCurrent)
   471         {
   400         {
   472         // There isn't a 0ma round set from the Repository source -> 10208DD7.txt
   401         newCurrent = KMinCurrent;
   473         // Just add it to make sure the device can be accepted by host    
       
   474         newCurrent = 0;
       
   475         }
   402         }
   476     else
   403     else
   477         {
   404         {
   478         // Warning 0001: If you go here, something wrong happend, check it.
   405         iPluginState = EPluginStateNoValidCurrent;
   479         __ASSERT_DEBUG(0,Panic(EUsbBatteryChargingPanicBadCharingCurrentNegotiation));
   406         User::Leave(EUsbBatteryChargingPanicBadCharingCurrentNegotiation);
   480         }
   407         }
   481     
   408     
   482     RequestCurrentL(newCurrent);
   409     RequestCurrentL(newCurrent);
   483     iRequestedCurrentValue = newCurrent;
   410     iRequestedCurrentValue = newCurrent;
   484     iPluginState = EPluginStateCurrentNegotiating;
   411     iPluginState = EPluginStateCurrentNegotiating;
   491     
   418     
   492     if((iPluginState != EPluginStateIdle))
   419     if((iPluginState != EPluginStateIdle))
   493         {
   420         {
   494         iDeviceStateTimer->Cancel(); // doesn't matter if not running
   421         iDeviceStateTimer->Cancel(); // doesn't matter if not running
   495         iPluginState = EPluginStateIdle;
   422         iPluginState = EPluginStateIdle;
   496         iPluginStateToRecovery = EPluginStateIdle;
       
   497         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN, "CUsbBatteryChargingPlugin::ResetPlugin;PluginState => EPluginStateIdle(%d)", iPluginState );
   423         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN, "CUsbBatteryChargingPlugin::ResetPlugin;PluginState => EPluginStateIdle(%d)", iPluginState );
   498 
   424 
   499         iRequestedCurrentValue = 0;
   425         iRequestedCurrentValue = 0;
   500         iCurrentIndexRequested = 0;
   426         iCurrentIndexRequested = 0;
   501         iAvailableMilliAmps = 0;
   427         iAvailableMilliAmps = 0;
   502         SetNegotiatedCurrent(0);
   428 		iBDevMaxPower = 0;
       
   429         UpdateChargingInfo();
   503         TRAP_IGNORE(SetInitialConfigurationL());
   430         TRAP_IGNORE(SetInitialConfigurationL());
   504         }
   431         }
   505     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN_EXIT );
   432     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN_EXIT );
   506     }
   433     }
   507 
   434 
   529         if(err < 0)
   456         if(err < 0)
   530             {
   457             {
   531             OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP3, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.GetConfigurationDescriptor(ptr) with error=%d", err );
   458             OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP3, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.GetConfigurationDescriptor(ptr) with error=%d", err );
   532             User::Leave(err);
   459             User::Leave(err);
   533             }
   460             }
       
   461 
       
   462 		// compliant to charging adaptation in modem adaptation
       
   463         TUint8 bmAttributes = ptr[KbmAttributes];
       
   464         bmAttributes &= ~(KSelfPowered);
       
   465         ptr[KbmAttributes] = bmAttributes;
   534 
   466 
   535         // set bMaxPower field. One unit = 2mA, so need to halve aMilliAmps.
   467         // set bMaxPower field. One unit = 2mA, so need to halve aMilliAmps.
   536         OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP4, "CUsbBatteryChargingPlugin::RequestCurrentL;Setting bMaxPower to %u mA ( = %u x 2mA units)", aMilliAmps, aMilliAmps >> 1 );
   468         OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP4, "CUsbBatteryChargingPlugin::RequestCurrentL;Setting bMaxPower to %u mA ( = %u x 2mA units)", aMilliAmps, aMilliAmps >> 1 );
   537         TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1;
   469         TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1;
   538         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP5, "CUsbBatteryChargingPlugin::RequestCurrentL;(old value was %u mA)", oldCurrentValue );
   470         OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP5, "CUsbBatteryChargingPlugin::RequestCurrentL;(old value was %u mA)", oldCurrentValue );
   582         }
   514         }
   583 
   515 
   584     CleanupStack::PopAndDestroy(repository);
   516     CleanupStack::PopAndDestroy(repository);
   585     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL_EXIT );
   517     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL_EXIT );
   586     }
   518     }
   587 
       
   588 void CUsbBatteryChargingPlugin::StartCharging(TUint aMilliAmps)
       
   589     {
       
   590     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_ENTRY );
       
   591     
       
   592     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING, "CUsbBatteryChargingPlugin::StartCharging;aMilliAmps=%u", aMilliAmps );
       
   593     
       
   594     // do licensee specific functionality (if any)
       
   595     iLicenseeHooks->StartCharging(aMilliAmps);
       
   596 
       
   597 #ifdef _DEBUG
       
   598     TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   599                 KPropertyUidUsbBatteryChargingChargingCurrent,
       
   600                             aMilliAmps);
       
   601     OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_DUP1, "CUsbBatteryChargingPlugin::StartCharging;Set P&S current = %umA - err = %d", aMilliAmps, err );
       
   602 #else
       
   603     (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   604                 KPropertyUidUsbBatteryChargingChargingCurrent,
       
   605                                 aMilliAmps);
       
   606 #endif
       
   607 
       
   608     SetState(EPluginStateCharging);
       
   609     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_EXIT );
       
   610     }
       
   611 
       
   612 void CUsbBatteryChargingPlugin::StopCharging()
       
   613     {
       
   614     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING_ENTRY );
       
   615     
       
   616     // do licensee specific functionality (if any)
       
   617     iLicenseeHooks->StopCharging();
       
   618 
       
   619 #ifdef _DEBUG
       
   620     TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   621                                     KPropertyUidUsbBatteryChargingChargingCurrent,
       
   622                                     0);
       
   623     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING, "CUsbBatteryChargingPlugin::StopCharging;Set P&S current = 0mA - err = %d", err );
       
   624 #else
       
   625     (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   626                                     KPropertyUidUsbBatteryChargingChargingCurrent,
       
   627                                     0);
       
   628 #endif
       
   629     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING_EXIT );
       
   630     }
       
   631 
       
   632 void CUsbBatteryChargingPlugin::SetNegotiatedCurrent(TUint aMilliAmps)
       
   633     {
       
   634     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_ENTRY );
       
   635     
       
   636     OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT, "CUsbBatteryChargingPlugin::SetNegotiatedCurrent;aMilliAmps=%u", aMilliAmps );
       
   637 
       
   638     // Ignore errors - not much we can do if it fails
       
   639 #ifdef _DEBUG
       
   640     TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   641                                     KPropertyUidUsbBatteryChargingAvailableCurrent,
       
   642                                     aMilliAmps);
       
   643     OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_DUP1, "CUsbBatteryChargingPlugin::SetNegotiatedCurrent;Set P&S current = %umA - err = %d", aMilliAmps, err );
       
   644 #else
       
   645     (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   646                                     KPropertyUidUsbBatteryChargingAvailableCurrent,
       
   647                                     aMilliAmps);
       
   648 #endif
       
   649     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_EXIT );
       
   650     }
       
   651 
       
   652 
   519 
   653 #ifndef _DEBUG
   520 #ifndef _DEBUG
   654 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState /*aState*/)
   521 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState /*aState*/)
   655     {
   522     {
   656     }
   523     }
   690 #endif
   557 #endif
   691 
   558 
   692 void CUsbBatteryChargingPlugin::MpsoVBusStateChanged(TInt aNewState)
   559 void CUsbBatteryChargingPlugin::MpsoVBusStateChanged(TInt aNewState)
   693     {
   560     {
   694     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_ENTRY );
   561     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_ENTRY );
   695     
   562     if (iChargingInfo().iChargingPortType == EUsbChargingPortTypeStandardDownstreamPort)
   696     iCurrentState->MpsoVBusStateChanged(aNewState);
   563     	{
       
   564     	iCurrentState->MpsoVBusStateChanged(aNewState);
       
   565     	}
       
   566 	iVBusState = aNewState;
       
   567 	UpdateChargingInfo();
   697     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_EXIT );
   568     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_EXIT );
   698     }
   569     }
   699 
   570 
   700 
   571 
   701 // For host OTG enabled charging plug-in
   572 // For host OTG enabled charging plug-in
   703 void CUsbBatteryChargingPlugin::MpsoIdPinStateChanged(TInt aValue)
   574 void CUsbBatteryChargingPlugin::MpsoIdPinStateChanged(TInt aValue)
   704     {
   575     {
   705     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_ENTRY );
   576     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_ENTRY );
   706     
   577     
   707     iCurrentState->MpsoIdPinStateChanged(aValue);
   578     iCurrentState->MpsoIdPinStateChanged(aValue);
       
   579 	UpdateChargingInfo();
   708     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_EXIT );
   580     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_EXIT );
   709     }
   581     }
   710 
   582 
   711 void CUsbBatteryChargingPlugin::MpsoOtgStateChangedL(TUsbOtgState aNewState)
   583 void CUsbBatteryChargingPlugin::MpsoOtgStateChangedL(TUsbOtgState aNewState)
   712     {
   584     {
   713     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_ENTRY );
   585     OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_ENTRY );
   714 
   586 
   715     iCurrentState->MpsoOtgStateChangedL(aNewState);
   587     iCurrentState->MpsoOtgStateChangedL(aNewState);
   716     OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_EXIT );
   588 	UpdateChargingInfo();
   717     }
   589 	OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_EXIT );
   718 #endif
   590     }
       
   591 #endif
       
   592 
       
   593 
       
   594 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1
       
   595 void CUsbBatteryChargingPlugin::UsbChargingPortType(TUint aChargingPortType)
       
   596 	{
       
   597 	OstTraceExt1( TRACE_NORMAL, CUSBBATTERYCHARGINGPLUGIN_USBCHARGINGPORTTYPE, "CUsbBatteryChargingPlugin::UsbChargingPortType;ChargingTypeToString(aChargingPortType)=%s", *ChargingTypeToString(aChargingPortType) );
       
   598 	ChargingTypeToString(aChargingPortType);
       
   599 	switch (aChargingPortType)
       
   600 		{
       
   601 		case KUsbChargingPortTypeNone:
       
   602 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeNone;
       
   603 			break;
       
   604 		case KUsbChargingPortTypeUnsupported:
       
   605 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeUnsupported;
       
   606 			break;
       
   607 		case KUsbChargingPortTypeDedicatedChargingPort:
       
   608 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeDedicatedChargingPort;
       
   609 			break;				
       
   610 		case KUsbChargingPortTypeChargingDownstreamPort:
       
   611 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeChargingDownstreamPort;
       
   612 			break;
       
   613 		case KUsbChargingPortTypeStandardDownstreamPort:
       
   614 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeStandardDownstreamPort;
       
   615 			break;
       
   616 		case KUsbChargingPortTypeAcaRidA:
       
   617 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeAcaRidA;
       
   618 			break;
       
   619 		case KUsbChargingPortTypeAcaRidB:
       
   620 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeAcaRidB;
       
   621 			break;
       
   622 		case KUsbChargingPortTypeAcaRidC:
       
   623 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeAcaRidC;
       
   624 			break;
       
   625 		case KUsbChargingPortTypeChargingPort:	
       
   626 			iChargingInfo().iChargingPortType = EUsbChargingPortTypeChargingPort;
       
   627 			break;
       
   628 		default:
       
   629 			break;
       
   630 		}
       
   631 	iLdd.ChargerDetectorCaps(iChargerDetectotCaps);
       
   632 	iCurrentState->UsbChargingPortType(aChargingPortType);
       
   633 	UpdateChargingInfo();
       
   634 	}
       
   635 #endif
       
   636 
       
   637 _LIT8(KPortTypeNone, "PortTypeNone");
       
   638 _LIT8(KPortTypeUnsupported, "PortTypeUnsupported");
       
   639 _LIT8(KPortTypeDedicatedChargingPort, "PortTypeDedicatedChargingPort");
       
   640 _LIT8(KPortTypeStandardDownstreamPort, "PortTypeStandardDownstreamPort");
       
   641 _LIT8(KPortTypeChargingDownstreamPort, "PortTypeChargingDownstreamPort");
       
   642 _LIT8(KPortTypeAcaRidA, "PortTypeAcaRidA");
       
   643 _LIT8(KPortTypeAcaRidB, "PortTypeAcaRidB");
       
   644 _LIT8(KPortTypeAcaRidC, "PortTypeAcaRidC");
       
   645 _LIT8(KPortTypeChargingPort, "PortTypeChargingPort");
       
   646 
       
   647 
       
   648 const TDesC8* CUsbBatteryChargingPlugin::ChargingTypeToString(TUint aChargingType)
       
   649 	{
       
   650 	const TDesC8* str = NULL;
       
   651 	switch (aChargingType)
       
   652    		{
       
   653 		case EUsbChargingPortTypeNone:
       
   654 			str = &KPortTypeNone;
       
   655 			break;
       
   656 		case EUsbChargingPortTypeUnsupported:
       
   657 			str = &KPortTypeUnsupported;
       
   658 			break;
       
   659 		case EUsbChargingPortTypeDedicatedChargingPort:
       
   660 			str = &KPortTypeDedicatedChargingPort;
       
   661 			break;				
       
   662 		case EUsbChargingPortTypeChargingDownstreamPort:
       
   663 			str = &KPortTypeChargingDownstreamPort;
       
   664 			break;
       
   665 		case EUsbChargingPortTypeStandardDownstreamPort:
       
   666 			str = &KPortTypeStandardDownstreamPort;
       
   667 			break;
       
   668 		case EUsbChargingPortTypeAcaRidA:
       
   669 			str = &KPortTypeAcaRidA;
       
   670 			break;
       
   671 		case EUsbChargingPortTypeAcaRidB:
       
   672 			str = &KPortTypeAcaRidB;
       
   673 			break;
       
   674 		case EUsbChargingPortTypeAcaRidC:
       
   675 			str = &KPortTypeAcaRidC;
       
   676 			break;
       
   677 		case EUsbChargingPortTypeChargingPort:	
       
   678 			str = &KPortTypeChargingPort;
       
   679 			break;
       
   680 		default:
       
   681 			break;
       
   682 		}
       
   683 	return str;
       
   684 	}
       
   685 
       
   686 void CUsbBatteryChargingPlugin::QueryCurrentSpeed()
       
   687     {
       
   688 	if (iChargingInfo().iChargingPortType == EUsbChargingPortTypeChargingDownstreamPort)
       
   689 		{
       
   690 		if (iLdd.CurrentlyUsingHighSpeed())
       
   691 			{
       
   692 		    OstTrace0( TRACE_NORMAL, CUSBBATTERYCHARGINGPLUGIN_QUERYCURRENTSPEED, "CUsbBatteryChargingPlugin::QueryCurrentSpeed is high speed" );
       
   693 			iUsbSpeedType = EUsbHighSpeed;
       
   694 			}
       
   695 		else
       
   696 			{
       
   697 			OstTrace0( TRACE_NORMAL, DUP1_CUSBBATTERYCHARGINGPLUGIN_QUERYCURRENTSPEED, "CUsbBatteryChargingPlugin::QueryCurrentSpeed is full speed" );
       
   698 			iUsbSpeedType = EUsbFullSpeed;
       
   699 			}
       
   700 		}
       
   701     }
       
   702 
       
   703 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1	
       
   704 void CUsbBatteryChargingPlugin::UpdateChargingInfo()
       
   705 	{
       
   706 	OstTraceFunctionEntry0( CUSBBATTERYCHARGINGPLUGIN_UPDATECHARGINGINFO_ENTRY );
       
   707 	const TUint16 KIDev_Dchg = 1800;
       
   708 	const TUint16 KIDev_Chg = 1500;	
       
   709 	const TUint16 KIDev_Hchg_Lfs = 1500;
       
   710 	const TUint16 KIDev_Hchg_Hs = 900;
       
   711 	const TUint16 KIDev_Hchg_Hs_Chirp = 560;
       
   712 	const TUint16 KIDev_Avaiable = 500;
       
   713 	const TUint16 KIDev_Suspend = 2;
       
   714 	const TUint16 KVBus_Chg = 4500;
       
   715 	const TUint16 KVBus_Dchg = 2000;
       
   716 
       
   717 		
       
   718     QueryCurrentSpeed();
       
   719 //set iUsbConnStatus field 	
       
   720 	iChargingInfo().iUsbConnStatus = EUsbConnectionStatusNone;
       
   721 	if (EUsbChargingPortTypeStandardDownstreamPort == iChargingInfo().iChargingPortType 
       
   722 		&& IsUsbChargingPossible())
       
   723 		{
       
   724 		switch (iDeviceState)
       
   725 			{
       
   726 			case EUsbDeviceStateSuspended:
       
   727 				iChargingInfo().iUsbConnStatus = EUsbConnectionStatusSuspend;
       
   728 				break;
       
   729 			case EUsbDeviceStateConfigured:
       
   730 				iChargingInfo().iUsbConnStatus = EUsbConnectionStatusConfigured;
       
   731 				break;
       
   732 			default:
       
   733 				break;
       
   734 			}		
       
   735 		}
       
   736 //set current and voltage field	
       
   737 	switch (iChargingInfo().iChargingPortType)
       
   738 		{
       
   739 		case EUsbChargingPortTypeDedicatedChargingPort:
       
   740 			iChargingInfo().iMinAvailableVbusCurrent = KIDev_Avaiable;
       
   741 			iChargingInfo().iMaxVbusCurrent = KIDev_Dchg;
       
   742 			iChargingInfo().iMinVbusVoltage = KVBus_Dchg;						
       
   743 			break;
       
   744 		case EUsbChargingPortTypeChargingPort:
       
   745 		case EUsbChargingPortTypeChargingDownstreamPort:	
       
   746 			iChargingInfo().iMinAvailableVbusCurrent = KIDev_Avaiable;
       
   747 			iChargingInfo().iMinVbusVoltage = KVBus_Dchg;		
       
   748 			if (iChargerDetectotCaps.iCapabilities & KChargerDetectorCapChirpCurrentLimiting)
       
   749 				{			
       
   750 				if (iUsbSpeedType == EUsbFullSpeed)
       
   751 					{
       
   752 					iChargingInfo().iMaxVbusCurrent = KIDev_Hchg_Lfs;
       
   753 					}
       
   754 				else
       
   755 					{
       
   756 					iChargingInfo().iMaxVbusCurrent = KIDev_Hchg_Hs;					
       
   757 					}
       
   758 				}
       
   759 			else
       
   760 				{
       
   761 				if (iDeviceState == EUsbDeviceStateConfigured && iUsbSpeedType == EUsbFullSpeed)
       
   762 					{
       
   763 					iChargingInfo().iMaxVbusCurrent = KIDev_Hchg_Lfs;
       
   764 					}
       
   765 				else
       
   766 					{
       
   767 					iChargingInfo().iMaxVbusCurrent = KIDev_Hchg_Hs_Chirp;					
       
   768 					}
       
   769 				}
       
   770 			break;
       
   771 		case EUsbChargingPortTypeNone:
       
   772 		case EUsbChargingPortTypeUnsupported:	
       
   773 			iChargingInfo().iMinAvailableVbusCurrent = 0;
       
   774 			iChargingInfo().iMaxVbusCurrent = 0;
       
   775 			iChargingInfo().iMinVbusVoltage = 0; 					
       
   776 			break;
       
   777 		case EUsbChargingPortTypeStandardDownstreamPort:
       
   778 			if (IsUsbChargingPossible())
       
   779 				{
       
   780 				switch (iDeviceState)
       
   781 					{
       
   782 					case EUsbDeviceStateConfigured:
       
   783 						iChargingInfo().iMinAvailableVbusCurrent = iAvailableMilliAmps;
       
   784 						iChargingInfo().iMaxVbusCurrent = iAvailableMilliAmps;
       
   785 						iChargingInfo().iMinVbusVoltage = KVBus_Chg; 								
       
   786 						break;
       
   787 					case EUsbDeviceStateSuspended:
       
   788 						iChargingInfo().iMinAvailableVbusCurrent = KIDev_Suspend;
       
   789 						iChargingInfo().iMaxVbusCurrent = KIDev_Suspend;
       
   790 						iChargingInfo().iMinVbusVoltage = KVBus_Chg; 						
       
   791 						break;
       
   792 					default:
       
   793 						iChargingInfo().iMinAvailableVbusCurrent = 0;
       
   794 						iChargingInfo().iMaxVbusCurrent = 0;
       
   795 						iChargingInfo().iMinVbusVoltage = 0; 						
       
   796 						break;
       
   797 					}
       
   798 				}
       
   799 			else
       
   800 				{
       
   801 				iChargingInfo().iMinAvailableVbusCurrent = 0;
       
   802 				iChargingInfo().iMaxVbusCurrent = 0;
       
   803 				iChargingInfo().iMinVbusVoltage = 0;						
       
   804 				}
       
   805 			break;
       
   806 		case EUsbChargingPortTypeAcaRidA:
       
   807 			iChargingInfo().iMinAvailableVbusCurrent = KIDev_Avaiable - iBDevMaxPower;
       
   808 			iChargingInfo().iMaxVbusCurrent = KIDev_Chg;
       
   809 			iChargingInfo().iMinVbusVoltage = KVBus_Dchg; 					
       
   810 			break;
       
   811 		case EUsbChargingPortTypeAcaRidB:
       
   812 			iChargingInfo().iMinAvailableVbusCurrent = KIDev_Avaiable;
       
   813 			iChargingInfo().iMaxVbusCurrent = KIDev_Chg;
       
   814 			iChargingInfo().iMinVbusVoltage = KVBus_Dchg; 					
       
   815 			break;
       
   816 		case EUsbChargingPortTypeAcaRidC:
       
   817 			iChargingInfo().iMinAvailableVbusCurrent = KIDev_Avaiable;
       
   818 			iChargingInfo().iMaxVbusCurrent = KIDev_Chg;
       
   819 			iChargingInfo().iMinVbusVoltage = KVBus_Dchg; 					
       
   820 			break;
       
   821 		default:
       
   822 			break;
       
   823 		}
       
   824 	PublishChargingInfo();
       
   825 	OstTraceFunctionExit0( CUSBBATTERYCHARGINGPLUGIN_UPDATECHARGINGINFO_EXIT );
       
   826 	}
       
   827 
       
   828 #else
       
   829 void CUsbBatteryChargingPlugin::UpdateChargingInfo()
       
   830 	{
       
   831 	OstTraceFunctionEntry0( CUSBBATTERYCHARGINGPLUGIN_UPDATECHARGINGINF1_ENTRY );
       
   832 	const TUint16 KIDev_Suspend = 2;
       
   833 	const TUint16 KVBus_Chg = 4500;
       
   834 
       
   835 		
       
   836     QueryCurrentSpeed();
       
   837 //set iUsbConnStatus field 	
       
   838 	iChargingInfo().iUsbConnStatus = EUsbConnectionStatusNone;
       
   839 	if (EUsbChargingPortTypeStandardDownstreamPort == iChargingInfo().iChargingPortType 
       
   840 		&& IsUsbChargingPossible())
       
   841 		{
       
   842 		switch (iDeviceState)
       
   843 			{
       
   844 			case EUsbDeviceStateSuspended:
       
   845 				iChargingInfo().iUsbConnStatus = EUsbConnectionStatusSuspend;
       
   846 				break;
       
   847 			case EUsbDeviceStateConfigured:
       
   848 				iChargingInfo().iUsbConnStatus = EUsbConnectionStatusConfigured;
       
   849 				break;
       
   850 			default:
       
   851 				break;
       
   852 			}		
       
   853 		}
       
   854 //set current and voltage field	
       
   855 	switch (iChargingInfo().iChargingPortType)
       
   856 		{
       
   857 		case EUsbChargingPortTypeStandardDownstreamPort:
       
   858 			if (IsUsbChargingPossible())
       
   859 				{
       
   860 				switch (iDeviceState)
       
   861 					{
       
   862 					case EUsbDeviceStateConfigured:
       
   863 						iChargingInfo().iMinAvailableVbusCurrent = iAvailableMilliAmps;
       
   864 						iChargingInfo().iMaxVbusCurrent = iAvailableMilliAmps;
       
   865 						iChargingInfo().iMinVbusVoltage = KVBus_Chg; 								
       
   866 						break;
       
   867 					case EUsbDeviceStateSuspended:
       
   868 						iChargingInfo().iMinAvailableVbusCurrent = KIDev_Suspend;
       
   869 						iChargingInfo().iMaxVbusCurrent = KIDev_Suspend;
       
   870 						iChargingInfo().iMinVbusVoltage = KVBus_Chg; 						
       
   871 						break;
       
   872 					default:
       
   873 						iChargingInfo().iMinAvailableVbusCurrent = 0;
       
   874 						iChargingInfo().iMaxVbusCurrent = 0;
       
   875 						iChargingInfo().iMinVbusVoltage = 0; 						
       
   876 						break;
       
   877 					}
       
   878 				}
       
   879 			else
       
   880 				{
       
   881 				iChargingInfo().iMinAvailableVbusCurrent = 0;
       
   882 				iChargingInfo().iMaxVbusCurrent = 0;
       
   883 				iChargingInfo().iMinVbusVoltage = 0;						
       
   884 				}
       
   885 			break;
       
   886 		default:
       
   887 			break;
       
   888 		}
       
   889 	PublishChargingInfo();
       
   890 	OstTraceFunctionExit0( CUSBBATTERYCHARGINGPLUGIN_UPDATECHARGINGINF1_EXIT );
       
   891 	}
       
   892 
       
   893 #endif
       
   894 
       
   895 
       
   896 void CUsbBatteryChargingPlugin::PublishChargingInfo()
       
   897 	{
       
   898 	OstTraceFunctionEntry0( CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_ENTRY );
       
   899 	OstTraceExt1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_DUP1, "charging type: %s", 
       
   900 		*ChargingTypeToString(iChargingInfo().iChargingPortType) );
       
   901 	OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_DUP2, "iUsbConnStatus %d", 
       
   902 		iChargingInfo().iUsbConnStatus );
       
   903 	OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_DUP3, "iMinAvailableVbusCurrent %d", 
       
   904 		iChargingInfo().iMinAvailableVbusCurrent );
       
   905 	OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_DUP4, "iMaxVbusCurrent %d", 
       
   906 		iChargingInfo().iMaxVbusCurrent );
       
   907 	OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_DUP5, "iMinVbusVoltage %d", 
       
   908 		iChargingInfo().iMinVbusVoltage );
       
   909 	
       
   910 	if (iLastPublishedInfo.iChargingPortType != iChargingInfo().iChargingPortType
       
   911 		|| iLastPublishedInfo.iUsbConnStatus != iChargingInfo().iUsbConnStatus
       
   912 		|| iLastPublishedInfo.iMinAvailableVbusCurrent != iChargingInfo().iMinAvailableVbusCurrent
       
   913 		|| iLastPublishedInfo.iMaxVbusCurrent != iChargingInfo().iMaxVbusCurrent
       
   914 		|| iLastPublishedInfo.iMinVbusVoltage != iChargingInfo().iMinVbusVoltage)
       
   915 		{
       
   916 		OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_DUP6, "info changed, publish it");
       
   917 		RProperty::Set(KPropertyUidUsbBatteryChargingCategory,
       
   918                       KPropertyUidUsbBatteryChargingInfo,
       
   919                       iChargingInfo);
       
   920 		}
       
   921 	iLastPublishedInfo = iChargingInfo();
       
   922 	OstTraceFunctionExit0( CUSBBATTERYCHARGINGPLUGIN_PUBLISHCHARGINGINFO_EXIT );
       
   923 	}
       
   924 
       
   925 #ifdef SYMBIAN_USB_BATTERYCHARGING_V1_1	
       
   926 
       
   927 void CUsbBatteryChargingPlugin::PeerDeviceMaxPower(TUint aCurrent)
       
   928 	{
       
   929 	OstTraceFunctionEntry0( CUSBBATTERYCHARGINGPLUGIN_PEERDEVICEMAXPOWER_ENTRY );
       
   930 	const TUint16 KIBDev_Drawn = 500;
       
   931 	iBDevMaxPower = (aCurrent < KIBDev_Drawn)?aCurrent:KIBDev_Drawn;	
       
   932 	UpdateChargingInfo();
       
   933 	OstTraceFunctionExit0( CUSBBATTERYCHARGINGPLUGIN_PEERDEVICEMAXPOWER_EXIT );
       
   934 	}
       
   935 #endif
       
   936