ski2c.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /******************************************************************************
  2. *
  3. * Name: ski2c.h
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.34 $
  6. * Date: $Date: 2003/01/28 09:11:21 $
  7. * Purpose: Defines to access Voltage and Temperature Sensor
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2003 SysKonnect GmbH.
  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. * History:
  25. *
  26. * $Log: ski2c.h,v $
  27. * Revision 1.34 2003/01/28 09:11:21 rschmidt
  28. * Editorial changes
  29. *
  30. * Revision 1.33 2002/10/14 16:40:50 rschmidt
  31. * Editorial changes (TWSI)
  32. *
  33. * Revision 1.32 2002/08/13 08:55:07 rschmidt
  34. * Editorial changes
  35. *
  36. * Revision 1.31 2002/08/06 09:44:22 jschmalz
  37. * Extensions and changes for Yukon
  38. *
  39. * Revision 1.30 2001/04/05 11:38:09 rassmann
  40. * Set SenState to idle in SkI2cWaitIrq().
  41. * Changed error message in SkI2cWaitIrq().
  42. *
  43. * Revision 1.29 2000/08/03 14:28:17 rassmann
  44. * - Added function to wait for I2C being ready before resetting the board.
  45. * - Replaced one duplicate "out of range" message with correct one.
  46. *
  47. * Revision 1.28 1999/11/22 13:55:46 cgoos
  48. * Changed license header to GPL.
  49. *
  50. * Revision 1.27 1999/05/20 09:23:10 cgoos
  51. * Changes for 1000Base-T (Fan sensors).
  52. *
  53. * Revision 1.26 1998/12/01 13:45:47 gklug
  54. * add: InitLevel to I2c struct
  55. *
  56. * Revision 1.25 1998/11/03 06:55:16 gklug
  57. * add: Dummy Reads to I2c struct
  58. *
  59. * Revision 1.24 1998/10/02 14:28:59 cgoos
  60. * Added prototype for SkI2cIsr.
  61. *
  62. * Revision 1.23 1998/09/08 12:20:11 gklug
  63. * add: prototypes for init and read functions
  64. *
  65. * Revision 1.22 1998/09/08 07:37:56 gklug
  66. * add: log error if PCI_IO voltage sensor could not be initialized
  67. *
  68. * Revision 1.21 1998/09/04 08:38:05 malthoff
  69. * Change the values for I2C_READ and I2C_WRITE
  70. *
  71. * Revision 1.20 1998/08/25 07:52:22 gklug
  72. * chg: Timestamps (last) added for logging
  73. *
  74. * Revision 1.19 1998/08/25 06:09:00 gklug
  75. * rmv: warning and error levels of the individual sensors.
  76. * add: timing definitions for sending traps and logging errors
  77. *
  78. * Revision 1.18 1998/08/20 11:41:15 gklug
  79. * chg: omit STRCPY macro by using char * as Sensor Description
  80. *
  81. * Revision 1.17 1998/08/20 11:37:43 gklug
  82. * chg: change Ioc to IoC
  83. *
  84. * Revision 1.16 1998/08/20 11:30:38 gklug
  85. * fix: SenRead declaration
  86. *
  87. * Revision 1.15 1998/08/20 11:27:53 gklug
  88. * fix: Compile bugs with new awrning constants
  89. *
  90. * Revision 1.14 1998/08/20 08:53:12 gklug
  91. * fix: compiler errors
  92. * add: Threshold values
  93. *
  94. * Revision 1.13 1998/08/19 12:21:16 gklug
  95. * fix: remove struct from C files (see CCC)
  96. * add: typedefs for all structs
  97. *
  98. * Revision 1.12 1998/08/19 10:57:41 gklug
  99. * add: Warning levels
  100. *
  101. * Revision 1.11 1998/08/18 08:37:02 malthoff
  102. * Prototypes not required for SK_DIAG.
  103. *
  104. * Revision 1.10 1998/08/17 13:54:00 gklug
  105. * fix: declaration of event function
  106. *
  107. * Revision 1.9 1998/08/17 06:48:39 malthoff
  108. * Remove some unrequired macros.
  109. * Fix the compiler errors.
  110. *
  111. * Revision 1.8 1998/08/14 06:47:19 gklug
  112. * fix: Values are intergers
  113. *
  114. * Revision 1.7 1998/08/14 06:26:05 gklug
  115. * add: Init error message
  116. *
  117. * Revision 1.6 1998/08/13 08:31:08 gklug
  118. * add: Error message
  119. *
  120. * Revision 1.5 1998/08/12 14:32:04 gklug
  121. * add: new error code/message
  122. *
  123. * Revision 1.4 1998/08/12 13:39:08 gklug
  124. * chg: names of error messages
  125. * add: defines for Sensor type and thresholds
  126. *
  127. * Revision 1.3 1998/08/11 07:57:16 gklug
  128. * add: sensor struct
  129. * add: Timeout defines
  130. * add: I2C control struct for pAC
  131. *
  132. * Revision 1.2 1998/07/17 11:29:02 gklug
  133. * rmv: Microwire and SMTPANIC
  134. *
  135. * Revision 1.1 1998/06/19 14:30:10 malthoff
  136. * Created. Sources taken from ML Project.
  137. *
  138. *
  139. ******************************************************************************/
  140. /*
  141. * SKI2C.H contains all I2C specific defines
  142. */
  143. #ifndef _SKI2C_H_
  144. #define _SKI2C_H_
  145. typedef struct s_Sensor SK_SENSOR;
  146. #include "h/skgei2c.h"
  147. /*
  148. * Define the I2C events.
  149. */
  150. #define SK_I2CEV_IRQ 1 /* IRQ happened Event */
  151. #define SK_I2CEV_TIM 2 /* Timeout event */
  152. #define SK_I2CEV_CLEAR 3 /* Clear MIB Values */
  153. /*
  154. * Define READ and WRITE Constants.
  155. */
  156. #undef I2C_READ /* just in case */
  157. #undef I2C_WRITE /* just in case */
  158. #define I2C_READ 0
  159. #define I2C_WRITE 1
  160. #define I2C_BURST 1
  161. #define I2C_SINGLE 0
  162. #define SKERR_I2C_E001 (SK_ERRBASE_I2C+0)
  163. #define SKERR_I2C_E001MSG "Sensor index unknown"
  164. #define SKERR_I2C_E002 (SKERR_I2C_E001+1)
  165. #define SKERR_I2C_E002MSG "TWSI: transfer does not complete"
  166. #define SKERR_I2C_E003 (SKERR_I2C_E002+1)
  167. #define SKERR_I2C_E003MSG "LM80: NAK on device send"
  168. #define SKERR_I2C_E004 (SKERR_I2C_E003+1)
  169. #define SKERR_I2C_E004MSG "LM80: NAK on register send"
  170. #define SKERR_I2C_E005 (SKERR_I2C_E004+1)
  171. #define SKERR_I2C_E005MSG "LM80: NAK on device (2) send"
  172. #define SKERR_I2C_E006 (SKERR_I2C_E005+1)
  173. #define SKERR_I2C_E006MSG "Unknown event"
  174. #define SKERR_I2C_E007 (SKERR_I2C_E006+1)
  175. #define SKERR_I2C_E007MSG "LM80 read out of state"
  176. #define SKERR_I2C_E008 (SKERR_I2C_E007+1)
  177. #define SKERR_I2C_E008MSG "Unexpected sensor read completed"
  178. #define SKERR_I2C_E009 (SKERR_I2C_E008+1)
  179. #define SKERR_I2C_E009MSG "WARNING: temperature sensor out of range"
  180. #define SKERR_I2C_E010 (SKERR_I2C_E009+1)
  181. #define SKERR_I2C_E010MSG "WARNING: voltage sensor out of range"
  182. #define SKERR_I2C_E011 (SKERR_I2C_E010+1)
  183. #define SKERR_I2C_E011MSG "ERROR: temperature sensor out of range"
  184. #define SKERR_I2C_E012 (SKERR_I2C_E011+1)
  185. #define SKERR_I2C_E012MSG "ERROR: voltage sensor out of range"
  186. #define SKERR_I2C_E013 (SKERR_I2C_E012+1)
  187. #define SKERR_I2C_E013MSG "ERROR: couldn't init sensor"
  188. #define SKERR_I2C_E014 (SKERR_I2C_E013+1)
  189. #define SKERR_I2C_E014MSG "WARNING: fan sensor out of range"
  190. #define SKERR_I2C_E015 (SKERR_I2C_E014+1)
  191. #define SKERR_I2C_E015MSG "ERROR: fan sensor out of range"
  192. #define SKERR_I2C_E016 (SKERR_I2C_E015+1)
  193. #define SKERR_I2C_E016MSG "TWSI: active transfer does not complete"
  194. /*
  195. * Define Timeout values
  196. */
  197. #define SK_I2C_TIM_LONG 2000000L /* 2 seconds */
  198. #define SK_I2C_TIM_SHORT 100000L /* 100 milliseconds */
  199. #define SK_I2C_TIM_WATCH 1000000L /* 1 second */
  200. /*
  201. * Define trap and error log hold times
  202. */
  203. #ifndef SK_SEN_ERR_TR_HOLD
  204. #define SK_SEN_ERR_TR_HOLD (4*SK_TICKS_PER_SEC)
  205. #endif
  206. #ifndef SK_SEN_ERR_LOG_HOLD
  207. #define SK_SEN_ERR_LOG_HOLD (60*SK_TICKS_PER_SEC)
  208. #endif
  209. #ifndef SK_SEN_WARN_TR_HOLD
  210. #define SK_SEN_WARN_TR_HOLD (15*SK_TICKS_PER_SEC)
  211. #endif
  212. #ifndef SK_SEN_WARN_LOG_HOLD
  213. #define SK_SEN_WARN_LOG_HOLD (15*60*SK_TICKS_PER_SEC)
  214. #endif
  215. /*
  216. * Defines for SenType
  217. */
  218. #define SK_SEN_UNKNOWN 0
  219. #define SK_SEN_TEMP 1
  220. #define SK_SEN_VOLT 2
  221. #define SK_SEN_FAN 3
  222. /*
  223. * Define for the SenErrorFlag
  224. */
  225. #define SK_SEN_ERR_NOT_PRESENT 0 /* Error Flag: Sensor not present */
  226. #define SK_SEN_ERR_OK 1 /* Error Flag: O.K. */
  227. #define SK_SEN_ERR_WARN 2 /* Error Flag: Warning */
  228. #define SK_SEN_ERR_ERR 3 /* Error Flag: Error */
  229. #define SK_SEN_ERR_FAULTY 4 /* Error Flag: Faulty */
  230. /*
  231. * Define the Sensor struct
  232. */
  233. struct s_Sensor {
  234. char *SenDesc; /* Description */
  235. int SenType; /* Voltage or Temperature */
  236. SK_I32 SenValue; /* Current value of the sensor */
  237. SK_I32 SenThreErrHigh; /* High error Threshhold of this sensor */
  238. SK_I32 SenThreWarnHigh; /* High warning Threshhold of this sensor */
  239. SK_I32 SenThreErrLow; /* Lower error Threshold of the sensor */
  240. SK_I32 SenThreWarnLow; /* Lower warning Threshold of the sensor */
  241. int SenErrFlag; /* Sensor indicated an error */
  242. SK_BOOL SenInit; /* Is sensor initialized ? */
  243. SK_U64 SenErrCts; /* Error trap counter */
  244. SK_U64 SenWarnCts; /* Warning trap counter */
  245. SK_U64 SenBegErrTS; /* Begin error timestamp */
  246. SK_U64 SenBegWarnTS; /* Begin warning timestamp */
  247. SK_U64 SenLastErrTrapTS; /* Last error trap timestamp */
  248. SK_U64 SenLastErrLogTS; /* Last error log timestamp */
  249. SK_U64 SenLastWarnTrapTS; /* Last warning trap timestamp */
  250. SK_U64 SenLastWarnLogTS; /* Last warning log timestamp */
  251. int SenState; /* Sensor State (see HW specific include) */
  252. int (*SenRead)(SK_AC *pAC, SK_IOC IoC, struct s_Sensor *pSen);
  253. /* Sensors read function */
  254. SK_U16 SenReg; /* Register Address for this sensor */
  255. SK_U8 SenDev; /* Device Selection for this sensor */
  256. };
  257. typedef struct s_I2c {
  258. SK_SENSOR SenTable[SK_MAX_SENSORS]; /* Sensor Table */
  259. int CurrSens; /* Which sensor is currently queried */
  260. int MaxSens; /* Max. number of sensors */
  261. int TimerMode; /* Use the timer also to watch the state machine */
  262. int InitLevel; /* Initialized Level */
  263. #ifndef SK_DIAG
  264. int DummyReads; /* Number of non-checked dummy reads */
  265. SK_TIMER SenTimer; /* Sensors timer */
  266. #endif /* !SK_DIAG */
  267. } SK_I2C;
  268. extern int SkI2cReadSensor(SK_AC *pAC, SK_IOC IoC, SK_SENSOR *pSen);
  269. #ifndef SK_DIAG
  270. extern int SkI2cEvent(SK_AC *pAC, SK_IOC IoC, SK_U32 Event, SK_EVPARA Para);
  271. extern int SkI2cInit(SK_AC *pAC, SK_IOC IoC, int Level);
  272. extern void SkI2cWaitIrq(SK_AC *pAC, SK_IOC IoC);
  273. extern void SkI2cIsr(SK_AC *pAC, SK_IOC IoC);
  274. #endif
  275. #endif /* n_SKI2C_H */