#ifndef _I2CGPIO_H
#define _I2CGPIO_H
#include <IOKit/IOService.h>
#include "GPIOParent.h"
#ifdef DLOG
#undef DLOG
#endif
#ifdef I2CGPIO_DEBUG
#define DLOG(fmt, args...) kprintf(fmt, ## args)
#else
#define DLOG(fmt, args...)
#endif
#define kOpenI2CBus "openI2CBus"
#define kReadI2CBus "readI2CBus"
#define kWriteI2CBus "writeI2CBus"
#define kCloseI2CBus "closeI2CBus"
#define kSetCombinedMode "setCombinedMode"
#define kSetStandardSubMode "setStandardSubMode"
#define kRegisterForInts "registerForI2cInterrupts"
#define kDeRegisterForInts "deRegisterI2cClient"
#define kI2CGPIOCombined "i2c-combined"
enum {
kI2CReadRetryCount = 10,
kI2CWriteRetryCount = 10,
k9554InputPort = 0x00, k9554OutputPort = 0x01, k9554PolarityInv = 0x02, k9554Config = 0x03 };
typedef struct {
GPIOEventHandler handler;
void *self;
bool isEnabled;
} I2CGPIOCallbackInfo;
#define kNumGPIOs 8
enum {
kPresent = 3,
kSwitch = 4
};
enum {
kI2CGPIOPowerOff = 0,
kI2CGPIOPowerOn = 1,
kI2CGPIONumPowerStates = 2
};
class I2CGPIO : public IOService
{
OSDeclareDefaultStructors(I2CGPIO)
private:
UInt8 fI2CBus;
UInt8 fI2CAddress;
IOService *fI2CInterface;
IOService *fKeyswitch;
const OSSymbol *fSymOpenI2CBus;
const OSSymbol *fSymReadI2CBus;
const OSSymbol *fSymWriteI2CBus;
const OSSymbol *fSymCloseI2CBus;
const OSSymbol *fSymSetCombinedMode;
const OSSymbol *fSymSetStandardSubMode;
const OSSymbol *fSymRegisterForInts;
const OSSymbol *fSymDeRegisterForInts;
unsigned long fCurrentPowerState;
UInt8 fConfigReg;
UInt8 fPolarityReg;
UInt8 fOutputReg;
#ifdef I2CGPIO_DEBUG
UInt32 fWriteCookie;
UInt32 fReadCookie;
#endif
bool fC3Mapping;
bool fRegisteredWithI2C; IOLock *fRegisteredWithI2CLock;
UInt32 fBayIndex;
UInt32 fIntAddrInfo; UInt8 fIntRegState;
I2CGPIOCallbackInfo *fClients[kNumGPIOs];
IOReturn doI2CWrite(UInt8 busNo, UInt8 addr, UInt8 subAddr, UInt8 mask, UInt8 value);
IOReturn doI2CRead(UInt8 busNo, UInt8 addr, UInt8 subAddr, UInt8 *value);
bool registerClient(void *param1, void *param2, void *param3, void *param4);
bool unregisterClient(void *param1, void *param2, void *param3, void *param4);
bool enableClient(void *param1, void *param2, void *param3,
void *param4);
bool disableClient(void *param1, void *param2, void *param3,
void *param4);
void handleEvent(UInt32 addressInfo, UInt32 length, UInt8 *buffer);
bool registerWithI2C(void);
void unregisterWithI2C(void);
IOService *createNub(IORegistryEntry *from);
void processNub(IOService *myNub);
void publishBelow(IORegistryEntry *root);
void doPowerDown(void);
void doPowerUp(void);
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 setPowerState(unsigned long powerStateOrdinal,
IOService *whatDevice);
virtual IOReturn callPlatformFunction( const OSSymbol *functionName,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4 );
virtual IOReturn callPlatformFunction( const char *functionName,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4 );
static void sI2CEventOccured(I2CGPIO *client, UInt32 addressInfo,
UInt32 length, UInt8 *buffer);
};
class I2CGPIODevice : public IOService
{
OSDeclareDefaultStructors(I2CGPIODevice)
virtual bool compareName(OSString *name, OSString **matched) const;
};
#endif // _I2CGPIO_H