16 */ |
16 */ |
17 |
17 |
18 /** @file |
18 /** @file |
19 @internalComponent |
19 @internalComponent |
20 */ |
20 */ |
21 |
|
22 #include "CUsbBatteryChargingPlugin.h" |
21 #include "CUsbBatteryChargingPlugin.h" |
23 #include "chargingstates.h" |
22 #include <e32debug.h> |
24 #include <musbmanextensionpluginobserver.h> |
23 #include <e32def.h> |
25 #include "cusbbatterycharginglicenseehooks.h" |
|
26 #include "reenumerator.h" |
|
27 #include <usb/usblogger.h> |
24 #include <usb/usblogger.h> |
28 #include <e32property.h> |
25 #include <e32property.h> |
29 #include <centralrepository.h> |
26 #include <centralrepository.h> |
30 #include <usbotgdefs.h> |
27 #include <usbotgdefs.h> |
|
28 #include <musbmanextensionpluginobserver.h> |
|
29 |
|
30 |
|
31 #include "chargingstates.h" |
|
32 #include "cusbbatterycharginglicenseehooks.h" |
|
33 #include "reenumerator.h" |
31 |
34 |
32 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV // For host OTG enabled charging plug-in |
35 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV // For host OTG enabled charging plug-in |
33 #include "idpinwatcher.h" |
36 #include "idpinwatcher.h" |
34 #include "otgstatewatcher.h" |
37 #include "otgstatewatcher.h" |
35 #endif |
38 #endif |
36 |
39 |
37 #include "vbuswatcher.h" |
40 #include "vbuswatcher.h" |
38 #include <e32debug.h> |
41 #include "OstTraceDefinitions.h" |
39 #include <e32def.h> |
42 #ifdef OST_TRACE_COMPILER_IN_USE |
|
43 #include "CUsbBatteryChargingPluginTraces.h" |
|
44 #endif |
|
45 |
40 |
46 |
41 static const TInt KUsbBatteryChargingConfigurationDescriptorCurrentOffset = 8; // see bMaxPower in section 9.6.3 of USB Spec 2.0 |
47 static const TInt KUsbBatteryChargingConfigurationDescriptorCurrentOffset = 8; // see bMaxPower in section 9.6.3 of USB Spec 2.0 |
42 static const TInt KUsbBatteryChargingCurrentRequestTimeout = 3000000; // 3 seconds |
48 static const TInt KUsbBatteryChargingCurrentRequestTimeout = 3000000; // 3 seconds |
43 |
49 |
44 #ifdef __FLOG_ACTIVE |
|
45 _LIT8(KLogComponent, "USBCHARGE"); |
|
46 #endif |
|
47 |
50 |
48 /** |
51 /** |
49 Factory function. |
52 Factory function. |
50 @return Ownership of a new CUsbBatteryChargingPlugin. |
53 @return Ownership of a new CUsbBatteryChargingPlugin. |
51 */ |
54 */ |
245 /** |
250 /** |
246 Set first power to request |
251 Set first power to request |
247 */ |
252 */ |
248 void CUsbBatteryChargingPlugin::SetInitialConfigurationL() |
253 void CUsbBatteryChargingPlugin::SetInitialConfigurationL() |
249 { |
254 { |
250 LOGTEXT(_L8("Setting Initial Configuration")); |
255 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Setting Initial Configuration" ); |
251 if (iCurrentValues.Count() > 0) |
256 if (iCurrentValues.Count() > 0) |
252 { |
257 { |
|
258 TInt err; |
253 TInt configDescriptorSize = 0; |
259 TInt configDescriptorSize = 0; |
254 LEAVEIFERRORL(iLdd.GetConfigurationDescriptorSize(configDescriptorSize)); |
260 err = iLdd.GetConfigurationDescriptorSize(configDescriptorSize); |
|
261 if(err < 0) |
|
262 { |
|
263 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP1, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;iLdd.GetConfigurationDescriptorSize(configDescriptorSize) with error=%d", err ); |
|
264 User::Leave(err); |
|
265 } |
255 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
266 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
256 TPtr8 ptr(configDescriptor->Des()); |
267 TPtr8 ptr(configDescriptor->Des()); |
257 |
268 |
258 LOGTEXT2(_L8("Getting Configuration Descriptor (size = %d)"),configDescriptorSize); |
269 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP2, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Getting Configuration Descriptor (size = %d)", configDescriptorSize ); |
259 LEAVEIFERRORL(iLdd.GetConfigurationDescriptor(ptr)); |
270 err = iLdd.GetConfigurationDescriptor(ptr); |
|
271 if(err < 0) |
|
272 { |
|
273 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP3, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;iLdd.GetConfigurationDescriptor(ptr) with error=%d", err ); |
|
274 User::Leave(err); |
|
275 } |
260 |
276 |
261 // For host OTG enabled charging plug-in |
277 // For host OTG enabled charging plug-in |
262 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
278 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
263 // Get first power to put in configurator |
279 // Get first power to put in configurator |
264 LOGTEXT(_L8("Checking IdPin state:")); |
280 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP4, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Checking IdPin state:" ); |
265 if(iIdPinState == EUsbBatteryChargingIdPinBRole) |
281 if(iIdPinState == EUsbBatteryChargingIdPinBRole) |
266 #else |
282 #else |
267 if (ETrue) |
283 if (ETrue) |
268 #endif |
284 #endif |
269 { |
285 { |
270 if (iCurrentValues.Count() > 0) |
286 if (iCurrentValues.Count() > 0) |
271 { |
287 { |
272 iCurrentIndexRequested = 0; |
288 iCurrentIndexRequested = 0; |
273 iRequestedCurrentValue = iCurrentValues[iCurrentIndexRequested]; |
289 iRequestedCurrentValue = iCurrentValues[iCurrentIndexRequested]; |
274 LOGTEXT2(_L8("IdPin state is 0, current set to: %d"), iRequestedCurrentValue); |
290 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP5, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;IdPin state is 0, current set to: %d", iRequestedCurrentValue ); |
275 } |
291 } |
276 else |
292 else |
277 { |
293 { |
278 LOGTEXT(_L8("No vailable current found !")); |
294 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP6, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;No vailable current found !" ); |
279 } |
295 } |
280 } |
296 } |
281 else |
297 else |
282 { |
298 { |
283 iRequestedCurrentValue = 0; |
299 iRequestedCurrentValue = 0; |
284 LOGTEXT(_L8("IdPin state is 1, current set to 0")); |
300 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP7, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;IdPin state is 1, current set to 0" ); |
285 } |
301 } |
286 |
302 |
287 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
303 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
288 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (iRequestedCurrentValue >> 1); |
304 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (iRequestedCurrentValue >> 1); |
289 |
305 |
290 LOGTEXT(_L8("Setting Updated Configuration Descriptor")); |
306 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP8, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;Setting Updated Configuration Descriptor" ); |
291 LEAVEIFERRORL(iLdd.SetConfigurationDescriptor(ptr)); |
307 err = iLdd.SetConfigurationDescriptor(ptr); |
|
308 if(err < 0) |
|
309 { |
|
310 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETINITIALCONFIGURATIONL_DUP9, "CUsbBatteryChargingPlugin::SetInitialConfigurationL;iLdd.SetConfigurationDescriptor(ptr) with error=%d", err ); |
|
311 User::Leave(err); |
|
312 } |
292 |
313 |
293 CleanupStack::PopAndDestroy(configDescriptor); |
314 CleanupStack::PopAndDestroy(configDescriptor); |
294 } |
315 } |
295 } |
316 } |
296 |
317 |
297 |
318 |
298 TAny* CUsbBatteryChargingPlugin::GetInterface(TUid aUid) |
319 TAny* CUsbBatteryChargingPlugin::GetInterface(TUid aUid) |
299 { |
320 { |
300 LOGTEXT(KNullDesC8); |
321 OstTrace1( TRACE_FLOW, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE, "CUsbBatteryChargingPlugin::GetInterface;this = [0x%08x]", this ); |
301 LOGTEXT3(_L8(">>CUsbBatteryChargingPlugin::GetInterface this = [0x%08x], aUid = 0x%08x"), this, aUid); |
322 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP1, "CUsbBatteryChargingPlugin::GetInterface;aUid = 0x%08x", aUid.iUid ); |
302 (void)aUid; |
323 (void)aUid; |
303 |
324 |
304 TAny* ret = NULL; |
325 TAny* ret = NULL; |
305 |
326 |
306 LOGTEXT2(_L8("<<CUsbBatteryChargingPlugin::GetInterface ret = [0x%08x]"), ret); |
327 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_GETINTERFACE_DUP2, "CUsbBatteryChargingPlugin::GetInterface;ret = [0x%08x]", ret ); |
307 return ret; |
328 return ret; |
308 } |
329 } |
309 |
330 |
310 void CUsbBatteryChargingPlugin::Panic(TUsbBatteryChargingPanic aPanic) |
331 void CUsbBatteryChargingPlugin::Panic(TUsbBatteryChargingPanic aPanic) |
311 { |
332 { |
312 LOGTEXT2(_L8("*** CUsbBatteryChargingPlugin::Panic(%d) ***"),aPanic); |
333 OstTrace1( TRACE_FATAL, REF_CUSBBATTERYCHARGINGPLUGIN_PANIC, "CUsbBatteryChargingPlugin::Panic;*** CUsbBatteryChargingPlugin::Panic(%d) ***", aPanic ); |
313 _LIT(KUsbChargingPanic,"USB Charging"); |
334 _LIT(KUsbChargingPanic,"USB Charging"); |
314 User::Panic(KUsbChargingPanic, aPanic); |
335 User::Panic(KUsbChargingPanic, aPanic); |
315 } |
336 } |
316 |
337 |
317 void CUsbBatteryChargingPlugin::UsbServiceStateChange(TInt /*aLastError*/, TUsbServiceState /*aOldState*/, TUsbServiceState /*aNewState*/) |
338 void CUsbBatteryChargingPlugin::UsbServiceStateChange(TInt /*aLastError*/, TUsbServiceState /*aOldState*/, TUsbServiceState /*aNewState*/) |
369 default: |
392 default: |
370 // Should never happen ... |
393 // Should never happen ... |
371 iPluginState = EPluginStateIdle; |
394 iPluginState = EPluginStateIdle; |
372 iCurrentState = iPluginStates[EPluginStateIdle]; |
395 iCurrentState = iPluginStates[EPluginStateIdle]; |
373 |
396 |
374 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::SetState: Invalid new state: aState = %d"), aState); |
397 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE, "CUsbBatteryChargingPlugin::SetState;Invalid new state: aState = %d", aState ); |
375 |
398 |
376 Panic(EUsbBatteryChargingPanicUnexpectedPluginState); |
399 Panic(EUsbBatteryChargingPanicUnexpectedPluginState); |
377 } |
400 } |
378 iPluginState = aState; |
401 iPluginState = aState; |
379 |
402 |
380 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::SetState, New state: aState = %d"), aState); |
403 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE_DUP1, "CUsbBatteryChargingPlugin::SetState;New state: aState=%d", aState ); |
381 |
404 |
|
405 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_SETSTATE_EXIT ); |
382 return iPluginState; |
406 return iPluginState; |
383 } |
407 } |
384 |
408 |
385 void CUsbBatteryChargingPlugin::NegotiateChargingCurrent() |
409 void CUsbBatteryChargingPlugin::NegotiateChargingCurrent() |
386 { |
410 { |
387 LOG_FUNC |
411 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT_ENTRY ); |
388 |
412 |
389 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::StartNegotiation, iDeviceState = %d"), iDeviceState); |
413 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT, "CUsbBatteryChargingPlugin::NegotiateChargingCurrent;iDeviceState=%d", iDeviceState ); |
390 TRAPD(result, NegotiateNextCurrentValueL()); |
414 TRAPD(result, NegotiateNextCurrentValueL()); |
391 if(result == KErrNone) |
415 if(result == KErrNone) |
392 { |
416 { |
393 SetState(EPluginStateCurrentNegotiating); |
417 SetState(EPluginStateCurrentNegotiating); |
394 } |
418 } |
395 else |
419 else |
396 { |
420 { |
397 LOGTEXT2(_L8("Negotiation call failed, iVBusState = 1: result = %d"), result); |
421 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT_DUP1, "CUsbBatteryChargingPlugin::NegotiateChargingCurrent;Negotiation call failed, iVBusState = 1: result = %d", result ); |
398 } |
422 } |
|
423 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATECHARGINGCURRENT_EXIT ); |
399 } |
424 } |
400 |
425 |
401 void CUsbBatteryChargingPlugin::UsbDeviceStateChange(TInt aLastError, |
426 void CUsbBatteryChargingPlugin::UsbDeviceStateChange(TInt aLastError, |
402 TUsbDeviceState aOldState, TUsbDeviceState aNewState) |
427 TUsbDeviceState aOldState, TUsbDeviceState aNewState) |
403 { |
428 { |
404 LOG_FUNC |
429 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_ENTRY ); |
405 |
430 |
406 iCurrentState->UsbDeviceStateChange(aLastError, aOldState, aNewState); |
431 iCurrentState->UsbDeviceStateChange(aLastError, aOldState, aNewState); |
|
432 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_USBDEVICESTATECHANGE_EXIT ); |
407 } |
433 } |
408 |
434 |
409 void CUsbBatteryChargingPlugin::HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal) |
435 void CUsbBatteryChargingPlugin::HandleRepositoryValueChangedL(const TUid& aRepository, TUint aId, TInt aVal) |
410 { |
436 { |
411 LOG_FUNC |
437 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_HANDLEREPOSITORYVALUECHANGEDL_ENTRY ); |
412 |
438 |
413 iCurrentState->HandleRepositoryValueChangedL(aRepository, aId, aVal); |
439 iCurrentState->HandleRepositoryValueChangedL(aRepository, aId, aVal); |
|
440 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_HANDLEREPOSITORYVALUECHANGEDL_EXIT ); |
414 } |
441 } |
415 |
442 |
416 void CUsbBatteryChargingPlugin::DeviceStateTimeout() |
443 void CUsbBatteryChargingPlugin::DeviceStateTimeout() |
417 { |
444 { |
418 LOG_FUNC |
445 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_ENTRY ); |
419 |
446 |
420 iCurrentState->DeviceStateTimeout(); |
447 iCurrentState->DeviceStateTimeout(); |
|
448 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_DEVICESTATETIMEOUT_EXIT ); |
421 } |
449 } |
422 |
450 |
423 void CUsbBatteryChargingPlugin::NegotiateNextCurrentValueL() |
451 void CUsbBatteryChargingPlugin::NegotiateNextCurrentValueL() |
424 { |
452 { |
425 LOG_FUNC |
453 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATENEXTCURRENTVALUEL_ENTRY ); |
426 |
454 |
427 iDeviceStateTimer->Cancel(); |
455 iDeviceStateTimer->Cancel(); |
428 TUint newCurrent = 0; |
456 TUint newCurrent = 0; |
429 |
457 |
430 if ((iPluginState == EPluginStateIdle) && iCurrentValues.Count() > 0) |
458 if ((iPluginState == EPluginStateIdle) && iCurrentValues.Count() > 0) |
452 } |
480 } |
453 |
481 |
454 RequestCurrentL(newCurrent); |
482 RequestCurrentL(newCurrent); |
455 iRequestedCurrentValue = newCurrent; |
483 iRequestedCurrentValue = newCurrent; |
456 iPluginState = EPluginStateCurrentNegotiating; |
484 iPluginState = EPluginStateCurrentNegotiating; |
|
485 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_NEGOTIATENEXTCURRENTVALUEL_EXIT ); |
457 } |
486 } |
458 |
487 |
459 void CUsbBatteryChargingPlugin::ResetPlugin() |
488 void CUsbBatteryChargingPlugin::ResetPlugin() |
460 { |
489 { |
461 LOG_FUNC |
490 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN_ENTRY ); |
462 |
491 |
463 if((iPluginState != EPluginStateIdle)) |
492 if((iPluginState != EPluginStateIdle)) |
464 { |
493 { |
465 iDeviceStateTimer->Cancel(); // doesn't matter if not running |
494 iDeviceStateTimer->Cancel(); // doesn't matter if not running |
466 iPluginState = EPluginStateIdle; |
495 iPluginState = EPluginStateIdle; |
467 iPluginStateToRecovery = EPluginStateIdle; |
496 iPluginStateToRecovery = EPluginStateIdle; |
468 LOGTEXT2(_L8("PluginState => EPluginStateIdle(%d)"),iPluginState); |
497 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN, "CUsbBatteryChargingPlugin::ResetPlugin;PluginState => EPluginStateIdle(%d)", iPluginState ); |
469 |
498 |
470 iRequestedCurrentValue = 0; |
499 iRequestedCurrentValue = 0; |
471 iCurrentIndexRequested = 0; |
500 iCurrentIndexRequested = 0; |
472 iAvailableMilliAmps = 0; |
501 iAvailableMilliAmps = 0; |
473 SetNegotiatedCurrent(0); |
502 SetNegotiatedCurrent(0); |
474 TRAP_IGNORE(SetInitialConfigurationL()); |
503 TRAP_IGNORE(SetInitialConfigurationL()); |
475 } |
504 } |
|
505 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_RESETPLUGIN_EXIT ); |
476 } |
506 } |
477 |
507 |
478 void CUsbBatteryChargingPlugin::RequestCurrentL(TUint aMilliAmps) |
508 void CUsbBatteryChargingPlugin::RequestCurrentL(TUint aMilliAmps) |
479 { |
509 { |
480 LOG_FUNC |
510 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_ENTRY ); |
481 |
511 |
482 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::RequestCurrent aMilliAmps = %d"), aMilliAmps); |
512 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL, "CUsbBatteryChargingPlugin::RequestCurrentL;aMilliAmps=%u", aMilliAmps ); |
483 |
513 |
484 if((EPluginStateCurrentNegotiating == iPluginState) && (iRequestedCurrentValue != aMilliAmps)) |
514 if((EPluginStateCurrentNegotiating == iPluginState) && (iRequestedCurrentValue != aMilliAmps)) |
485 { |
515 { |
|
516 TInt err; |
486 TInt configDescriptorSize = 0; |
517 TInt configDescriptorSize = 0; |
487 LEAVEIFERRORL(iLdd.GetConfigurationDescriptorSize(configDescriptorSize)); |
518 err = iLdd.GetConfigurationDescriptorSize(configDescriptorSize); |
|
519 if(err < 0) |
|
520 { |
|
521 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP1, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.GetConfigurationDescriptorSize(configDescriptorSize) with error=%d", err ); |
|
522 User::Leave(err); |
|
523 } |
488 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
524 HBufC8* configDescriptor = HBufC8::NewLC(configDescriptorSize); |
489 TPtr8 ptr(configDescriptor->Des()); |
525 TPtr8 ptr(configDescriptor->Des()); |
490 |
526 |
491 LOGTEXT2(_L8("Getting Configuration Descriptor (size = %d)"),configDescriptorSize); |
527 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP2, "CUsbBatteryChargingPlugin::RequestCurrentL;Getting Configuration Descriptor (size = %d)", configDescriptorSize ); |
492 LEAVEIFERRORL(iLdd.GetConfigurationDescriptor(ptr)); |
528 err = iLdd.GetConfigurationDescriptor(ptr); |
|
529 if(err < 0) |
|
530 { |
|
531 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP3, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.GetConfigurationDescriptor(ptr) with error=%d", err ); |
|
532 User::Leave(err); |
|
533 } |
493 |
534 |
494 // set bMaxPower field. One unit = 2mA, so need to halve aMilliAmps. |
535 // set bMaxPower field. One unit = 2mA, so need to halve aMilliAmps. |
495 LOGTEXT3(_L8("Setting bMaxPower to %d mA ( = %d x 2mA units)"),aMilliAmps, (aMilliAmps >> 1)); |
536 OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP4, "CUsbBatteryChargingPlugin::RequestCurrentL;Setting bMaxPower to %u mA ( = %u x 2mA units)", aMilliAmps, aMilliAmps >> 1 ); |
496 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
537 TUint oldCurrentValue = ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] << 1; |
497 LOGTEXT2(_L8("(old value was %d mA)"), oldCurrentValue); |
538 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP5, "CUsbBatteryChargingPlugin::RequestCurrentL;(old value was %u mA)", oldCurrentValue ); |
498 |
539 |
499 //since the device will force reEnumeration if the value is odd |
540 //since the device will force reEnumeration if the value is odd |
500 aMilliAmps = aMilliAmps & 0xFFFE; |
541 aMilliAmps = aMilliAmps & 0xFFFE; |
501 |
542 |
502 // to negotiate a new current value, ReEnumerate is needed |
543 // to negotiate a new current value, ReEnumerate is needed |
503 LOGTEXT(_L8("Forcing ReEnumeration")); |
544 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP6, "CUsbBatteryChargingPlugin::RequestCurrentL;Forcing ReEnumeration" ); |
504 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (aMilliAmps >> 1); |
545 ptr[KUsbBatteryChargingConfigurationDescriptorCurrentOffset] = (aMilliAmps >> 1); |
505 LOGTEXT(_L8("Setting Updated Configuration Descriptor")); |
546 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP7, "CUsbBatteryChargingPlugin::RequestCurrentL;Setting Updated Configuration Descriptor" ); |
506 LEAVEIFERRORL(iLdd.SetConfigurationDescriptor(ptr)); |
547 err = iLdd.SetConfigurationDescriptor(ptr); |
507 LOGTEXT(_L8("Triggering Re-enumeration")); |
548 if(err < 0) |
|
549 { |
|
550 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP8, "CUsbBatteryChargingPlugin::RequestCurrentL;iLdd.SetConfigurationDescriptor(ptr) with err=%d", err ); |
|
551 User::Leave(err); |
|
552 } |
|
553 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP9, "CUsbBatteryChargingPlugin::RequestCurrentL;Triggering Re-enumeration" ); |
508 iDeviceReEnumerator->ReEnumerate(); |
554 iDeviceReEnumerator->ReEnumerate(); |
509 |
555 |
510 CleanupStack::PopAndDestroy(configDescriptor); // configDescriptor |
556 CleanupStack::PopAndDestroy(configDescriptor); // configDescriptor |
511 } |
557 } |
512 |
558 |
513 // Always issue a timer as a watchdog to monitor the request progress |
559 // Always issue a timer as a watchdog to monitor the request progress |
514 LOGTEXT2(_L8("Starting timer: %d"), User::NTickCount()); |
560 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_DUP10, "CUsbBatteryChargingPlugin::RequestCurrentL;Starting timer: %d", User::NTickCount() ); |
515 iDeviceStateTimer->Cancel(); |
561 iDeviceStateTimer->Cancel(); |
516 iDeviceStateTimer->Start(TTimeIntervalMicroSeconds32(KUsbBatteryChargingCurrentRequestTimeout)); |
562 iDeviceStateTimer->Start(TTimeIntervalMicroSeconds32(KUsbBatteryChargingCurrentRequestTimeout)); |
|
563 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_REQUESTCURRENTL_EXIT ); |
517 } |
564 } |
518 |
565 |
519 void CUsbBatteryChargingPlugin::ReadCurrentRequestValuesL() |
566 void CUsbBatteryChargingPlugin::ReadCurrentRequestValuesL() |
520 { |
567 { |
521 LOG_FUNC |
568 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL_ENTRY ); |
522 |
569 |
523 CRepository* repository = CRepository::NewLC(KUsbBatteryChargingCentralRepositoryUid); |
570 CRepository* repository = CRepository::NewLC(KUsbBatteryChargingCentralRepositoryUid); |
524 |
571 |
525 TInt numberOfCurrents = 0; |
572 TInt numberOfCurrents = 0; |
526 repository->Get(KUsbBatteryChargingKeyNumberOfCurrentValues, numberOfCurrents); |
573 repository->Get(KUsbBatteryChargingKeyNumberOfCurrentValues, numberOfCurrents); |
529 for (i=0; i<numberOfCurrents; i++) |
576 for (i=0; i<numberOfCurrents; i++) |
530 { |
577 { |
531 TInt value; |
578 TInt value; |
532 repository->Get(KUsbBatteryChargingCurrentValuesOffset + i, value); |
579 repository->Get(KUsbBatteryChargingCurrentValuesOffset + i, value); |
533 iCurrentValues.Append(static_cast<TUint>(value)); |
580 iCurrentValues.Append(static_cast<TUint>(value)); |
534 LOGTEXT3(_L8("CurrentValue %d = %dmA"),i,value); |
581 OstTraceExt2( TRACE_FLOW, REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL, "CUsbBatteryChargingPlugin::ReadCurrentRequestValuesL;CurrentValue %d = %dmA", i, value ); |
535 } |
582 } |
536 |
583 |
537 CleanupStack::PopAndDestroy(repository); |
584 CleanupStack::PopAndDestroy(repository); |
|
585 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_READCURRENTREQUESTVALUESL_EXIT ); |
538 } |
586 } |
539 |
587 |
540 void CUsbBatteryChargingPlugin::StartCharging(TUint aMilliAmps) |
588 void CUsbBatteryChargingPlugin::StartCharging(TUint aMilliAmps) |
541 { |
589 { |
542 LOG_FUNC |
590 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_ENTRY ); |
543 |
591 |
544 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::StartCharging aMilliAmps = %d"), aMilliAmps); |
592 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING, "CUsbBatteryChargingPlugin::StartCharging;aMilliAmps=%u", aMilliAmps ); |
545 |
593 |
546 // do licensee specific functionality (if any) |
594 // do licensee specific functionality (if any) |
547 iLicenseeHooks->StartCharging(aMilliAmps); |
595 iLicenseeHooks->StartCharging(aMilliAmps); |
548 |
596 |
549 #ifdef __FLOG_ACTIVE |
597 #ifdef _DEBUG |
550 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
598 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
551 KPropertyUidUsbBatteryChargingChargingCurrent, |
599 KPropertyUidUsbBatteryChargingChargingCurrent, |
552 aMilliAmps); |
600 aMilliAmps); |
553 LOGTEXT3(_L8("Set P&S current = %dmA - err = %d"),aMilliAmps,err); |
601 OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_DUP1, "CUsbBatteryChargingPlugin::StartCharging;Set P&S current = %umA - err = %d", aMilliAmps, err ); |
554 #else |
602 #else |
555 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
603 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
556 KPropertyUidUsbBatteryChargingChargingCurrent, |
604 KPropertyUidUsbBatteryChargingChargingCurrent, |
557 aMilliAmps); |
605 aMilliAmps); |
558 #endif |
606 #endif |
559 |
607 |
560 SetState(EPluginStateCharging); |
608 SetState(EPluginStateCharging); |
|
609 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_STARTCHARGING_EXIT ); |
561 } |
610 } |
562 |
611 |
563 void CUsbBatteryChargingPlugin::StopCharging() |
612 void CUsbBatteryChargingPlugin::StopCharging() |
564 { |
613 { |
565 LOG_FUNC |
614 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING_ENTRY ); |
566 |
615 |
567 // do licensee specific functionality (if any) |
616 // do licensee specific functionality (if any) |
568 iLicenseeHooks->StopCharging(); |
617 iLicenseeHooks->StopCharging(); |
569 |
618 |
570 #ifdef __FLOG_ACTIVE |
619 #ifdef _DEBUG |
571 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
620 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
572 KPropertyUidUsbBatteryChargingChargingCurrent, |
621 KPropertyUidUsbBatteryChargingChargingCurrent, |
573 0); |
622 0); |
574 LOGTEXT2(_L8("Set P&S current = 0mA - err = %d"),err); |
623 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING, "CUsbBatteryChargingPlugin::StopCharging;Set P&S current = 0mA - err = %d", err ); |
575 #else |
624 #else |
576 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
625 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
577 KPropertyUidUsbBatteryChargingChargingCurrent, |
626 KPropertyUidUsbBatteryChargingChargingCurrent, |
578 0); |
627 0); |
579 #endif |
628 #endif |
|
629 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_STOPCHARGING_EXIT ); |
580 } |
630 } |
581 |
631 |
582 void CUsbBatteryChargingPlugin::SetNegotiatedCurrent(TUint aMilliAmps) |
632 void CUsbBatteryChargingPlugin::SetNegotiatedCurrent(TUint aMilliAmps) |
583 { |
633 { |
584 LOG_FUNC |
634 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_ENTRY ); |
585 |
635 |
586 LOGTEXT2(_L8(">>CUsbBatteryChargingPlugin::SetNegotiatedCurrent aMilliAmps = %d"), aMilliAmps); |
636 OstTrace1( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT, "CUsbBatteryChargingPlugin::SetNegotiatedCurrent;aMilliAmps=%u", aMilliAmps ); |
587 |
637 |
588 // Ignore errors - not much we can do if it fails |
638 // Ignore errors - not much we can do if it fails |
589 #ifdef __FLOG_ACTIVE |
639 #ifdef _DEBUG |
590 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
640 TInt err = RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
591 KPropertyUidUsbBatteryChargingAvailableCurrent, |
641 KPropertyUidUsbBatteryChargingAvailableCurrent, |
592 aMilliAmps); |
642 aMilliAmps); |
593 LOGTEXT3(_L8("Set P&S current = %dmA - err = %d"),aMilliAmps,err); |
643 OstTraceExt2( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_DUP1, "CUsbBatteryChargingPlugin::SetNegotiatedCurrent;Set P&S current = %umA - err = %d", aMilliAmps, err ); |
594 #else |
644 #else |
595 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
645 (void)RProperty::Set(KPropertyUidUsbBatteryChargingCategory, |
596 KPropertyUidUsbBatteryChargingAvailableCurrent, |
646 KPropertyUidUsbBatteryChargingAvailableCurrent, |
597 aMilliAmps); |
647 aMilliAmps); |
598 #endif |
648 #endif |
599 } |
649 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_SETNEGOTIATEDCURRENT_EXIT ); |
600 |
650 } |
601 |
651 |
602 #ifndef __FLOG_ACTIVE |
652 |
|
653 #ifndef _DEBUG |
603 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState /*aState*/) |
654 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState /*aState*/) |
604 { |
655 { |
605 LOG_FUNC |
|
606 } |
656 } |
607 #else |
657 #else |
608 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState aState) |
658 void CUsbBatteryChargingPlugin::LogStateText(TUsbDeviceState aState) |
609 { |
659 { |
610 LOG_FUNC |
660 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_ENTRY ); |
611 |
661 |
612 switch (aState) |
662 switch (aState) |
613 { |
663 { |
614 case EUsbDeviceStateUndefined: |
664 case EUsbDeviceStateUndefined: |
615 LOGTEXT(_L8(" ***** UNDEFINED *****")); |
665 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT, "CUsbBatteryChargingPlugin::LogStateText; ***** UNDEFINED *****" ); |
616 break; |
666 break; |
617 case EUsbDeviceStateDefault: |
667 case EUsbDeviceStateDefault: |
618 LOGTEXT(_L8(" ***** DEFAULT *****")); |
668 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP1, "CUsbBatteryChargingPlugin::LogStateText; ***** DEFAULT *****" ); |
619 break; |
669 break; |
620 case EUsbDeviceStateAttached: |
670 case EUsbDeviceStateAttached: |
621 LOGTEXT(_L8(" ***** ATTACHED *****")); |
671 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP2, "CUsbBatteryChargingPlugin::LogStateText; ***** ATTACHED *****" ); |
622 break; |
672 break; |
623 case EUsbDeviceStatePowered: |
673 case EUsbDeviceStatePowered: |
624 LOGTEXT(_L8(" ***** POWERED *****")); |
674 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP3, "CUsbBatteryChargingPlugin::LogStateText; ***** POWERED *****" ); |
625 break; |
675 break; |
626 case EUsbDeviceStateConfigured: |
676 case EUsbDeviceStateConfigured: |
627 LOGTEXT(_L8(" ***** CONFIGURED *****")); |
677 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP4, "CUsbBatteryChargingPlugin::LogStateText; ***** CONFIGURED *****" ); |
628 break; |
678 break; |
629 case EUsbDeviceStateAddress: |
679 case EUsbDeviceStateAddress: |
630 LOGTEXT(_L8(" ***** ADDRESS *****")); |
680 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP5, "CUsbBatteryChargingPlugin::LogStateText; ***** ADDRESS *****" ); |
631 break; |
681 break; |
632 case EUsbDeviceStateSuspended: |
682 case EUsbDeviceStateSuspended: |
633 LOGTEXT(_L8(" ***** SUSPENDED *****")); |
683 OstTrace0( TRACE_NORMAL, REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_DUP6, "CUsbBatteryChargingPlugin::LogStateText; ***** SUSPENDED *****" ); |
634 break; |
684 break; |
635 default: |
685 default: |
636 break; |
686 break; |
637 } |
687 } |
|
688 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_LOGSTATETEXT_EXIT ); |
638 } |
689 } |
639 #endif |
690 #endif |
640 |
691 |
641 void CUsbBatteryChargingPlugin::MpsoVBusStateChanged(TInt aNewState) |
692 void CUsbBatteryChargingPlugin::MpsoVBusStateChanged(TInt aNewState) |
642 { |
693 { |
643 LOG_FUNC |
694 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_ENTRY ); |
644 |
695 |
645 iCurrentState->MpsoVBusStateChanged(aNewState); |
696 iCurrentState->MpsoVBusStateChanged(aNewState); |
|
697 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOVBUSSTATECHANGED_EXIT ); |
646 } |
698 } |
647 |
699 |
648 |
700 |
649 // For host OTG enabled charging plug-in |
701 // For host OTG enabled charging plug-in |
650 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
702 #ifdef SYMBIAN_ENABLE_USB_OTG_HOST_PRIV |
651 void CUsbBatteryChargingPlugin::MpsoIdPinStateChanged(TInt aValue) |
703 void CUsbBatteryChargingPlugin::MpsoIdPinStateChanged(TInt aValue) |
652 { |
704 { |
653 LOG_FUNC |
705 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_ENTRY ); |
654 |
706 |
655 iCurrentState->MpsoIdPinStateChanged(aValue); |
707 iCurrentState->MpsoIdPinStateChanged(aValue); |
|
708 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOIDPINSTATECHANGED_EXIT ); |
656 } |
709 } |
657 |
710 |
658 void CUsbBatteryChargingPlugin::MpsoOtgStateChangedL(TUsbOtgState aNewState) |
711 void CUsbBatteryChargingPlugin::MpsoOtgStateChangedL(TUsbOtgState aNewState) |
659 { |
712 { |
660 LOG_FUNC |
713 OstTraceFunctionEntry0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_ENTRY ); |
661 |
714 |
662 iCurrentState->MpsoOtgStateChangedL(aNewState); |
715 iCurrentState->MpsoOtgStateChangedL(aNewState); |
663 } |
716 OstTraceFunctionExit0( REF_CUSBBATTERYCHARGINGPLUGIN_MPSOOTGSTATECHANGEDL_EXIT ); |
664 #endif |
717 } |
|
718 #endif |