AppleSmartBattery.h [plain text]
#ifndef __AppleSmartBattery__
#define __AppleSmartBattery__
#include <IOKit/IOService.h>
#include <IOKit/pwr_mgt/IOPMPowerSource.h>
#include <IOKit/smbus/IOSMBusController.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>
#include "AppleSmartBatteryCommands.h"
#include "AppleSmartBatteryManager.h"
#define kBatteryPollingDebugKey "BatteryPollingPeriodOverride"
class AppleSmartBatteryManager;
class AppleSmartBattery : public IOPMPowerSource {
OSDeclareDefaultStructors(AppleSmartBattery)
protected:
AppleSmartBatteryManager *fProvider;
IOWorkLoop *fWorkLoop;
IOTimerEventSource *fPollTimer;
IOTimerEventSource *fBatteryReadAllTimer;
bool fStalledByUserClient;
bool fCancelPolling;
bool fPollingNow;
IOSMBusTransaction fTransaction;
uint16_t fMachinePath;
uint32_t fPollingInterval;
bool fPollingOverridden;
bool fRebootPolling;
bool fInflowDisabled;
bool fChargeInhibited;
uint16_t fRemainingCapacity;
uint16_t fFullChargeCapacity;
uint8_t fInitialPollCountdown;
uint8_t fIncompleteReadRetries;
int fRetryAttempts;
IOService * fPowerServiceToAck;
bool fSystemSleeping;
bool fPermanentFailure;
bool fFullyDischarged;
bool fFullyCharged;
int fBatteryPresent;
int fACConnected;
int fAvgCurrent;
OSArray *fCellVoltages;
IOACPIPlatformDevice *fACPIProvider;
void setMaxErr(int error);
int maxErr(void);
void setDeviceName(OSSymbol *sym);
OSSymbol *deviceName(void);
void setFullyCharged(bool);
bool fullyCharged(void);
void setInstantaneousTimeToEmpty(int seconds);
void setInstantAmperage(int mA);
void setAverageTimeToEmpty(int seconds);
int averageTimeToEmpty(void);
void setAverageTimeToFull(int seconds);
int averageTimeToFull(void);
void setManufactureDate(int date);
int manufactureDate(void);
void setSerialNumber(uint16_t sernum);
uint16_t serialNumber(void);
void setChargeStatus(const OSSymbol *sym);
const OSSymbol *chargeStatus(void);
void setManufacturerData(uint8_t *buffer, uint32_t bufferSize);
void oneTimeBatterySetup(void);
void constructAppleSerialNumber(void);
public:
static AppleSmartBattery *smartBattery(void);
virtual bool init(void);
virtual bool start(IOService *provider);
void setPollingInterval(int milliSeconds);
bool pollBatteryState(int path = 0);
void handleBatteryInserted(void);
void handleBatteryRemoved(void);
void handleInflowDisabled(bool inflow_state);
void handleChargeInhibited(bool charge_state);
void handleExclusiveAccess(bool exclusive);
IOReturn handleSystemSleepWake(IOService * powerService, bool isSystemSleep);
protected:
void logReadError( const char *error_type,
uint16_t additional_error,
IOSMBusTransaction *t);
void clearBatteryState(bool do_update);
void pollingTimeOut(void);
void incompleteReadTimeOut(void);
void rebuildLegacyIOBatteryInfo(void);
bool transactionCompletion(void *ref, IOSMBusTransaction *transaction);
IOReturn readWordAsync(uint8_t address, uint8_t cmd);
IOReturn writeWordAsync(uint8_t address, uint8_t cmd, uint16_t writeWord);
IOReturn readBlockAsync(uint8_t address, uint8_t cmd);
void acknowledgeSystemSleepWake( void );
};
#endif