xref: /onnv-gate/usr/src/uts/sun4u/sys/i2c/nexus/i2bsc_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _NEXUS_I2BSC_IMPL_H
28*0Sstevel@tonic-gate #define	_NEXUS_I2BSC_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef	__cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/modctl.h>
37*0Sstevel@tonic-gate #include <sys/promif.h>
38*0Sstevel@tonic-gate #include <sys/lom_ebuscodes.h>
39*0Sstevel@tonic-gate #include <sys/bscbus.h>
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate /*
42*0Sstevel@tonic-gate  * When "#address-cells" is 1, it means we aren't multiplexing i2c busses.  We
43*0Sstevel@tonic-gate  * therefore mark the bus number to I2BSC_DEFAULT_BUS.
44*0Sstevel@tonic-gate  */
45*0Sstevel@tonic-gate #define	I2BSC_DEFAULT_BUS		0
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /*
48*0Sstevel@tonic-gate  * Since i2c transfers are slow and take up lots of time, we limit our i2c
49*0Sstevel@tonic-gate  * transfer size to an advertised limit, I2BSC_MAX_TRANSFER_SZ bytes.
50*0Sstevel@tonic-gate  * The value was derived from an EEPROM page size of 32 bytes + 2 bytes to
51*0Sstevel@tonic-gate  * denote the address offset within the EEPROM.
52*0Sstevel@tonic-gate  */
53*0Sstevel@tonic-gate #define	I2BSC_MAX_TRANSFER_SZ		34
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /*
56*0Sstevel@tonic-gate  * Address Space Accessors
57*0Sstevel@tonic-gate  */
58*0Sstevel@tonic-gate #define	I2BSC_NEXUS_ADDR(ssp, as, index) \
59*0Sstevel@tonic-gate 	(&((ssp)->bscbus_regs[((as) * 256) + (index)]))
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate /*
62*0Sstevel@tonic-gate  * Re-try limit on Accessors was determined empircally.  During a firmware
63*0Sstevel@tonic-gate  * download (the most heavy use of the comms channel), retries of up to 21
64*0Sstevel@tonic-gate  * attempts have been seen.  The next power of 2 up is 32; the chosen retry
65*0Sstevel@tonic-gate  * limit.
66*0Sstevel@tonic-gate  */
67*0Sstevel@tonic-gate #define	I2BSC_RETRY_LIMIT		32
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate /*
70*0Sstevel@tonic-gate  * During attach processing we need to figure out if the firmware is broken
71*0Sstevel@tonic-gate  * from the start.  If our re-try strategy is too aggressive we get poor
72*0Sstevel@tonic-gate  * boot times.  Therefore, the initial broken firmware check done during attach
73*0Sstevel@tonic-gate  * is given a relatively low retry threshold.
74*0Sstevel@tonic-gate  */
75*0Sstevel@tonic-gate #define	I2BSC_SHORT_RETRY_LIMIT		4
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate /*
79*0Sstevel@tonic-gate  * strace(1M) prints out the debug data once the debug value is set in
80*0Sstevel@tonic-gate  * the i2bsc.conf file and the debug driver is installed.
81*0Sstevel@tonic-gate  *
82*0Sstevel@tonic-gate  * Debug flags
83*0Sstevel@tonic-gate  *
84*0Sstevel@tonic-gate  * '@' - Register (@)ccess
85*0Sstevel@tonic-gate  * 'A' - (A)ttach
86*0Sstevel@tonic-gate  * 'D' - (D)ettach
87*0Sstevel@tonic-gate  * 'S' - (S)ession
88*0Sstevel@tonic-gate  * 'T' - I2C (T)ransfer
89*0Sstevel@tonic-gate  * 'U' - (U)pload
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate /*
93*0Sstevel@tonic-gate  * Debug tips :
94*0Sstevel@tonic-gate  *
95*0Sstevel@tonic-gate  * strace(1M) prints out the debug data.
96*0Sstevel@tonic-gate  * A nice way to work out the debug value set in i2bsc.conf is to use mdb
97*0Sstevel@tonic-gate  * Say we want to show 'T' i2c transfer and 'U' upload processing,
98*0Sstevel@tonic-gate  * you calculate the debug value with the following mdb session :
99*0Sstevel@tonic-gate  *	# mdb
100*0Sstevel@tonic-gate  *	> 1<<('T'-'@') | 1<<('U'-'@') = X
101*0Sstevel@tonic-gate  *	                300000
102*0Sstevel@tonic-gate  *
103*0Sstevel@tonic-gate  *      > $q
104*0Sstevel@tonic-gate  * When you explicitly set "debug=0x300000;" in i2bsc.conf, it causes the
105*0Sstevel@tonic-gate  * debug driver to log Transfer and upload messages for strace(1M).
106*0Sstevel@tonic-gate  */
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate typedef struct i2bsc {
109*0Sstevel@tonic-gate 	uint64_t		debug;		/* debugging turned on */
110*0Sstevel@tonic-gate 	short			majornum;	/* debugging - major number */
111*0Sstevel@tonic-gate 	short			minornum;	/* debugging - minor number */
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate 	int			i2c_proxy_support;
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	ddi_device_acc_attr_t	bscbus_attr;	/* bscbus attributes */
116*0Sstevel@tonic-gate 	ddi_acc_handle_t	bscbus_handle;	/* bscbus opaque handle */
117*0Sstevel@tonic-gate 	uint32_t		bscbus_fault;	/* 0 => okay		*/
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate 	/*
120*0Sstevel@tonic-gate 	 * A session is a set of contigious gets/puts marked either as
121*0Sstevel@tonic-gate 	 * successful or failed.
122*0Sstevel@tonic-gate 	 */
123*0Sstevel@tonic-gate 	int			bscbus_session_failure;
124*0Sstevel@tonic-gate 	uint8_t			*bscbus_regs;	/* bscbus register space */
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	dev_info_t		*i2bsc_dip;
127*0Sstevel@tonic-gate 	int			i2bsc_attachflags;
128*0Sstevel@tonic-gate 	kmutex_t		i2bsc_imutex;
129*0Sstevel@tonic-gate 	kcondvar_t		i2bsc_icv;
130*0Sstevel@tonic-gate 	int			i2bsc_open;
131*0Sstevel@tonic-gate 	int			i2bsc_busy;
132*0Sstevel@tonic-gate 	int			i2bsc_bus;
133*0Sstevel@tonic-gate 	i2c_transfer_t		*i2bsc_cur_tran;
134*0Sstevel@tonic-gate 	dev_info_t		*i2bsc_cur_dip;
135*0Sstevel@tonic-gate 	char			i2bsc_name[MODMAXNAMELEN];
136*0Sstevel@tonic-gate } i2bsc_t;
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate /*
139*0Sstevel@tonic-gate  * i2c_parent_pvt contains info that is chip specific
140*0Sstevel@tonic-gate  * and is stored on the child's devinfo parent private data.
141*0Sstevel@tonic-gate  */
142*0Sstevel@tonic-gate typedef struct i2bsc_ppvt {
143*0Sstevel@tonic-gate 	int i2bsc_ppvt_bus; /* multiple I2C busses on a single set of */
144*0Sstevel@tonic-gate 			    /* registers.  this tells it what bus to */
145*0Sstevel@tonic-gate 			    /* use  */
146*0Sstevel@tonic-gate 	int i2bsc_ppvt_addr; /* address of I2C device */
147*0Sstevel@tonic-gate } i2bsc_ppvt_t;
148*0Sstevel@tonic-gate 
149*0Sstevel@tonic-gate #define	I2BSC_INITIAL_SOFT_SPACE	1
150*0Sstevel@tonic-gate 
151*0Sstevel@tonic-gate /*
152*0Sstevel@tonic-gate  * Attach flags
153*0Sstevel@tonic-gate  */
154*0Sstevel@tonic-gate #define	SETUP_REGS	0x01
155*0Sstevel@tonic-gate #define	NEXUS_REGISTER	0x02
156*0Sstevel@tonic-gate #define	IMUTEX		0x04
157*0Sstevel@tonic-gate #define	MINOR_NODE	0x08
158*0Sstevel@tonic-gate #define	FIRMWARE_ALIVE	0x10
159*0Sstevel@tonic-gate #define	TRANSFER_SZ	0x20
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate #ifdef	__cplusplus
162*0Sstevel@tonic-gate }
163*0Sstevel@tonic-gate #endif
164*0Sstevel@tonic-gate 
165*0Sstevel@tonic-gate #endif /* _NEXUS_I2BSC_IMPL_H */
166