xref: /illumos-gate/usr/src/uts/sun4u/sys/i2c/nexus/smbus.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef _SMBUS_H
28*7c478bd9Sstevel@tonic-gate #define	_SMBUS_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate  * Attach flags
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate #define	SETUP_REGS	0x01
42*7c478bd9Sstevel@tonic-gate #define	NEXUS_REGISTER	0x02
43*7c478bd9Sstevel@tonic-gate #define	IMUTEX		0x04
44*7c478bd9Sstevel@tonic-gate #define	ADD_INTR	0x08
45*7c478bd9Sstevel@tonic-gate #define	INTERRUPT_PRI	0x10
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate  * Register offsets
49*7c478bd9Sstevel@tonic-gate  */
50*7c478bd9Sstevel@tonic-gate #define	SMB_STS		0x00
51*7c478bd9Sstevel@tonic-gate #define	SMB_TYP		0x01
52*7c478bd9Sstevel@tonic-gate #define	STR_PORT	0x02
53*7c478bd9Sstevel@tonic-gate #define	DEV_ADDR	0x03
54*7c478bd9Sstevel@tonic-gate #define	DEV_DATA0	0x04
55*7c478bd9Sstevel@tonic-gate #define	DEV_DATA1	0x05
56*7c478bd9Sstevel@tonic-gate #define	BLK_DATA	0x06
57*7c478bd9Sstevel@tonic-gate #define	SMB_CMD		0x07
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * Bit values for SMB_STS (status) register
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate #define	FAILED		0x80
63*7c478bd9Sstevel@tonic-gate #define	BUS_ERR		0x40
64*7c478bd9Sstevel@tonic-gate #define	DRV_ERR		0x20
65*7c478bd9Sstevel@tonic-gate #define	CMD_CMPL	0x10
66*7c478bd9Sstevel@tonic-gate #define	HOST_BSY	0x08
67*7c478bd9Sstevel@tonic-gate #define	IDLE		0x04
68*7c478bd9Sstevel@tonic-gate #define	INDEX		0x04
69*7c478bd9Sstevel@tonic-gate #define	TENBITS		0x02
70*7c478bd9Sstevel@tonic-gate #define	ALERT		0x01
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate  * Bit values for the SMB_TYP (command type) register
74*7c478bd9Sstevel@tonic-gate  */
75*7c478bd9Sstevel@tonic-gate #define	DEV10B_EN	0x80
76*7c478bd9Sstevel@tonic-gate #define	QUICK_CMD	0x00
77*7c478bd9Sstevel@tonic-gate #define	SEND_BYTE	0x10
78*7c478bd9Sstevel@tonic-gate #define	RCV_BYTE	0x10
79*7c478bd9Sstevel@tonic-gate #define	WR_BYTE		0x20
80*7c478bd9Sstevel@tonic-gate #define	RD_BYTE		0x20
81*7c478bd9Sstevel@tonic-gate #define	WR_WORD		0x30
82*7c478bd9Sstevel@tonic-gate #define	RD_WORD		0x30
83*7c478bd9Sstevel@tonic-gate #define	WR_BLK		0x40
84*7c478bd9Sstevel@tonic-gate #define	RD_BLK		0x40
85*7c478bd9Sstevel@tonic-gate #define	PRC_CALL	0x50
86*7c478bd9Sstevel@tonic-gate #define	T_OUT		0x08
87*7c478bd9Sstevel@tonic-gate #define	KILL		0x04
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate #define	SMBUS_PIL	4
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate #define	MAX_BLK_SEND	32
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /*
94*7c478bd9Sstevel@tonic-gate  * Used to or in bit 0 to be 1 for I2C read address.
95*7c478bd9Sstevel@tonic-gate  */
96*7c478bd9Sstevel@tonic-gate #define	I2C_READ	0x01
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /*
99*7c478bd9Sstevel@tonic-gate  * The maximum number of times to retry in event of
100*7c478bd9Sstevel@tonic-gate  * a failure.
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate #define	SMBUS_MAX_RETRIES	10
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate /*
105*7c478bd9Sstevel@tonic-gate  * If smbus_put() should make sure the buffer is flushed.
106*7c478bd9Sstevel@tonic-gate  */
107*7c478bd9Sstevel@tonic-gate #define	SMBUS_FLUSH 0x01
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /*
110*7c478bd9Sstevel@tonic-gate  * The time in microseconds to wait before the timeout fires
111*7c478bd9Sstevel@tonic-gate  * to protect against an interrupt never arriving.
112*7c478bd9Sstevel@tonic-gate  */
113*7c478bd9Sstevel@tonic-gate #define	INTR_TIMEOUT 100000
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate  * Time to wait in microseconds for any transaction before giving up
117*7c478bd9Sstevel@tonic-gate  * ie 10 seconds.
118*7c478bd9Sstevel@tonic-gate  */
119*7c478bd9Sstevel@tonic-gate #define	SMBUS_TRANS_TIMEOUT 10000000
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /*
122*7c478bd9Sstevel@tonic-gate  * smbus event mode selection. select poll or interrupt mode
123*7c478bd9Sstevel@tonic-gate  */
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate #define	SMBUS_POLL_MODE		1	/* polling mode */
126*7c478bd9Sstevel@tonic-gate #define	SMBUS_POLL_TIMEOUT	50000
127*7c478bd9Sstevel@tonic-gate 					/*
128*7c478bd9Sstevel@tonic-gate 					 * how long to wait(us) for
129*7c478bd9Sstevel@tonic-gate 					 * command completion.
130*7c478bd9Sstevel@tonic-gate 					 */
131*7c478bd9Sstevel@tonic-gate #define	SMBUS_POLL_INTERVAL	1
132*7c478bd9Sstevel@tonic-gate 					/*
133*7c478bd9Sstevel@tonic-gate 					 * time (us) to wait between
134*7c478bd9Sstevel@tonic-gate 					 * polls: must be small in comparison
135*7c478bd9Sstevel@tonic-gate 					 * to the time an an i2c transaction
136*7c478bd9Sstevel@tonic-gate 					 * takes.
137*7c478bd9Sstevel@tonic-gate 					 */
138*7c478bd9Sstevel@tonic-gate /*
139*7c478bd9Sstevel@tonic-gate  * Scale polling retries so that the total timeout is "SMBUS_POLL_TIMEOUT"
140*7c478bd9Sstevel@tonic-gate  */
141*7c478bd9Sstevel@tonic-gate #define	SMBUS_POLL_MAX_RETRIES	(SMBUS_POLL_TIMEOUT/SMBUS_POLL_INTERVAL)
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate /*
145*7c478bd9Sstevel@tonic-gate  * smbus_ppvt_t contains info that is chip specific
146*7c478bd9Sstevel@tonic-gate  * and is stored on the child's devinfo parent private data.
147*7c478bd9Sstevel@tonic-gate  */
148*7c478bd9Sstevel@tonic-gate typedef struct smbus_ppvt {
149*7c478bd9Sstevel@tonic-gate 	int	smbus_ppvt_addr; /* address of I2C device */
150*7c478bd9Sstevel@tonic-gate } smbus_ppvt_t;
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate typedef struct smbus {
153*7c478bd9Sstevel@tonic-gate 	dev_info_t		*smbus_dip;
154*7c478bd9Sstevel@tonic-gate 	int			smbus_attachflags;
155*7c478bd9Sstevel@tonic-gate 	kmutex_t		smbus_mutex;
156*7c478bd9Sstevel@tonic-gate 	kmutex_t		smbus_imutex;
157*7c478bd9Sstevel@tonic-gate 	kcondvar_t		smbus_icv;
158*7c478bd9Sstevel@tonic-gate 	kcondvar_t		smbus_cv;
159*7c478bd9Sstevel@tonic-gate 	kcondvar_t		smbus_intr_cv;
160*7c478bd9Sstevel@tonic-gate 	ddi_iblock_cookie_t	smbus_icookie;
161*7c478bd9Sstevel@tonic-gate 	int			smbus_busy;
162*7c478bd9Sstevel@tonic-gate 	int			smbus_wait;
163*7c478bd9Sstevel@tonic-gate 	int			smbus_bus;
164*7c478bd9Sstevel@tonic-gate 	i2c_transfer_t		*smbus_cur_tran;
165*7c478bd9Sstevel@tonic-gate 	dev_info_t		*smbus_cur_dip;
166*7c478bd9Sstevel@tonic-gate 	char			smbus_name[12];
167*7c478bd9Sstevel@tonic-gate 	uint8_t			*smbus_regaddr;
168*7c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	smbus_rhandle;
169*7c478bd9Sstevel@tonic-gate 	uint8_t			*smbus_configregaddr;
170*7c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	smbus_confighandle;
171*7c478bd9Sstevel@tonic-gate 	timeout_id_t		smbus_timeout;
172*7c478bd9Sstevel@tonic-gate 	int		smbus_saved_w_resid;
173*7c478bd9Sstevel@tonic-gate 	int		smbus_retries;
174*7c478bd9Sstevel@tonic-gate 	int		smbus_bytes_to_read;
175*7c478bd9Sstevel@tonic-gate 	int		smbus_poll_complete;
176*7c478bd9Sstevel@tonic-gate 							/*
177*7c478bd9Sstevel@tonic-gate 							 * Boolean:true if
178*7c478bd9Sstevel@tonic-gate 							 * polling is complete
179*7c478bd9Sstevel@tonic-gate 							 */
180*7c478bd9Sstevel@tonic-gate 	int		smbus_polling;
181*7c478bd9Sstevel@tonic-gate 							/*
182*7c478bd9Sstevel@tonic-gate 							 * Boolean: true if
183*7c478bd9Sstevel@tonic-gate 							 * driver is polling
184*7c478bd9Sstevel@tonic-gate 							 */
185*7c478bd9Sstevel@tonic-gate 	int		smbus_poll_retries;
186*7c478bd9Sstevel@tonic-gate 								/*
187*7c478bd9Sstevel@tonic-gate 								 * How many
188*7c478bd9Sstevel@tonic-gate 								 * times we
189*7c478bd9Sstevel@tonic-gate 								 * have polled
190*7c478bd9Sstevel@tonic-gate 								 * the status
191*7c478bd9Sstevel@tonic-gate 								 * register. Not
192*7c478bd9Sstevel@tonic-gate 								 * to be
193*7c478bd9Sstevel@tonic-gate 								 * confused with
194*7c478bd9Sstevel@tonic-gate 								 * "retries",
195*7c478bd9Sstevel@tonic-gate 								 * which is how
196*7c478bd9Sstevel@tonic-gate 								 * many times we
197*7c478bd9Sstevel@tonic-gate 								 * tried after
198*7c478bd9Sstevel@tonic-gate 								 * an error
199*7c478bd9Sstevel@tonic-gate 								 */
200*7c478bd9Sstevel@tonic-gate } smbus_t;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate #define	PRT_INIT	0x01
203*7c478bd9Sstevel@tonic-gate #define	PRT_WR		0x02
204*7c478bd9Sstevel@tonic-gate #define	PRT_RD		0x04
205*7c478bd9Sstevel@tonic-gate #define	PRT_PUT		0x08
206*7c478bd9Sstevel@tonic-gate #define	PRT_GET		0x10
207*7c478bd9Sstevel@tonic-gate #define	PRT_ATTACH	0x20
208*7c478bd9Sstevel@tonic-gate #define	PRT_INTR	0x40
209*7c478bd9Sstevel@tonic-gate #define	PRT_INTR_ERR	0x80
210*7c478bd9Sstevel@tonic-gate #define	PRT_TRANS	0x100
211*7c478bd9Sstevel@tonic-gate #define	PRT_SPEC	0x200
212*7c478bd9Sstevel@tonic-gate #define	PRT_BUFFONLY	0x1000
213*7c478bd9Sstevel@tonic-gate #define	PRT_PROM	0x2000
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate /*
216*7c478bd9Sstevel@tonic-gate  * smbus_switch return status
217*7c478bd9Sstevel@tonic-gate  */
218*7c478bd9Sstevel@tonic-gate #define	SMBUS_PENDING	0x01
219*7c478bd9Sstevel@tonic-gate #define	SMBUS_COMPLETE	0x02
220*7c478bd9Sstevel@tonic-gate #define	SMBUS_FAILURE	0x03
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate #define	SMBUS_SUCCESS	0x04
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate #define	SMBUS_SRC_STATUS	0x48
225*7c478bd9Sstevel@tonic-gate #define	SMBUS_SRC_ENA		0x44
226*7c478bd9Sstevel@tonic-gate #define	SMBUS_SMI		0x80000
227*7c478bd9Sstevel@tonic-gate #define	SMBUS_SMB_INTR_STATUS	0x80000
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate #define	SMBUS_INTR	"smbus_intr"
230*7c478bd9Sstevel@tonic-gate #define	SMBUS_TIMEOUT	"smbus_timeout"
231*7c478bd9Sstevel@tonic-gate #define	SMBUS_POLL	"smbus_poll"
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
234*7c478bd9Sstevel@tonic-gate #define	SMBUS_PRINT(a)	smbus_print a
235*7c478bd9Sstevel@tonic-gate #else
236*7c478bd9Sstevel@tonic-gate #define	SMBUS_PRINT(a)
237*7c478bd9Sstevel@tonic-gate #endif
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate /*
241*7c478bd9Sstevel@tonic-gate  * Other function delcarations
242*7c478bd9Sstevel@tonic-gate  */
243*7c478bd9Sstevel@tonic-gate int smbus_transfer(dev_info_t *, i2c_transfer_t *);
244*7c478bd9Sstevel@tonic-gate void smbus_print(int flags, const char *fmt, ...);
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
247*7c478bd9Sstevel@tonic-gate }
248*7c478bd9Sstevel@tonic-gate #endif
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate #endif /* _SMBUS_H */
251