1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/power/binary/bpower.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,178 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\drivers\power\binary\bpower.cpp
1.18 +// Binary power model
1.19 +//
1.20 +//
1.21 +
1.22 +#include <assp.h>
1.23 +#include <kernel/kern_priv.h>
1.24 +#include <kernel/kpower.h>
1.25 +#include "mconf.h"
1.26 +#include <e32keys.h>
1.27 +
1.28 +NONSHARABLE_CLASS(DBinaryBatteryMonitor) : public DBatteryMonitor
1.29 + {
1.30 +public: // from DBatteryMonitor
1.31 + void SystemTimeChanged(TInt anOldTime, TInt aNewTime);
1.32 + TSupplyStatus MachinePowerStatus();
1.33 +public:
1.34 + DBinaryBatteryMonitor();
1.35 + void SupplyInfo(TSupplyInfoV1& si);
1.36 + };
1.37 +DBinaryBatteryMonitor* BinaryBatteryMonitor;
1.38 +
1.39 +NONSHARABLE_CLASS(DBinaryPowerHal) : public DPowerHal
1.40 + {
1.41 +public: // from DPowerHal
1.42 + TInt PowerHalFunction(TInt aFunction, TAny* a1, TAny* a2);
1.43 +public:
1.44 + DBinaryPowerHal();
1.45 +private:
1.46 + void InitData();
1.47 + };
1.48 +DBinaryPowerHal* BinaryPowerHal;
1.49 +
1.50 +DBinaryBatteryMonitor::DBinaryBatteryMonitor()
1.51 + {
1.52 + Register();
1.53 + }
1.54 +
1.55 +void DBinaryBatteryMonitor::SystemTimeChanged(TInt /* aOldTime */, TInt /* aNewTime */)
1.56 + {
1.57 + }
1.58 +
1.59 +void DBinaryBatteryMonitor::SupplyInfo(TSupplyInfoV1& si)
1.60 + {
1.61 + si.iMainBatteryStatus = EZero;
1.62 + si.iMainBatteryMilliVolts = 0;
1.63 + si.iMainBatteryMaxMilliVolts = 0;
1.64 + si.iBackupBatteryStatus = EZero;
1.65 + si.iBackupBatteryMilliVolts = 0;
1.66 + si.iBackupBatteryMaxMilliVolts = 0;
1.67 + si.iMainBatteryInsertionTime = 0;
1.68 + si.iMainBatteryInUseMicroSeconds = 0;
1.69 + si.iMainBatteryConsumedMilliAmpSeconds = 0;
1.70 + si.iExternalPowerPresent = 0;
1.71 + si.iExternalPowerInUseMicroSeconds = 0;
1.72 + si.iCurrentConsumptionMilliAmps = 0;
1.73 + si.iFlags = 0;
1.74 + }
1.75 +
1.76 +TSupplyStatus DBinaryBatteryMonitor::MachinePowerStatus()
1.77 + {
1.78 + return EGood;
1.79 + }
1.80 +
1.81 +
1.82 +DBinaryPowerHal::DBinaryPowerHal()
1.83 + {
1.84 + Register();
1.85 + // initialise persistent data on cold start
1.86 + if (Kern::ColdStart())
1.87 + InitData();
1.88 + }
1.89 +
1.90 +void DBinaryPowerHal::InitData()
1.91 + {
1.92 + TActualMachineConfig& mc = TheActualMachineConfig();
1.93 + TOnOffInfoV1& i = mc.iOnOffInfo;
1.94 + i.iPointerSwitchesOn = EFalse;
1.95 + i.iCaseOpenSwitchesOn = EFalse;
1.96 + i.iCaseCloseSwitchesOff = EFalse;
1.97 + }
1.98 +
1.99 +TInt DBinaryPowerHal::PowerHalFunction(TInt aFunction, TAny* a1, TAny* /* a2 */)
1.100 + {
1.101 + __KTRACE_OPT(KPOWER,Kern::Printf("DBinaryPowerHal::PowerHalFunction() func=0x%x, a1=0x%x", aFunction, a1));
1.102 + TActualMachineConfig& mc=TheActualMachineConfig();
1.103 + TInt r=KErrNone;
1.104 + switch(aFunction)
1.105 + {
1.106 + case EPowerHalSwitchOff:
1.107 + if(!Kern::CurrentThreadHasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSwitchOff")))
1.108 + return KErrPermissionDenied;
1.109 + {
1.110 + TRawEvent v;
1.111 + v.Set(TRawEvent::ESwitchOff);
1.112 + Kern::AddEvent(v);
1.113 + }
1.114 + break;
1.115 + case EPowerHalOnOffInfo:
1.116 + Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&mc.iOnOffInfo, sizeof(mc.iOnOffInfo));
1.117 + break;
1.118 + case EPowerHalSupplyInfo:
1.119 + {
1.120 + TSupplyInfoV1 si;
1.121 + BinaryBatteryMonitor->SupplyInfo(si);
1.122 + Kern::InfoCopy(*(TDes8*)a1, (TUint8*)&si, sizeof(si));
1.123 + break;
1.124 + }
1.125 + case EPowerHalSetPointerSwitchesOn:
1.126 + if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal Function EPowerHalSetPointerSwitchesOn")))
1.127 + return KErrPermissionDenied;
1.128 + mc.iOnOffInfo.iPointerSwitchesOn = (TUint8)(TUint)a1;
1.129 + break;
1.130 + case EPowerHalPointerSwitchesOn:
1.131 + kumemput32(a1, &mc.iOnOffInfo.iPointerSwitchesOn, sizeof(TBool));
1.132 + break;
1.133 + case EPowerHalSetCaseOpenSwitchesOn:
1.134 + if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseOpenSwitchesOn")))
1.135 + return KErrPermissionDenied;
1.136 + mc.iOnOffInfo.iCaseOpenSwitchesOn = (TUint8)(TUint)a1;
1.137 + break;
1.138 + case EPowerHalCaseOpenSwitchesOn:
1.139 + kumemput32(a1, &mc.iOnOffInfo.iCaseOpenSwitchesOn, sizeof(TBool));
1.140 + break;
1.141 + case EPowerHalSetCaseCloseSwitchesOff:
1.142 + if(!Kern::CurrentThreadHasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by Hal function EPowerHalSetCaseCloseSwitchesOff")))
1.143 + return KErrPermissionDenied;
1.144 + mc.iOnOffInfo.iCaseCloseSwitchesOff = (TUint8)(TUint)a1;
1.145 + break;
1.146 + case EPowerHalCaseCloseSwitchesOff:
1.147 + kumemput32(a1, &mc.iOnOffInfo.iCaseCloseSwitchesOff, sizeof(TBool));
1.148 + break;
1.149 + case EPowerHalTestBootSequence:
1.150 + r = EFalse;
1.151 + break;
1.152 + case EPowerHalBackupPresent:
1.153 + {
1.154 + TBool ret=EFalse;
1.155 + kumemput32(a1, &ret, sizeof(TBool));
1.156 + }
1.157 + break;
1.158 + case EPowerHalAcessoryPowerPresent:
1.159 + {
1.160 + TBool ret=EFalse;
1.161 + kumemput32(a1, &ret, sizeof(TBool));
1.162 + }
1.163 + break;
1.164 + default:
1.165 + r = KErrNotSupported;
1.166 + break;
1.167 + }
1.168 + return r;
1.169 + }
1.170 +
1.171 +TInt BinaryPowerInit()
1.172 + {
1.173 + __KTRACE_OPT(KPOWER,Kern::Printf("BinaryPowerInit()"));
1.174 + BinaryBatteryMonitor = new DBinaryBatteryMonitor();
1.175 + if (!BinaryBatteryMonitor)
1.176 + return KErrNoMemory;
1.177 + BinaryPowerHal = new DBinaryPowerHal();
1.178 + if (!BinaryPowerHal)
1.179 + return KErrNoMemory;
1.180 + return KErrNone;
1.181 + }