#ifndef _APPLEGPIO_H
#define _APPLEGPIO_H
#include <IOKit/IOService.h>
#include <IOKit/IOPlatformExpert.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include "GPIOParent.h"
#include "IOPlatformFunction.h"
#define OLD_STYLE_COMPAT
#ifdef DLOG
#undef DLOG
#endif
#ifdef APPLEGPIO_DEBUG
#define DLOG(fmt, args...) kprintf(fmt, ## args)
#else
#define DLOG(fmt, args...)
#endif
#ifdef OLD_STYLE_COMPAT
#define ADD_OBJ_TO_SET(obj, set) \
{ if (set) \
{ \
if (!(set)->setObject(obj)) \
{ \
DLOG("AppleGPIO error adding to set\n"); \
return(-1); \
} \
} \
else \
{ \
(set) = OSSet::withObjects( (const OSObject **) &(obj), 1, 1); \
if (!(set)) \
{ \
DLOG("AppleGPIO error creating set\n"); \
return(-1); \
} \
} \
}
#define kFunctionRegisterPrefix "register-"
#define kFunctionUnregisterPrefix "unregister-"
#define kFunctionEvtEnablePrefix "enable-"
#define kFunctionEvtDisablePrefix "disable-"
#endif // OLD_STYLE_COMPAT
enum {
kAppleGPIOPowerOff = 0,
kAppleGPIOPowerOn = 1,
kAppleGPIONumPowerStates = 2,
kGPIOIDInvalid = 0xFFFFFFFF
};
typedef struct AppleGPIOCallbackInfo_
{
GPIOEventHandler handler;
void *param1;
void *param2;
bool isEnabled;
AppleGPIOCallbackInfo_ *next;
} AppleGPIOCallbackInfo;
class AppleGPIO : public IOService
{
OSDeclareDefaultStructors(AppleGPIO)
private:
IOService *fParent; UInt32 fGPIOID;
OSArray *fPlatformFuncArray;
bool fIntGen;
const OSSymbol *fSymIntRegister;
const OSSymbol *fSymIntUnRegister;
const OSSymbol *fSymIntEnable;
const OSSymbol *fSymIntDisable;
const OSSymbol *fSymGPIOParentWriteGPIO;
const OSSymbol *fSymGPIOParentReadGPIO;
AppleGPIOCallbackInfo *fClients; IOSimpleLock *fClientsLock;
bool performFunction(IOPlatformFunction *func, void *pfParam1,
void *pfParam2, void *pfParam3, void *pfParam4);
bool fAmRegistered;
IOLock *fAmRegisteredLock;
bool registerWithParent(void);
void unregisterWithParent(void);
bool amRegistered(void);
bool fAmEnabled;
IOSimpleLock *fAmEnabledLock;
void enableWithParent(void);
void disableWithParent(void);
bool amEnabled(void);
bool setAmEnabled(bool enabled);
bool registerClient(void *param1, void *param2,
void *param3);
bool unregisterClient(void *param1, void *param2,
void *param3);
bool enableClient(void *param1, void *param2,
void *param3);
bool disableClient(void *param1, void *param2,
void *param3);
bool areRegisteredClients(void);
bool areEnabledClients(void);
void handleEvent(void *newData, void *z1, void *z2);
IOPMrootDomain *pmRootDomain;
void doSleep(void);
void doWake(void);
#ifdef OLD_STYLE_COMPAT
OSSet *fRegisterStrings; OSSet *fUnregisterStrings; OSSet *fEnableStrings; OSSet *fDisableStrings;
void publishStrings(OSCollection *strings);
void releaseStrings(void);
#endif
public:
virtual bool init(OSDictionary *dict);
virtual void free(void);
virtual IOService *probe(IOService *provider, SInt32 *score);
virtual bool start(IOService *provider);
virtual void stop(IOService *provider);
virtual IOReturn callPlatformFunction( const OSSymbol * functionName,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4 );
static void sGPIOEventOccured(void *param1, void *param2,
void *param3, void *param4);
virtual IOReturn powerStateWillChangeTo (IOPMPowerFlags, unsigned long, IOService*);
};
#endif // _APPLEGPIO_H