xref: /illumos-gate/usr/src/uts/sun4u/sys/i2c/clients/i2c_client.h (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_I2C_CLIENT_H
28 #define	_I2C_CLIENT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Common IOCTL definitions for client drivers.
38  */
39 
40 #define	I2C_BASE_IOCTL	('M' << 8)
41 
42 #define	I2C_GET_PORT		(I2C_BASE_IOCTL | 0)
43 #define	I2C_SET_PORT		(I2C_BASE_IOCTL | 1)
44 #define	I2C_GET_BIT		(I2C_BASE_IOCTL | 2)
45 #define	I2C_SET_BIT		(I2C_BASE_IOCTL | 3)
46 #define	I2C_GET_REG		(I2C_BASE_IOCTL | 4)
47 #define	I2C_SET_REG		(I2C_BASE_IOCTL | 5)
48 #define	I2C_GET_TEMPERATURE	(I2C_BASE_IOCTL | 7)
49 #define	I2C_GET_FAN_SPEED	(I2C_BASE_IOCTL | 8)
50 #define	I2C_SET_FAN_SPEED	(I2C_BASE_IOCTL | 9)
51 #define	I2C_SET_OUTPUT		(I2C_BASE_IOCTL | 10)
52 #define	I2C_GET_OUTPUT		(I2C_BASE_IOCTL | 11)
53 #define	I2C_GET_INPUT		(I2C_BASE_IOCTL | 12)
54 #define	I2C_SET_MODE		(I2C_BASE_IOCTL | 13)
55 #define	I2C_GET_MODE		(I2C_BASE_IOCTL | 14)
56 
57 /*
58  * A private IOCTL definition to be used by clients. The first 128 ioctls
59  * derived by OR'ing with I2C_BASE_IOCTL are common. The next 128
60  * ioctls derived by OR'ing with I2C_PVT_BASE_IOCTL are client private.
61  */
62 
63 #define	I2C_PVT_BASE_IOCTL	(I2C_BASE_IOCTL + 128)
64 
65 /*
66  * ARGS for I2C_*_MODE
67  */
68 #define	I2C_NORMAL	0
69 #define	I2C_DEBUG	1
70 
71 /*
72  * ARGS for i2c_bit_t direction
73  */
74 
75 #define	DIR_NO_CHANGE	0
76 #define	DIR_OUTPUT	1
77 #define	DIR_INPUT	2
78 
79 
80 #define	INST_TO_MINOR(x) (x << 4)
81 #define	MINOR_TO_INST(x) ((x & 0xFFFFFFF0) >> 4)
82 #define	PORT_TO_MINOR(x)  (x)
83 #define	MINOR_TO_PORT(x)  (0x0F & x)
84 
85 #define	I2C_PORT(x)		(0x00 + x)
86 
87 typedef struct i2c_port {
88 	uint8_t		value;
89 	uint8_t		direction;
90 	uint8_t		dir_mask;
91 } i2c_port_t;
92 
93 typedef struct i2c_bit {
94 	uchar_t		bit_num;
95 	boolean_t	bit_value;
96 	uint8_t		direction;
97 } i2c_bit_t;
98 
99 typedef struct i2c_reg {
100 	uint8_t		reg_num;
101 	int32_t		reg_value;
102 } i2c_reg_t;
103 
104 #if defined(_KERNEL)
105 
106 #include <sys/i2c/misc/i2c_svc.h>
107 
108 #endif /* _KERNEL */
109 
110 #ifdef	__cplusplus
111 }
112 #endif
113 
114 #endif /* _I2C_CLIENT_H */
115