2 * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _IOPMPowerSource_h_
30 #define _IOPMPowerSource_h_
32 #include <libkern/c++/OSObject.h>
33 #include <IOKit/pwr_mgt/IOPM.h>
34 #include <IOKit/IOTypes.h>
35 #include <IOKit/IOReturn.h>
36 #include <IOKit/IOService.h>
39 kSecondsPerHour
= 3600,
40 kTenMinutesInSeconds
= 600
44 /*! @class IOPMPowerSource
46 * See IOKit/pwr_mgt/IOPM.h for power source keys relevant to this class. These
47 * report-type keys are required for calls to IOPMPowerSource::setReportables(),
48 * and they define the IORegistry interface through which data is passed back
49 * up to the rest of the system.
51 * A subclassing driver that doesn't want to do anything fancy should:
52 * 1. Subclass IOPMPowerSource
53 * 2. Install its own battery change notifications or polling routine that can
54 * converse with actual battery hardware.
55 * 3. When battery state changes, change the relevant member variables
56 * through setCurrentCapacity() style accessors.
57 * 4. Call updateStatus() on itself when all such settings have been updated.
59 * The subclass driver should also initially populate its settings and call
60 * updateStatus() on launch.
68 * IORegistry Key: kIOPMPSExternalConnectedKey
69 * True if computer is drawing external power
71 * ExternalChargeCapable
73 * IORegistry Key: kIOPMPSExternalChargeCapableKey
74 * True if external power is capable of charging internal battery
78 * IORegistry Key: kIOPMPSBatteryInstalledKey
79 * True if a battery is present; false if removed
83 * IORegistry Key: kIOPMPSIsChargingKey
84 * True if battery is charging itself from external power
88 * IORegistry Key: kIOPMPSAtWarnLevelKey
89 * True if draining battery capacity and past warn level
93 * IORegistry Key: kIOPMPSAtCriticalLevelKey
94 * True if draining battery capacity and past critical level
99 * IORegistry Key: kIOPMPSCurrentCapacityKey, kIOPMPSMaxCapacityKey
100 * Capacity measured in mAh
104 * IORegistry Key: kIOPMPSTimeRemainingKey
105 * Time remaining measured in minutes
109 * IORegistry Key: kIOPMPSAmperageKey
110 * Current is measured in mA
114 * IORegistry Key: kIOPMPSVoltageKey
115 * Voltage measured in mV
119 * IORegistry Key: kIOPMPSCycleCountKey
120 * Number of charge/discharge cycles
124 * IORegistry Key: kIOPMPSAdapterInfoKey
125 * Power adapter information
129 * IORegistry Key: kIOPMPSLocationKey
130 * Clue about battery's location in machine - Left vs. Right
134 * IORegistry Key: kIOPMPSErrorConditionKey
135 * String describing error state of battery
139 * IORegistry Key: kIOPMPSManufacturerKey
140 * String describing battery manufacturer
143 * Type: unsigned 16-bit bitfield
144 * IORegistry Key: kIOPMPSManufactureDateKey
145 * Date is published in a bitfield per the Smart Battery Data spec rev 1.1
147 * Bits 0...4 => day (value 1-31; 5 bits)
148 * Bits 5...8 => month (value 1-12; 4 bits)
149 * Bits 9...15 => years since 1980 (value 0-127; 7 bits)
153 * IORegistry Key: kIOPMPSModelKey
154 * String describing model number
158 * IORegistry Key: kIOPMPSSerialKey
159 * String describing serial number or unique info
160 * The serial number published hear bears no correspondence to the Apple serial
161 * number printed on each battery. This is a manufacturer serial number with
162 * no correlation to the printed serial number.
164 * LegacyIOBatteryInfo
166 * IORegistry Key: kIOPMPSLegacyBatteryInfoKey
167 * Dictionary conforming to the OS X 10.0-10.4
171 class IOPMPowerSource
: public IOService
173 OSDeclareDefaultStructors(IOPMPowerSource
)
175 friend class IOPMPowerSourceList
;
179 /*! @var settingsChangedSinceLastUpdate
180 * Used by subclasses to determine if any settings have been modified via the
181 * accessors below since last call to update(). true is settings have changed;
184 bool settingsChangedSinceUpdate
;
187 * Stores power source state
189 OSDictionary
*properties
;
191 const OSSymbol
*externalConnectedKey
;
192 const OSSymbol
*externalChargeCapableKey
;
193 const OSSymbol
*batteryInstalledKey
;
194 const OSSymbol
*chargingKey
;
195 const OSSymbol
*warnLevelKey
;
196 const OSSymbol
*criticalLevelKey
;
197 const OSSymbol
*currentCapacityKey
;
198 const OSSymbol
*maxCapacityKey
;
199 const OSSymbol
*timeRemainingKey
;
200 const OSSymbol
*amperageKey
;
201 const OSSymbol
*voltageKey
;
202 const OSSymbol
*cycleCountKey
;
203 const OSSymbol
*adapterInfoKey
;
204 const OSSymbol
*locationKey
;
205 const OSSymbol
*errorConditionKey
;
206 const OSSymbol
*manufacturerKey
;
207 const OSSymbol
*modelKey
;
208 const OSSymbol
*serialKey
;
209 const OSSymbol
*batteryInfoKey
;
211 // Tracking for IOPMPowerSourceList
212 IOPMPowerSource
*nextInList
;
216 /*! @function powerSource
217 @abstract Creates a new IOPMPowerSource nub. Must be attached to IORegistry,
218 and registered by provider.
220 static IOPMPowerSource
*powerSource(void);
222 virtual bool init(void) APPLE_KEXT_OVERRIDE
;
224 virtual void free(void) APPLE_KEXT_OVERRIDE
;
226 /*! @function updateStatus
227 @abstract Must be called by physical battery controller when battery state
228 has changed significantly.
229 @discussion The system will not poll this object for battery updates. Rather \
230 the battery's controller must call updateStatus() every time state changes \
231 and the settings will be relayed to higher levels of power management. \
232 The subclassing driver should override this only if the driver needs to add \
233 new settings to the base class.
235 virtual void updateStatus(void);
237 /* Public accessors for battery state
239 bool externalConnected(void);
240 bool externalChargeCapable(void);
241 bool batteryInstalled(void);
242 bool isCharging(void);
243 bool atWarnLevel(void);
244 bool atCriticalLevel(void);
246 unsigned int currentCapacity(void);
247 unsigned int maxCapacity(void);
248 unsigned int capacityPercentRemaining(void);
249 int timeRemaining(void);
251 unsigned int voltage(void);
252 unsigned int cycleCount(void);
253 int adapterInfo(void);
256 OSSymbol
*errorCondition(void);
257 OSSymbol
*manufacturer(void);
258 OSSymbol
*model(void);
259 OSSymbol
*serial(void);
260 OSDictionary
*legacyIOBatteryInfo(void);
262 OSObject
*getPSProperty(const OSSymbol
*);
266 /* Protected "setter" methods for subclasses
267 * Subclasses should use these setters to modify all battery properties.
269 * Subclasses must follow all property changes with a call to updateStatus()
270 * to flush settings changes to upper level battery API clients.
273 void setExternalConnected(bool);
274 void setExternalChargeCapable(bool);
275 void setBatteryInstalled(bool);
276 void setIsCharging(bool);
277 void setAtWarnLevel(bool);
278 void setAtCriticalLevel(bool);
280 void setCurrentCapacity(unsigned int);
281 void setMaxCapacity(unsigned int);
282 void setTimeRemaining(int);
283 void setAmperage(int);
284 void setVoltage(unsigned int);
285 void setCycleCount(unsigned int);
286 void setAdapterInfo(int);
287 void setLocation(int);
289 void setErrorCondition(OSSymbol
*);
290 void setManufacturer(OSSymbol
*);
291 void setModel(OSSymbol
*);
292 void setSerial(OSSymbol
*);
293 void setLegacyIOBatteryInfo(OSDictionary
*);
295 /*! All of these methods funnel through the generic accessor method
296 setPSProperty. Caller can pass in any arbitrary OSSymbol key, and
297 that value will be stored in the PM settings dictionary, and relayed
298 onto the IORegistry at update time.
300 void setPSProperty(const OSSymbol
*, OSObject
*);