os/kernelhwsrv/kernel/eka/drivers/power/binary/bpower.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32\drivers\power\binary\bpower.cpp
    15 // Binary power model
    16 // 
    17 //
    18 
    19 #include <assp.h>
    20 #include <kernel/kern_priv.h>
    21 #include <kernel/kpower.h>
    22 #include "mconf.h"
    23 #include <e32keys.h>
    24 
    25 NONSHARABLE_CLASS(DBinaryBatteryMonitor) : public DBatteryMonitor
    26 	{
    27 public: // from DBatteryMonitor
    28 	void SystemTimeChanged(TInt anOldTime, TInt aNewTime);
    29 	TSupplyStatus MachinePowerStatus();
    30 public:
    31 	DBinaryBatteryMonitor();
    32 	void SupplyInfo(TSupplyInfoV1& si);
    33 	};
    34 DBinaryBatteryMonitor* BinaryBatteryMonitor;
    35 
    36 NONSHARABLE_CLASS(DBinaryPowerHal) : public DPowerHal
    37 	{
    38 public: // from DPowerHal
    39 	TInt PowerHalFunction(TInt aFunction, TAny* a1, TAny* a2);
    40 public:
    41 	DBinaryPowerHal();
    42 private:
    43 	void InitData();
    44 	};
    45 DBinaryPowerHal* BinaryPowerHal;
    46 
    47 DBinaryBatteryMonitor::DBinaryBatteryMonitor()
    48 	{
    49 	Register();
    50 	}
    51 
    52 void DBinaryBatteryMonitor::SystemTimeChanged(TInt /* aOldTime */, TInt /* aNewTime */)
    53 	{
    54 	}
    55 
    56 void DBinaryBatteryMonitor::SupplyInfo(TSupplyInfoV1& si)
    57 	{
    58 	si.iMainBatteryStatus = EZero;
    59 	si.iMainBatteryMilliVolts = 0;
    60 	si.iMainBatteryMaxMilliVolts = 0;
    61 	si.iBackupBatteryStatus = EZero;
    62 	si.iBackupBatteryMilliVolts = 0;
    63 	si.iBackupBatteryMaxMilliVolts = 0;
    64 	si.iMainBatteryInsertionTime = 0;
    65 	si.iMainBatteryInUseMicroSeconds = 0;
    66 	si.iMainBatteryConsumedMilliAmpSeconds = 0;
    67 	si.iExternalPowerPresent = 0;
    68 	si.iExternalPowerInUseMicroSeconds = 0;
    69 	si.iCurrentConsumptionMilliAmps = 0;
    70 	si.iFlags = 0;
    71 	}
    72 
    73 TSupplyStatus DBinaryBatteryMonitor::MachinePowerStatus()
    74 	{
    75 	return EGood;
    76 	}
    77 
    78 
    79 DBinaryPowerHal::DBinaryPowerHal()
    80 	{
    81 	Register();
    82 	// initialise persistent data on cold start
    83 	if (Kern::ColdStart())
    84 		InitData();
    85 	}
    86 
    87 void DBinaryPowerHal::InitData()
    88 	{
    89 	TActualMachineConfig& mc = TheActualMachineConfig();
    90 	TOnOffInfoV1& i = mc.iOnOffInfo;
    91 	i.iPointerSwitchesOn = EFalse;
    92 	i.iCaseOpenSwitchesOn = EFalse;
    93 	i.iCaseCloseSwitchesOff = EFalse;
    94 	}
    95 
    96 TInt DBinaryPowerHal::PowerHalFunction(TInt aFunction, TAny* a1, TAny* /* a2 */)
    97 	{
    98 	__KTRACE_OPT(KPOWER,Kern::Printf("DBinaryPowerHal::PowerHalFunction() func=0x%x, a1=0x%x", aFunction, a1));
    99 	TActualMachineConfig& mc=TheActualMachineConfig();
   100 	TInt r=KErrNone;
   101 	switch(aFunction)
   102 		{
   103 		case EPowerHalSwitchOff:
   104 			if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSwitchOff")))
   105 				return KErrPermissionDenied;
   106 			{
   107 			TRawEvent v;
   108 			v.Set(TRawEvent::ESwitchOff);
   109 			Kern::AddEvent(v);
   110 			}
   111 			break;
   112 		case EPowerHalOnOffInfo:
   113 			Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&mc.iOnOffInfo, sizeof(mc.iOnOffInfo));
   114 			break;
   115 		case EPowerHalSupplyInfo:
   116 			{
   117 			TSupplyInfoV1 si;
   118 			BinaryBatteryMonitor->SupplyInfo(si);
   119 			Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&si, sizeof(si));
   120 			break;
   121 			}
   122 		case EPowerHalSetPointerSwitchesOn:
   123 			if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal Function EPowerHalSetPointerSwitchesOn")))
   124 				return KErrPermissionDenied;
   125 			mc.iOnOffInfo.iPointerSwitchesOn = (TUint8)(TUint)a1;
   126 			break;	
   127 		case EPowerHalPointerSwitchesOn:
   128 			kumemput32(a1, &mc.iOnOffInfo.iPointerSwitchesOn, sizeof(TBool));
   129 			break;
   130 		case EPowerHalSetCaseOpenSwitchesOn:
   131 			if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseOpenSwitchesOn")))
   132 				return KErrPermissionDenied;
   133 			mc.iOnOffInfo.iCaseOpenSwitchesOn = (TUint8)(TUint)a1;
   134 			break;
   135 		case EPowerHalCaseOpenSwitchesOn:
   136 			kumemput32(a1, &mc.iOnOffInfo.iCaseOpenSwitchesOn, sizeof(TBool));
   137 			break;
   138 		case EPowerHalSetCaseCloseSwitchesOff:
   139 			if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseCloseSwitchesOff")))
   140 				return KErrPermissionDenied;
   141 			mc.iOnOffInfo.iCaseCloseSwitchesOff = (TUint8)(TUint)a1;
   142 			break;
   143 		case EPowerHalCaseCloseSwitchesOff:
   144 			kumemput32(a1, &mc.iOnOffInfo.iCaseCloseSwitchesOff, sizeof(TBool));
   145 			break;
   146 		case EPowerHalTestBootSequence:
   147 			r = EFalse;
   148 			break;
   149 		case EPowerHalBackupPresent:
   150 			{
   151 			TBool ret=EFalse;
   152 			kumemput32(a1, &ret, sizeof(TBool));
   153 			}
   154 			break;
   155 		case EPowerHalAcessoryPowerPresent:
   156 			{
   157 			TBool ret=EFalse;
   158 			kumemput32(a1, &ret, sizeof(TBool));
   159 			}
   160 			break;
   161 		default:
   162 			r = KErrNotSupported;
   163 			break;
   164 		}
   165 	return r;
   166 	}
   167 
   168 TInt BinaryPowerInit()
   169 	{
   170 	__KTRACE_OPT(KPOWER,Kern::Printf("BinaryPowerInit()"));
   171 	BinaryBatteryMonitor = new DBinaryBatteryMonitor();
   172 	if (!BinaryBatteryMonitor)
   173 		return KErrNoMemory;
   174 	BinaryPowerHal = new DBinaryPowerHal();
   175 	if (!BinaryPowerHal)
   176 		return KErrNoMemory;
   177 	return KErrNone;
   178 	}