#ifndef _IOI2CSMUSat_H
#define _IOI2CSMUSat_H
#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/IODeviceTreeSupport.h>
#include <IOKit/IOPlatformExpert.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include "IOPlatformFunction.h"
#include <IOI2C/IOI2CDevice.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IOCommandGate.h>
#ifdef DLOG
#undef DLOG
#endif
#ifdef SMUSAT_DEBUG
#define DLOG(fmt, args...) kprintf(fmt, ## args)
#else
#define DLOG(fmt, args...)
#endif
#define kNumRetries 10
enum
{
kTypeUnknown = 0, kTypeTemperature = 1,
kTypeADC = 2,
kTypeVoltage = 3,
kTypeCurrent = 4,
kLUN_TABLE_COUNT = 15
};
enum
{
kSatSDBPartitionIDRegister = 0x08,
kSatSDBPartitionIDSize = 2,
kSatSDBPartitionLengthRegister = 0x09,
kSatSDBPartitionLengthSize = 2,
kSatSDBPartitionDataRegister = 0x0A,
kSatSDBPartitionDataSize = 4,
kSatFlashCommandRegister = 0x40, kSatFlashStatusRegister = 0x41, kSatFlashBufferRegister = 0x42, kSatFlashCmdReset = 0x00, kSatFlashCmdRead = 0x10, kSatFlashCmdErase = 0x20, kSatFlashCmdWrite = 0x40, kSatFlashCmdXFer = 0xE0, kSatFlashCmdSuccess = 0, kSATCacheRegBase = 0x30,
kSatRegCacheTop = 0x38,
kCacheExpirationIntervalMilliseconds = 1000, kSatFlashTransferLength = 16,
kSATFlashNoError = 0,
kSatSPUBaseAddress = 0xFC000,
kSatSPUUpdateAddress = 0xF8000,
kSatSPUSize = 0x4000,
kSatSDBBaseAddress = 0xF000,
kSatSDBUpdateAddress = 0xF800, kSatSDBSize = 0x800,
};
inline UInt32 FlashParams (UInt32 flashCmd, UInt32 flashAddr) { return ((flashCmd << 24) | (flashAddr & 0xFFFFFF)); };
struct LogicalUnitNumberTable
{
UInt32 reg;
UInt8 type;
};
enum {
kHWSensorPollingPeriodNULL = 0xFFFFFFFF
};
struct SatFlashInput {
UInt8 *buffer;
UInt32 length;
UInt32 flashAddress;
};
struct SatFlashOutput {
UInt32 result;
};
class IOI2CSMUSat : public IOI2CDevice
{
OSDeclareDefaultStructors(IOI2CSMUSat)
private:
task_t fTask;
const OSSymbol *fGetSensorValueSym;
const OSSymbol *fSymDownloadCommand;
const OSSymbol *fSymGetDBPartition;
UInt16 fCachedSensorData[8];
AbsoluteTime fCacheExpirationTime;
UInt16 fNumberOfControlLoopsReading;
LogicalUnitNumberTable LUNtable[kLUN_TABLE_COUNT]; UInt8 LUNtableElement; UInt32 fFlashTransferLength;
bool fFlashInProgress;
UInt32 fFlashAddress, fBytesDone, fBytesTotal;
IOReturn publishChildren(IOService *);
IOReturn updateSensorCache ( void );
IOReturn readI2CCached ( UInt32 subAddress, UInt8 *data, UInt32 count );
IOReturn getSensor( UInt32 Reg, SInt32 * temp );
IOReturn flashReadWithStatus( UInt32 subAddress, UInt8 *data, UInt32 count );
IOReturn flashWriteWithStatus( UInt32 subAddress, UInt8 *data, UInt32 count );
IOLock *fCacheLock;
IOWorkLoop *fWorkLoop;
IOTimerEventSource *fTimerSource;
static void timerEventOccurred(OSObject *, IOTimerEventSource *);
protected:
public:
virtual bool start( IOService * );
virtual void stop( IOService * );
virtual bool init( OSDictionary * );
virtual void free( void );
using IOService::getProperty;
virtual OSObject *getProperty( const OSSymbol *) const;
using IOService::setProperty;
virtual bool setProperty( const OSSymbol *, OSObject * );
using IOService::callPlatformFunction;
virtual IOReturn callPlatformFunction( const OSSymbol *, bool, void *, void *, void *, void * );
virtual IOReturn callPlatformFunction( const char *, bool, void *, void *, void *, void * );
virtual OSData *getPartition( UInt32, UInt32 dbSelector = 0);
IOReturn flash( UInt8 *, UInt32, UInt32 );
IOReturn flashDownload( UInt8 *, UInt32, UInt32, UInt32 );
IOReturn reportProgress( UInt32 *, UInt32 *, UInt32 * );
IOReturn newUserClient(task_t owningTask,
void *security_id,
UInt32 type, OSDictionary *properties,
IOUserClient **handler);
IOReturn newUserClient(task_t owningTask,
void *security_id,
UInt32 type, IOUserClient **handler);
};
#endif // _IOI2CSMUSat_H