xref: /freebsd/sys/dev/smbus/smbconf.h (revision 94dce599)
1 /*-
2  * Copyright (c) 1998 Nicolas Souchu
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef __SMBONF_H
29 #define __SMBONF_H
30 
31 #include <sys/queue.h>
32 
33 #define SMBPRI (PZERO+8)		/* XXX sleep/wakeup queue priority */
34 
35 #define n(flags) (~(flags) & (flags))
36 
37 /* Order constants for smbus children. */
38 #define SMBUS_ORDER_HINTED	20
39 #define SMBUS_ORDER_PNP		40
40 
41 /*
42  * How tsleep() is called in smb_request_bus().
43  */
44 #define SMB_DONTWAIT	0
45 #define SMB_NOINTR	0
46 #define SMB_WAIT	0x1
47 #define SMB_INTR	0x2
48 
49 /*
50  * callback index
51  */
52 #define SMB_REQUEST_BUS	0x1
53 #define SMB_RELEASE_BUS	0x2
54 
55 /*
56  * SMB bus errors
57  */
58 #define SMB_ENOERR	0x0
59 #define SMB_EBUSERR	0x1
60 #define SMB_ENOTSUPP	0x2
61 #define SMB_ENOACK	0x4
62 #define SMB_ECOLLI	0x8
63 #define SMB_EABORT	0x10
64 #define SMB_ETIMEOUT	0x20
65 #define SMB_EBUSY	0x40
66 #define	SMB_EINVAL	0x100
67 
68 /*
69  * How Quick command is executed
70  */
71 #define SMB_QWRITE	0x0
72 #define SMB_QREAD	0x1
73 
74 /*
75  * smbus transction op with pass-thru capabilities
76  *
77  * This smbus function is capable of doing a smbus command transaction
78  * (read or write), and can be flagged to not issue the 'cmd' and/or
79  * issue or expect a count field as well as flagged for chaining (no STOP),
80  * which gives it an i2c pass-through capability.
81  *
82  * NOSTOP- Caller chaining transactions, do not issue STOP
83  * NOCMD-  Do not transmit the command field
84  * NOCNT-  Do not transmit (wr) or expect (rd) the count field
85  */
86 #define SMB_TRANS_NOSTOP  0x0001  /* do not send STOP at end */
87 #define SMB_TRANS_NOCMD   0x0002  /* ignore cmd field (do not tx) */
88 #define SMB_TRANS_NOCNT   0x0004  /* do not tx or rx count field */
89 #define SMB_TRANS_7BIT    0x0008  /* change address mode to 7-bit */
90 #define SMB_TRANS_10BIT   0x0010  /* change address mode to 10-bit */
91 #define SMB_TRANS_NOREPORT  0x0020  /* do not report errors */
92 
93 /*
94  * ivars codes
95  */
96 enum smbus_ivars {
97     SMBUS_IVAR_ADDR,	/* slave address of the device */
98 };
99 
100 int	smbus_request_bus(device_t, device_t, int);
101 int	smbus_release_bus(device_t, device_t);
102 device_t smbus_alloc_bus(device_t);
103 int	smbus_error(int error);
104 
105 void	smbus_intr(device_t, u_char, char low, char high, int error);
106 
107 #define SMBUS_ACCESSOR(var, ivar, type)					\
108 	__BUS_ACCESSOR(smbus, var, SMBUS, ivar, type)
109 
110 SMBUS_ACCESSOR(addr,		ADDR,		int)
111 
112 #undef SMBUS_ACCESSOR
113 
114 extern driver_t smbus_driver;
115 extern devclass_t smbus_devclass;
116 
117 #define smbus_quick(bus,slave,how) \
118 	(SMBUS_QUICK(device_get_parent(bus), slave, how))
119 #define smbus_sendb(bus,slave,byte) \
120 	(SMBUS_SENDB(device_get_parent(bus), slave, byte))
121 #define smbus_recvb(bus,slave,byte) \
122 	(SMBUS_RECVB(device_get_parent(bus), slave, byte))
123 #define smbus_writeb(bus,slave,cmd,byte) \
124 	(SMBUS_WRITEB(device_get_parent(bus), slave, cmd, byte))
125 #define smbus_writew(bus,slave,cmd,word) \
126 	(SMBUS_WRITEW(device_get_parent(bus), slave, cmd, word))
127 #define smbus_readb(bus,slave,cmd,byte) \
128 	(SMBUS_READB(device_get_parent(bus), slave, cmd, byte))
129 #define smbus_readw(bus,slave,cmd,word) \
130 	(SMBUS_READW(device_get_parent(bus), slave, cmd, word))
131 #define smbus_pcall(bus,slave,cmd,sdata,rdata) \
132 	(SMBUS_PCALL(device_get_parent(bus), slave, cmd, sdata, rdata))
133 #define smbus_bwrite(bus,slave,cmd,count,buf) \
134 	(SMBUS_BWRITE(device_get_parent(bus), slave, cmd, count, buf))
135 #define smbus_bread(bus,slave,cmd,count,buf) \
136 	(SMBUS_BREAD(device_get_parent(bus), slave, cmd, count, buf))
137 #define smbus_trans(bus,slave,cmd,op,wbuf,wcount,rbuf,rcount,actualp) \
138 	(SMBUS_TRANS(device_get_parent(bus), slave, cmd, op, \
139 	wbuf, wcount, rbuf, rcount, actualp))
140 
141 #define SMBUS_MODVER	1
142 #define SMBUS_MINVER	1
143 #define SMBUS_MAXVER	1
144 #define SMBUS_PREFVER	SMBUS_MODVER
145 
146 #endif
147