1 /******************************************************************************
2  *
3  * Name:	ski2c.h
4  * Project:	Gigabit Ethernet Adapters, TWSI-Module
5  * Purpose:	Defines to access Voltage and Temperature Sensor
6  *
7  ******************************************************************************/
8 
9 /******************************************************************************
10  *
11  *	(C)Copyright 1998-2002 SysKonnect.
12  *	(C)Copyright 2002-2003 Marvell.
13  *
14  *	This program is free software; you can redistribute it and/or modify
15  *	it under the terms of the GNU General Public License as published by
16  *	the Free Software Foundation; either version 2 of the License, or
17  *	(at your option) any later version.
18  *
19  *	The information in this file is provided "AS IS" without warranty.
20  *
21  ******************************************************************************/
22 
23 /*
24  * SKI2C.H	contains all I2C specific defines
25  */
26 
27 #ifndef _SKI2C_H_
28 #define _SKI2C_H_
29 
30 typedef struct  s_Sensor SK_SENSOR;
31 
32 #include "h/skgei2c.h"
33 
34 /*
35  * Define the I2C events.
36  */
37 #define SK_I2CEV_IRQ	1	/* IRQ happened Event */
38 #define SK_I2CEV_TIM	2	/* Timeout event */
39 #define SK_I2CEV_CLEAR	3	/* Clear MIB Values */
40 
41 /*
42  * Define READ and WRITE Constants.
43  */
44 #define I2C_READ	0
45 #define I2C_WRITE	1
46 #define I2C_BURST	1
47 #define I2C_SINGLE	0
48 
49 #define SKERR_I2C_E001		(SK_ERRBASE_I2C+0)
50 #define SKERR_I2C_E001MSG	"Sensor index unknown"
51 #define SKERR_I2C_E002		(SKERR_I2C_E001+1)
52 #define SKERR_I2C_E002MSG	"TWSI: transfer does not complete"
53 #define SKERR_I2C_E003		(SKERR_I2C_E002+1)
54 #define SKERR_I2C_E003MSG	"LM80: NAK on device send"
55 #define SKERR_I2C_E004		(SKERR_I2C_E003+1)
56 #define SKERR_I2C_E004MSG	"LM80: NAK on register send"
57 #define SKERR_I2C_E005		(SKERR_I2C_E004+1)
58 #define SKERR_I2C_E005MSG	"LM80: NAK on device (2) send"
59 #define SKERR_I2C_E006		(SKERR_I2C_E005+1)
60 #define SKERR_I2C_E006MSG	"Unknown event"
61 #define SKERR_I2C_E007		(SKERR_I2C_E006+1)
62 #define SKERR_I2C_E007MSG	"LM80 read out of state"
63 #define SKERR_I2C_E008		(SKERR_I2C_E007+1)
64 #define SKERR_I2C_E008MSG	"Unexpected sensor read completed"
65 #define SKERR_I2C_E009		(SKERR_I2C_E008+1)
66 #define SKERR_I2C_E009MSG	"WARNING: temperature sensor out of range"
67 #define SKERR_I2C_E010		(SKERR_I2C_E009+1)
68 #define SKERR_I2C_E010MSG	"WARNING: voltage sensor out of range"
69 #define SKERR_I2C_E011		(SKERR_I2C_E010+1)
70 #define SKERR_I2C_E011MSG	"ERROR: temperature sensor out of range"
71 #define SKERR_I2C_E012		(SKERR_I2C_E011+1)
72 #define SKERR_I2C_E012MSG	"ERROR: voltage sensor out of range"
73 #define SKERR_I2C_E013		(SKERR_I2C_E012+1)
74 #define SKERR_I2C_E013MSG	"ERROR: couldn't init sensor"
75 #define SKERR_I2C_E014		(SKERR_I2C_E013+1)
76 #define SKERR_I2C_E014MSG	"WARNING: fan sensor out of range"
77 #define SKERR_I2C_E015		(SKERR_I2C_E014+1)
78 #define SKERR_I2C_E015MSG	"ERROR: fan sensor out of range"
79 #define SKERR_I2C_E016		(SKERR_I2C_E015+1)
80 #define SKERR_I2C_E016MSG	"TWSI: active transfer does not complete"
81 
82 /*
83  * Define Timeout values
84  */
85 #define SK_I2C_TIM_LONG		2000000L	/* 2 seconds */
86 #define SK_I2C_TIM_SHORT	 100000L	/* 100 milliseconds */
87 #define SK_I2C_TIM_WATCH	1000000L	/* 1 second */
88 
89 /*
90  * Define trap and error log hold times
91  */
92 #ifndef	SK_SEN_ERR_TR_HOLD
93 #define SK_SEN_ERR_TR_HOLD		(4*SK_TICKS_PER_SEC)
94 #endif
95 #ifndef	SK_SEN_ERR_LOG_HOLD
96 #define SK_SEN_ERR_LOG_HOLD		(60*SK_TICKS_PER_SEC)
97 #endif
98 #ifndef	SK_SEN_WARN_TR_HOLD
99 #define SK_SEN_WARN_TR_HOLD		(15*SK_TICKS_PER_SEC)
100 #endif
101 #ifndef	SK_SEN_WARN_LOG_HOLD
102 #define SK_SEN_WARN_LOG_HOLD	(15*60*SK_TICKS_PER_SEC)
103 #endif
104 
105 /*
106  * Defines for SenType
107  */
108 #define SK_SEN_UNKNOWN	0
109 #define SK_SEN_TEMP		1
110 #define SK_SEN_VOLT		2
111 #define SK_SEN_FAN		3
112 
113 /*
114  * Define for the SenErrorFlag
115  */
116 #define SK_SEN_ERR_NOT_PRESENT	0	/* Error Flag: Sensor not present */
117 #define SK_SEN_ERR_OK			1	/* Error Flag: O.K. */
118 #define SK_SEN_ERR_WARN			2	/* Error Flag: Warning */
119 #define SK_SEN_ERR_ERR			3	/* Error Flag: Error */
120 #define SK_SEN_ERR_FAULTY		4	/* Error Flag: Faulty */
121 
122 /*
123  * Define the Sensor struct
124  */
125 struct	s_Sensor {
126 	char	*SenDesc;			/* Description */
127 	int		SenType;			/* Voltage or Temperature */
128 	SK_I32	SenValue;			/* Current value of the sensor */
129 	SK_I32	SenThreErrHigh;		/* High error Threshhold of this sensor */
130 	SK_I32	SenThreWarnHigh;	/* High warning Threshhold of this sensor */
131 	SK_I32	SenThreErrLow;		/* Lower error Threshold of the sensor */
132 	SK_I32	SenThreWarnLow;		/* Lower warning Threshold of the sensor */
133 	int		SenErrFlag;			/* Sensor indicated an error */
134 	SK_BOOL	SenInit;			/* Is sensor initialized ? */
135 	SK_U64	SenErrCts;			/* Error trap counter */
136 	SK_U64	SenWarnCts;			/* Warning trap counter */
137 	SK_U64	SenBegErrTS;		/* Begin error timestamp */
138 	SK_U64	SenBegWarnTS;		/* Begin warning timestamp */
139 	SK_U64	SenLastErrTrapTS;	/* Last error trap timestamp */
140 	SK_U64	SenLastErrLogTS;	/* Last error log timestamp */
141 	SK_U64	SenLastWarnTrapTS;	/* Last warning trap timestamp */
142 	SK_U64	SenLastWarnLogTS;	/* Last warning log timestamp */
143 	int		SenState;			/* Sensor State (see HW specific include) */
144 	int		(*SenRead)(SK_AC *pAC, SK_IOC IoC, struct s_Sensor *pSen);
145 								/* Sensors read function */
146 	SK_U16	SenReg;				/* Register Address for this sensor */
147 	SK_U8	SenDev;				/* Device Selection for this sensor */
148 };
149 
150 typedef	struct	s_I2c {
151 	SK_SENSOR	SenTable[SK_MAX_SENSORS];	/* Sensor Table */
152 	int			CurrSens;	/* Which sensor is currently queried */
153 	int			MaxSens;	/* Max. number of sensors */
154 	int			TimerMode;	/* Use the timer also to watch the state machine */
155 	int			InitLevel;	/* Initialized Level */
156 #ifndef SK_DIAG
157 	int			DummyReads;	/* Number of non-checked dummy reads */
158 	SK_TIMER	SenTimer;	/* Sensors timer */
159 #endif /* !SK_DIAG */
160 } SK_I2C;
161 
162 extern int SkI2cInit(SK_AC *pAC, SK_IOC IoC, int Level);
163 extern int SkI2cWrite(SK_AC *pAC, SK_IOC IoC, SK_U32 Data, int Dev, int Size,
164 					   int Reg, int Burst);
165 extern int SkI2cReadSensor(SK_AC *pAC, SK_IOC IoC, SK_SENSOR *pSen);
166 #ifdef SK_DIAG
167 extern	SK_U32 SkI2cRead(SK_AC *pAC, SK_IOC IoC, int Dev, int Size, int Reg,
168 						 int Burst);
169 #else /* !SK_DIAG */
170 extern int SkI2cEvent(SK_AC *pAC, SK_IOC IoC, SK_U32 Event, SK_EVPARA Para);
171 extern void SkI2cWaitIrq(SK_AC *pAC, SK_IOC IoC);
172 extern void SkI2cIsr(SK_AC *pAC, SK_IOC IoC);
173 #endif /* !SK_DIAG */
174 #endif /* n_SKI2C_H */
175 
176