1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.20 $
6 * Date: $Date: 2002/08/13 09:16:27 $
7 * Purpose: Funktions to access Voltage and Temperature Sensor (LM80)
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * The information in this file is provided "AS IS" without warranty.
22 ******************************************************************************/
24 /******************************************************************************
29 * Revision 1.20 2002/08/13 09:16:27 rschmidt
30 * Changed return value for SkLm80ReadSensor() back to 'int'
33 * Revision 1.19 2002/08/06 09:43:31 jschmalz
34 * Extensions and changes for Yukon
36 * Revision 1.18 2002/08/02 12:26:57 rschmidt
39 * Revision 1.17 1999/11/22 13:35:51 cgoos
40 * Changed license header to GPL.
42 * Revision 1.16 1999/05/27 14:05:47 malthoff
43 * Fans: Set SenVal to 0 if the fan value is 0 or 0xff. Both values
44 * are outside the limits (0: div zero error, 0xff: value not in
47 * Revision 1.15 1999/05/27 13:38:51 malthoff
48 * Pervent from Division by zero errors.
50 * Revision 1.14 1999/05/20 09:20:01 cgoos
51 * Changes for 1000Base-T (Fan sensors).
53 * Revision 1.13 1998/10/22 09:48:14 gklug
54 * fix: SysKonnectFileId typo
56 * Revision 1.12 1998/10/09 06:12:06 malthoff
57 * Remove ID_sccs by SysKonnectFileId.
59 * Revision 1.11 1998/09/04 08:33:48 malthoff
60 * bug fix: SenState = SK_SEN_IDLE when
61 * leaving SK_SEN_VALEXT state
63 * Revision 1.10 1998/08/20 12:02:10 gklug
64 * fix: compiler warnings type mismatch
66 * Revision 1.9 1998/08/20 11:37:38 gklug
67 * chg: change Ioc to IoC
69 * Revision 1.8 1998/08/19 12:20:58 gklug
70 * fix: remove struct from C files (see CCC)
72 * Revision 1.7 1998/08/17 07:04:57 malthoff
73 * Take SkLm80RcvReg() function from ski2c.c.
74 * Add IoC parameter to BREAK_OR_WAIT() macro.
76 * Revision 1.6 1998/08/14 07:11:28 malthoff
77 * remove pAc with pAC.
79 * Revision 1.5 1998/08/14 06:46:55 gklug
80 * fix: temperature can get negative
82 * Revision 1.4 1998/08/13 08:27:04 gklug
83 * add: temperature reading now o.k.
84 * fix: pSen declaration, SK_ERR_LOG call, ADDR macro
86 * Revision 1.3 1998/08/13 07:28:21 gklug
87 * fix: pSen was wrong initialized
88 * add: correct conversion for voltage readings
90 * Revision 1.2 1998/08/11 07:52:14 gklug
91 * add: Lm80 read sensor function
93 * Revision 1.1 1998/07/17 09:57:12 gklug
98 ******************************************************************************/
104 static const char SysKonnectFileId[] =
105 "$Id: sklm80.c,v 1.20 2002/08/13 09:16:27 rschmidt Exp $" ;
107 #include "h/skdrv1st.h" /* Driver Specific Definitions */
109 #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
112 #define BREAK_OR_WAIT(pAC,IoC,Event) SkI2cWait(pAC,IoC,Event)
114 #define BREAK_OR_WAIT(pAC,IoC,Event) break
115 #endif /* nSK_DIAG */
119 * read the register 'Reg' from the device 'Dev'
121 * return read error -1
122 * success the read value
125 SK_IOC IoC, /* Adapter Context */
126 int Dev, /* I2C device address */
127 int Reg) /* register to read */
132 /* Signal device number */
133 if (SkI2cSndDev(IoC, Dev, I2C_WRITE)) {
137 if (SkI2cSndByte(IoC, Reg)) {
142 if (SkI2cSndDev(IoC, Dev, I2C_READ)) {
148 Val = (int)SkI2cRcvByte(IoC, 1);
150 /* First: correct the value: it might be negative */
151 if ((Val & 0x80) != 0) {
152 /* Value is negative */
155 Val = Val * SK_LM80_TEMP_LSB;
158 TempExt = (int)SkLm80RcvReg(IoC, LM80_ADDR, LM80_TEMP_CTRL);
161 Val += ((TempExt >> 7) * SK_LM80_TEMPEXT_LSB);
164 Val -= ((TempExt >> 7) * SK_LM80_TEMPEXT_LSB);
172 Val = (int)SkI2cRcvByte(IoC, 1) * SK_LM80_VT_LSB;
176 Val = (int)SkI2cRcvByte(IoC, 1);
186 * read a sensors value (LM80 specific)
188 * This function reads a sensors value from the I2C sensor chip LM80.
189 * The sensor is defined by its index into the sensors database in the struct
192 * Returns 1 if the read is completed
193 * 0 if the read must be continued (I2C Bus still allocated)
195 int SkLm80ReadSensor(
196 SK_AC *pAC, /* Adapter Context */
197 SK_IOC IoC, /* I/O Context needed in level 1 and 2 */
198 SK_SENSOR *pSen) /* Sensor to be read */
202 switch (pSen->SenState) {
204 /* Send address to ADDR register */
205 SK_I2C_CTL(IoC, I2C_READ, pSen->SenDev, pSen->SenReg, 0);
207 pSen->SenState = SK_SEN_VALUE ;
208 BREAK_OR_WAIT(pAC, IoC, I2C_READ);
211 /* Read value from data register */
212 SK_IN32(IoC, B2_I2C_DATA, ((SK_U32 *)&Value));
214 Value &= 0xff; /* only least significant byte is valid */
216 /* Do NOT check the Value against the thresholds */
217 /* Checking is done in the calling instance */
219 if (pSen->SenType == SK_SEN_VOLT) {
221 pSen->SenValue = Value * SK_LM80_VT_LSB;
222 pSen->SenState = SK_SEN_IDLE ;
226 if (pSen->SenType == SK_SEN_FAN) {
227 if (Value != 0 && Value != 0xff) {
228 /* Fan speed counter */
229 pSen->SenValue = SK_LM80_FAN_FAKTOR/Value;
232 /* Indicate Fan error */
235 pSen->SenState = SK_SEN_IDLE ;
239 /* First: correct the value: it might be negative */
240 if ((Value & 0x80) != 0) {
241 /* Value is negative */
245 /* We have a temperature sensor and need to get the signed extension.
246 * For now we get the extension from the last reading, so in the normal
247 * case we won't see flickering temperatures.
249 pSen->SenValue = (Value * SK_LM80_TEMP_LSB) +
250 (pSen->SenValue % SK_LM80_TEMP_LSB);
252 /* Send address to ADDR register */
253 SK_I2C_CTL(IoC, I2C_READ, pSen->SenDev, LM80_TEMP_CTRL, 0);
255 pSen->SenState = SK_SEN_VALEXT ;
256 BREAK_OR_WAIT(pAC, IoC, I2C_READ);
259 /* Read value from data register */
260 SK_IN32(IoC, B2_I2C_DATA, ((SK_U32 *)&Value));
261 Value &= LM80_TEMP_LSB_9; /* only bit 7 is valid */
263 /* cut the LSB bit */
264 pSen->SenValue = ((pSen->SenValue / SK_LM80_TEMP_LSB) *
267 if (pSen->SenValue < 0) {
268 /* Value negative: The bit value must be subtracted */
269 pSen->SenValue -= ((Value >> 7) * SK_LM80_TEMPEXT_LSB);
272 /* Value positive: The bit value must be added */
273 pSen->SenValue += ((Value >> 7) * SK_LM80_TEMPEXT_LSB);
276 pSen->SenState = SK_SEN_IDLE ;
280 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E007, SKERR_I2C_E007MSG);