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