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