1706f2543Smrg/* 2706f2543Smrg * Copyright (C) 1998 Itai Nahshon, Michael Schimek 3706f2543Smrg */ 4706f2543Smrg 5706f2543Smrg 6706f2543Smrg#ifndef _XF86I2C_H 7706f2543Smrg#define _XF86I2C_H 8706f2543Smrg 9706f2543Smrg#include "regionstr.h" 10706f2543Smrg 11706f2543Smrgtypedef unsigned char I2CByte; 12706f2543Smrgtypedef unsigned short I2CSlaveAddr; 13706f2543Smrg 14706f2543Smrgtypedef struct _I2CBusRec *I2CBusPtr; 15706f2543Smrgtypedef struct _I2CDevRec *I2CDevPtr; 16706f2543Smrg 17706f2543Smrg/* I2C masters have to register themselves */ 18706f2543Smrg 19706f2543Smrgtypedef struct _I2CBusRec { 20706f2543Smrg char * BusName; 21706f2543Smrg int scrnIndex; 22706f2543Smrg 23706f2543Smrg void (*I2CUDelay) (I2CBusPtr b, int usec); 24706f2543Smrg 25706f2543Smrg void (*I2CPutBits)(I2CBusPtr b, int scl, int sda); 26706f2543Smrg void (*I2CGetBits)(I2CBusPtr b, int *scl, int *sda); 27706f2543Smrg 28706f2543Smrg /* Look at the generic routines to see how these functions should behave. */ 29706f2543Smrg 30706f2543Smrg Bool (*I2CStart) (I2CBusPtr b, int timeout); 31706f2543Smrg Bool (*I2CAddress)(I2CDevPtr d, I2CSlaveAddr); 32706f2543Smrg void (*I2CStop) (I2CDevPtr d); 33706f2543Smrg Bool (*I2CPutByte)(I2CDevPtr d, I2CByte data); 34706f2543Smrg Bool (*I2CGetByte)(I2CDevPtr d, I2CByte *data, Bool); 35706f2543Smrg 36706f2543Smrg DevUnion DriverPrivate; 37706f2543Smrg 38706f2543Smrg int HoldTime; /* 1 / bus clock frequency, 5 or 2 usec */ 39706f2543Smrg 40706f2543Smrg int BitTimeout; /* usec */ 41706f2543Smrg int ByteTimeout; /* usec */ 42706f2543Smrg int AcknTimeout; /* usec */ 43706f2543Smrg int StartTimeout; /* usec */ 44706f2543Smrg int RiseFallTime; /* usec */ 45706f2543Smrg 46706f2543Smrg I2CDevPtr FirstDev; 47706f2543Smrg I2CBusPtr NextBus; 48706f2543Smrg Bool (*I2CWriteRead)(I2CDevPtr d, I2CByte *WriteBuffer, int nWrite, 49706f2543Smrg I2CByte *ReadBuffer, int nRead); 50706f2543Smrg} I2CBusRec; 51706f2543Smrg 52706f2543Smrg#define CreateI2CBusRec xf86CreateI2CBusRec 53706f2543Smrgextern _X_EXPORT I2CBusPtr xf86CreateI2CBusRec(void); 54706f2543Smrg#define DestroyI2CBusRec xf86DestroyI2CBusRec 55706f2543Smrgextern _X_EXPORT void xf86DestroyI2CBusRec(I2CBusPtr pI2CBus, Bool unalloc, Bool devs_too); 56706f2543Smrg#define I2CBusInit xf86I2CBusInit 57706f2543Smrgextern _X_EXPORT Bool xf86I2CBusInit(I2CBusPtr pI2CBus); 58706f2543Smrg 59706f2543Smrgextern _X_EXPORT I2CBusPtr xf86I2CFindBus(int scrnIndex, char *name); 60706f2543Smrgextern _X_EXPORT int xf86I2CGetScreenBuses(int scrnIndex, I2CBusPtr **pppI2CBus); 61706f2543Smrg 62706f2543Smrg 63706f2543Smrg/* I2C slave devices */ 64706f2543Smrg 65706f2543Smrgtypedef struct _I2CDevRec { 66706f2543Smrg char * DevName; 67706f2543Smrg 68706f2543Smrg int BitTimeout; /* usec */ 69706f2543Smrg int ByteTimeout; /* usec */ 70706f2543Smrg int AcknTimeout; /* usec */ 71706f2543Smrg int StartTimeout; /* usec */ 72706f2543Smrg 73706f2543Smrg I2CSlaveAddr SlaveAddr; 74706f2543Smrg I2CBusPtr pI2CBus; 75706f2543Smrg I2CDevPtr NextDev; 76706f2543Smrg DevUnion DriverPrivate; 77706f2543Smrg} I2CDevRec; 78706f2543Smrg 79706f2543Smrg#define CreateI2CDevRec xf86CreateI2CDevRec 80706f2543Smrgextern _X_EXPORT I2CDevPtr xf86CreateI2CDevRec(void); 81706f2543Smrgextern _X_EXPORT void xf86DestroyI2CDevRec(I2CDevPtr pI2CDev, Bool unalloc); 82706f2543Smrg#define I2CDevInit xf86I2CDevInit 83706f2543Smrgextern _X_EXPORT Bool xf86I2CDevInit(I2CDevPtr pI2CDev); 84706f2543Smrgextern _X_EXPORT I2CDevPtr xf86I2CFindDev(I2CBusPtr, I2CSlaveAddr); 85706f2543Smrg 86706f2543Smrg/* See descriptions of these functions in xf86i2c.c */ 87706f2543Smrg 88706f2543Smrg#define I2CProbeAddress xf86I2CProbeAddress 89706f2543Smrgextern _X_EXPORT Bool xf86I2CProbeAddress(I2CBusPtr pI2CBus, I2CSlaveAddr); 90706f2543Smrg 91706f2543Smrg#define I2C_WriteRead xf86I2CWriteRead 92706f2543Smrgextern _X_EXPORT Bool xf86I2CWriteRead(I2CDevPtr d, I2CByte *WriteBuffer, int nWrite, 93706f2543Smrg I2CByte *ReadBuffer, int nRead); 94706f2543Smrg#define xf86I2CRead(d, rb, nr) xf86I2CWriteRead(d, NULL, 0, rb, nr) 95706f2543Smrg 96706f2543Smrgextern _X_EXPORT Bool xf86I2CReadStatus(I2CDevPtr d, I2CByte *pbyte); 97706f2543Smrgextern _X_EXPORT Bool xf86I2CReadByte(I2CDevPtr d, I2CByte subaddr, I2CByte *pbyte); 98706f2543Smrgextern _X_EXPORT Bool xf86I2CReadBytes(I2CDevPtr d, I2CByte subaddr, I2CByte *pbyte, int n); 99706f2543Smrgextern _X_EXPORT Bool xf86I2CReadWord(I2CDevPtr d, I2CByte subaddr, unsigned short *pword); 100706f2543Smrg#define xf86I2CWrite(d, wb, nw) xf86I2CWriteRead(d, wb, nw, NULL, 0) 101706f2543Smrgextern _X_EXPORT Bool xf86I2CWriteByte(I2CDevPtr d, I2CByte subaddr, I2CByte byte); 102706f2543Smrgextern _X_EXPORT Bool xf86I2CWriteBytes(I2CDevPtr d, I2CByte subaddr, I2CByte *WriteBuffer, int nWrite); 103706f2543Smrgextern _X_EXPORT Bool xf86I2CWriteWord(I2CDevPtr d, I2CByte subaddr, unsigned short word); 104706f2543Smrgextern _X_EXPORT Bool xf86I2CWriteVec(I2CDevPtr d, I2CByte *vec, int nValues); 105706f2543Smrg 106706f2543Smrg#endif /*_XF86I2C_H */ 107