1*0Sstevel@tonic-gate 2*0Sstevel@tonic-gate /* 3*0Sstevel@tonic-gate * Copyright (c) 1999 by Sun Microsystems, Inc. 4*0Sstevel@tonic-gate * All rights reserved. 5*0Sstevel@tonic-gate */ 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gate #ifndef _I2C_SVC_H 8*0Sstevel@tonic-gate #define _I2C_SVC_H 9*0Sstevel@tonic-gate 10*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 11*0Sstevel@tonic-gate 12*0Sstevel@tonic-gate #ifdef __cplusplus 13*0Sstevel@tonic-gate extern "C" { 14*0Sstevel@tonic-gate #endif 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate /* 17*0Sstevel@tonic-gate * I2C interface return values 18*0Sstevel@tonic-gate */ 19*0Sstevel@tonic-gate #define I2C_SUCCESS 0 20*0Sstevel@tonic-gate #define I2C_FAILURE -1 21*0Sstevel@tonic-gate #define I2C_INCOMPLETE -2 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate /* 24*0Sstevel@tonic-gate * Used for flags in i2c_transfer_alloc() 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate #define I2C_SLEEP 0x01 27*0Sstevel@tonic-gate #define I2C_NOSLEEP 0x02 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Version for i2c_transfer_t.i2c_version 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate #define I2C_XFER_REV 0 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate /* 35*0Sstevel@tonic-gate * Version for i2c_svc_t.i2c_nexus_version 36*0Sstevel@tonic-gate */ 37*0Sstevel@tonic-gate #define I2C_NEXUS_REV 0 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* 41*0Sstevel@tonic-gate * Valid transfer flags for i2c_transfer.flags 42*0Sstevel@tonic-gate */ 43*0Sstevel@tonic-gate #define I2C_WR 0x01 /* write */ 44*0Sstevel@tonic-gate #define I2C_RD 0x02 /* read */ 45*0Sstevel@tonic-gate #define I2C_WR_RD 0x04 /* write then read */ 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* 48*0Sstevel@tonic-gate * Developer's note: i2c_transfer_copyout is sensitive to 49*0Sstevel@tonic-gate * the ordering of i2c_transfer structure fields. If any fields 50*0Sstevel@tonic-gate * are changed, make sure to review i2c_transfer_copyout for 51*0Sstevel@tonic-gate * possible changes. 52*0Sstevel@tonic-gate * 53*0Sstevel@tonic-gate * Fields prefixed with 'I' are input fields passed to the 54*0Sstevel@tonic-gate * i2c_transfer function, while those prefixed with 'O' 55*0Sstevel@tonic-gate * are returned from the transfer function. 56*0Sstevel@tonic-gate */ 57*0Sstevel@tonic-gate typedef struct i2c_transfer { 58*0Sstevel@tonic-gate uint16_t i2c_version; /* I: Set to I2C_XFER_REV_0 */ 59*0Sstevel@tonic-gate uchar_t *i2c_wbuf; /* I: pointer to write buffer */ 60*0Sstevel@tonic-gate uchar_t *i2c_rbuf; /* I: pointer to read buffer */ 61*0Sstevel@tonic-gate int i2c_flags; /* I: description of transfer */ 62*0Sstevel@tonic-gate uint16_t i2c_wlen; /* I: length of write buffer */ 63*0Sstevel@tonic-gate uint16_t i2c_rlen; /* I: length of read buffer */ 64*0Sstevel@tonic-gate uint16_t i2c_w_resid; /* O: bytes not written */ 65*0Sstevel@tonic-gate uint16_t i2c_r_resid; /* O: bytes not read */ 66*0Sstevel@tonic-gate int16_t i2c_result; /* O: return value */ 67*0Sstevel@tonic-gate } i2c_transfer_t; 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate typedef struct i2c_client_hdl *i2c_client_hdl_t; 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate /* 72*0Sstevel@tonic-gate * i2c_nexus_reg is passed to the I2C services module 73*0Sstevel@tonic-gate * through the i2c_nexus_register() interface by the nexus 74*0Sstevel@tonic-gate * driver. It contains a version plus the pointer to 75*0Sstevel@tonic-gate * the functions that I2C services calls. 76*0Sstevel@tonic-gate */ 77*0Sstevel@tonic-gate typedef struct i2c_nexus_reg { 78*0Sstevel@tonic-gate int i2c_nexus_version; /* set to I2C_NEXUS_REV_0 */ 79*0Sstevel@tonic-gate int (*i2c_nexus_transfer)(dev_info_t *dip, struct i2c_transfer *); 80*0Sstevel@tonic-gate } i2c_nexus_reg_t; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate /* 83*0Sstevel@tonic-gate * Interfaces for I2C client drivers 84*0Sstevel@tonic-gate */ 85*0Sstevel@tonic-gate int i2c_client_register(dev_info_t *dip, i2c_client_hdl_t *i2c_hdl); 86*0Sstevel@tonic-gate void i2c_client_unregister(i2c_client_hdl_t i2c_hdl); 87*0Sstevel@tonic-gate int i2c_transfer(i2c_client_hdl_t i2c_hdl, i2c_transfer_t *i2c_tran); 88*0Sstevel@tonic-gate int i2c_transfer_alloc(i2c_client_hdl_t i2c_hdl, 89*0Sstevel@tonic-gate i2c_transfer_t **i2c, 90*0Sstevel@tonic-gate uint16_t wlen, 91*0Sstevel@tonic-gate uint16_t rlen, 92*0Sstevel@tonic-gate uint_t flags); 93*0Sstevel@tonic-gate void i2c_transfer_free(i2c_client_hdl_t i2c_hdl, i2c_transfer_t *i2c); 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate /* 96*0Sstevel@tonic-gate * Interfaces for I2C nexus drivers 97*0Sstevel@tonic-gate */ 98*0Sstevel@tonic-gate void i2c_nexus_register(dev_info_t *dip, i2c_nexus_reg_t *nexus_reg); 99*0Sstevel@tonic-gate void i2c_nexus_unregister(dev_info_t *dip); 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate #ifdef __cplusplus 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate #endif 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate #endif /* _I2C_SVC_H */ 106