#ifndef _IOI2CController_H
#define _IOI2CController_H
#include <IOKit/IOService.h>
#include <IOKit/IONotifier.h>
#include <IOI2C/IOI2CDefs.h>
class IOI2CController : public IOService
{
OSDeclareAbstractStructors( IOI2CController )
protected:
const OSSymbol *symLockI2CBus;
const OSSymbol *symUnlockI2CBus;
const OSSymbol *symReadI2CBus;
const OSSymbol *symWriteI2CBus;
const OSSymbol *symPowerInterest;
const OSSymbol *symPowerClient;
const OSSymbol *symPowerAcked;
const OSSymbol *symGetMaxI2CDataLength;
UInt32 fMaxI2CDataLength;
IOService *fProvider;
bool fDisablePowerManagement;
private:
enum
{
kIOI2C_CLIENT_KEY_LOCKED = (1 << 0),
kIOI2C_CLIENT_KEY_VALID = 0x1000,
kIOI2C_CLIENT_KEY_RESERVED = 0x80000000,
};
IOLock *fPowerLock;
IOLock *fClientLock; volatile semaphore_t
fClientSem;
UInt32 fClientLockKey;
bool fDeviceIsUsable;
bool fTransactionInProgress;
unsigned long fCurrentPowerState;
thread_call_t fIOSyncThreadCall; UInt32 fI2CBus;
#define kIOI2CMultiBusID 0xcafe12c
public:
virtual bool start ( IOService *provider );
virtual void stop ( IOService *provider );
virtual void free ( void );
using IOService::callPlatformFunction;
virtual IOReturn callPlatformFunction(
const OSSymbol *functionSymbol,
bool waitForFunction,
void *param1, void *param2,
void *param3, void *param4 );
private:
IOReturn clientReadI2C(
IOI2CCommand *cmd,
UInt32 clientKey);
IOReturn clientWriteI2C(
IOI2CCommand *cmd,
UInt32 clientKey);
IOReturn clientLockI2C(
UInt32 bus,
UInt32 *clientKeyRef);
IOReturn clientUnlockI2C(
UInt32 bus,
UInt32 clientKey);
protected:
IOReturn publishChildren(void);
IOReturn initI2CResources(void);
void freeI2CResources(void);
enum
{
kIOI2CPowerState_OFF = 0,
kIOI2CPowerState_SLEEP,
kIOI2CPowerState_DOZE,
kIOI2CPowerState_ON,
kIOI2CPowerState_COUNT
};
IOReturn InitializePowerManagement(void);
virtual IOReturn setPowerState(
unsigned long newPowerState,
IOService *dontCare);
static IOReturn sSysPowerDownHandler(
void *target,
void *refCon,
UInt32 messageType,
IOService *service,
void *messageArgument,
vm_size_t argSize);
static void sIOSyncCallback(
thread_call_param_t p0,
thread_call_param_t p1);
IOReturn registerPowerStateInterest(
IOService *client,
bool isRegistering);
bool notifyPowerStateInterest(void);
virtual IOReturn acknowledgeNotification(
IONotificationRef notification,
IOOptionBits response );
virtual IOReturn processLockI2CBus(
UInt32 bus) = 0;
virtual IOReturn processUnlockI2CBus(
UInt32 bus) = 0;
virtual IOReturn processReadI2CBus(
IOI2CCommand *cmd) = 0;
virtual IOReturn processWriteI2CBus(
IOI2CCommand *cmd) = 0;
using IOService::newUserClient;
virtual IOReturn newUserClient(
task_t owningTask,
void *securityID,
UInt32 type,
OSDictionary *properties,
IOUserClient **handler);
protected:
typedef struct ExpansionData {};
ExpansionData *reserved;
OSMetaClassDeclareReservedUnused ( IOI2CController, 0 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 1 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 2 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 3 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 4 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 5 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 6 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 7 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 8 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 9 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 10 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 11 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 12 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 13 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 14 );
OSMetaClassDeclareReservedUnused ( IOI2CController, 15 );
};
#endif // _IOI2CController_H