📄 ski2c.c
字号:
/****************************************************************************** * * Name: ski2c.c * Project: GEnesis, PCI Gigabit Ethernet Adapter * Version: $Revision: 1.1.1.1 $ * Date: $Date: 2005/06/27 17:05:02 $ * Purpose: Functions to access Voltage and Temperature Sensor * ******************************************************************************//****************************************************************************** * * (C)Copyright 1998-2003 SysKonnect GmbH. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The information in this file is provided "AS IS" without warranty. * ******************************************************************************//****************************************************************************** * * History: * * $Log: ski2c.c,v $ * Revision 1.1.1.1 2005/06/27 17:05:02 linuxpark * Initial import. * * Revision 1.57 2003/01/28 09:17:38 rschmidt * Fixed handling for sensors on YUKON Fiber. * Editorial changes. * * Revision 1.56 2002/12/19 14:20:41 rschmidt * Added debugging code in SkI2cWait(). * Replaced all I2C-write operations with function SkI2cWrite(). * Fixed compiler warning because of uninitialized 'Time' in SkI2cEvent(). * Editorial changes. * * Revision 1.55 2002/10/15 07:23:55 rschmidt * Added setting of the GIYukon32Bit bool variable to distinguish * 32-bit adapters. * Editorial changes (TWSI). * * Revision 1.54 2002/08/13 09:05:06 rschmidt * Added new thresholds if VAUX is not available (GIVauxAvail). * Merged defines for PHY PLL 3V3 voltage (A and B). * Editorial changes. * * Revision 1.53 2002/08/08 11:04:53 rwahl * Added missing comment for revision 1.51 * * Revision 1.52 2002/08/08 10:09:02 jschmalz * Sensor init state caused wrong error log entry * * Revision 1.51 2002/08/06 09:43:03 jschmalz * Extensions and changes for Yukon * * Revision 1.50 2002/08/02 12:09:22 rschmidt * Added support for YUKON sensors. * Editorial changes. * * Revision 1.49 2002/07/30 11:07:52 rschmidt * Replaced MaxSens init by update for Copper in SkI2cInit1(), * because it was already initialized in SkI2cInit0(). * Editorial changes. * * Revision 1.48 2001/08/16 12:44:33 afischer * LM80 sensor init values corrected * * Revision 1.47 2001/04/05 11:38:09 rassmann * Set SenState to idle in SkI2cWaitIrq(). * Changed error message in SkI2cWaitIrq(). * * Revision 1.46 2001/04/02 14:03:35 rassmann * Changed pAC to IoC in SK_IN32(). * * Revision 1.45 2001/03/21 12:12:49 rassmann * Resetting I2C_READY interrupt in SkI2cInit1(). * * Revision 1.44 2000/08/07 15:49:03 gklug * Fix: SK_INFAST only in NetWare driver. * * Revision 1.43 2000/08/03 14:28:17 rassmann * Added function to wait for I2C being ready before resetting the board. * Replaced one duplicate "out of range" message with correct one. * * Revision 1.42 1999/11/22 13:35:12 cgoos * Changed license header to GPL. * * Revision 1.41 1999/09/14 14:11:30 malthoff * The 1000BT Dual Link adapter has got only one Fan. * The second Fan has been removed. * * Revision 1.40 1999/05/27 13:37:27 malthoff * Set divisor of 1 for fan count calculation. * * Revision 1.39 1999/05/20 14:54:43 malthoff * I2c.DummyReads is not used in Diagnostics. * * Revision 1.38 1999/05/20 09:20:56 cgoos * Changes for 1000Base-T (up to 9 sensors and fans). * * Revision 1.37 1999/03/25 15:11:36 gklug * fix: reset error flag if sensor reads correct value * * Revision 1.36 1999/01/07 14:11:16 gklug * fix: break added * * Revision 1.35 1999/01/05 15:31:49 gklug * fix: CLEAR STAT command is now added correctly * * Revision 1.34 1998/12/01 13:45:16 gklug * fix: introduced Init level, because we don't need reinits * * Revision 1.33 1998/11/09 14:54:25 malthoff * Modify I2C Transfer Timeout handling for Diagnostics. * * Revision 1.32 1998/11/03 06:54:35 gklug * fix: Need dummy reads at the beginning to init sensors * * Revision 1.31 1998/11/03 06:42:42 gklug * fix: select correctVIO range only if between warning levels * * Revision 1.30 1998/11/02 07:36:53 gklug * fix: Error should not include WARNING message * * Revision 1.29 1998/10/30 15:07:43 malthoff * Disable 'I2C does not compelete' error log for diagnostics. * * Revision 1.28 1998/10/22 09:48:11 gklug * fix: SysKonnectFileId typo * * Revision 1.27 1998/10/20 09:59:46 gklug * add: parameter to SkOsGetTime * * Revision 1.26 1998/10/09 06:10:59 malthoff * Remove ID_sccs by SysKonnectFileId. * * Revision 1.25 1998/09/08 12:40:26 gklug * fix: syntax error in if clause * * Revision 1.24 1998/09/08 12:19:42 gklug * chg: INIT Level checking * * Revision 1.23 1998/09/08 07:37:20 gklug * fix: log error if PCI_IO voltage sensor could not be initialized * * Revision 1.22 1998/09/04 08:30:03 malthoff * Bugfixes during SK_DIAG testing: * - correct NS2BCLK() macro * - correct SkI2cSndDev() * - correct SkI2cWait() loop waiting for an event * * Revision 1.21 1998/08/27 14:46:01 gklug * chg: if-then-else replaced by switch * * Revision 1.20 1998/08/27 14:40:07 gklug * test: integral types * * Revision 1.19 1998/08/25 07:51:54 gklug * fix: typos for compiling * * Revision 1.18 1998/08/25 06:12:24 gklug * add: count errors and warnings * fix: check not the sensor state but the ErrFlag! * * Revision 1.17 1998/08/25 05:56:48 gklug * add: CheckSensor function * * Revision 1.16 1998/08/20 11:41:10 gklug * chg: omit STRCPY macro by using char * as Sensor Description * * Revision 1.15 1998/08/20 11:37:35 gklug * chg: change Ioc to IoC * * Revision 1.14 1998/08/20 11:32:52 gklug * fix: Para compile error * * Revision 1.13 1998/08/20 11:27:41 gklug * fix: Compile bugs with new awrning constants * * Revision 1.12 1998/08/20 08:53:05 gklug * fix: compiler errors * add: Threshold values * * Revision 1.11 1998/08/19 12:39:22 malthoff * Compiler Fix: Some names have changed. * * Revision 1.10 1998/08/19 12:20:56 gklug * fix: remove struct from C files (see CCC) * * Revision 1.9 1998/08/19 06:28:46 malthoff * SkOsGetTime returns SK_U64 now. * * Revision 1.8 1998/08/17 13:53:33 gklug * fix: Parameter of event function and its result * * Revision 1.7 1998/08/17 07:02:15 malthoff * Modify the functions for accessing the I2C SW Registers. * Modify SkI2cWait(). * Put Lm80RcvReg into sklm80.c * Remove Compiler Errors. * * Revision 1.6 1998/08/14 07:13:20 malthoff * remove pAc with pAC * remove smc with pAC * change names to new convention * * Revision 1.5 1998/08/14 06:24:49 gklug * add: init level 1 and 2 * * Revision 1.4 1998/08/12 14:31:12 gklug * add: error log for unknown event * * Revision 1.3 1998/08/12 13:37:04 gklug * add: Init 0 function * * Revision 1.2 1998/08/11 07:27:15 gklug * add: functions of the interface * adapt rest of source to C coding Conventions * rmv: unnecessary code taken from Mona Lisa * * Revision 1.1 1998/06/19 14:28:43 malthoff * Created. Sources taken from ML Projekt. * Sources have to be reworked for GE. * * ******************************************************************************/#include <config.h>#ifdef CONFIG_SK98/* * I2C Protocol */static const char SysKonnectFileId[] = "$Id: ski2c.c,v 1.1.1.1 2005/06/27 17:05:02 linuxpark Exp $";#include "h/skdrv1st.h" /* Driver Specific Definitions */#include "h/lm80.h"#include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */#ifdef __C2MAN__/* I2C protocol implementation. General Description: The I2C protocol is used for the temperature sensors and for the serial EEPROM which hold the configuration. This file covers functions that allow to read write and do some bulk requests a specified I2C address. The Genesis has 2 I2C buses. One for the EEPROM which holds the VPD Data and one for temperature and voltage sensor. The following picture shows the I2C buses, I2C devices and their control registers. Note: The VPD functions are in skvpd.c.. PCI Config I2C Bus for VPD Data:.. +------------+. | VPD EEPROM |. +------------+. |. | <-- I2C. |. +-----------+-----------+. | |. +-----------------+ +-----------------+. | PCI_VPD_ADR_REG | | PCI_VPD_DAT_REG |. +-----------------+ +-----------------+... I2C Bus for LM80 sensor:.. +-----------------+. | Temperature and |. | Voltage Sensor |. | LM80 |. +-----------------+. |. |. I2C --> |. |. +----+. +-------------->| OR |<--+. | +----+ |. +------+------+ |. | | |. +--------+ +--------+ +----------+. | B2_I2C | | B2_I2C | | B2_I2C |. | _CTRL | | _DATA | | _SW |. +--------+ +--------+ +----------+. The I2C bus may be driven by the B2_I2C_SW or by the B2_I2C_CTRL and B2_I2C_DATA registers. For driver software it is recommended to use the I2C control and data register, because I2C bus timing is done by the ASIC and an interrupt may be received when the I2C request is completed. Clock Rate Timing: MIN MAX generated by VPD EEPROM: 50 kHz 100 kHz HW LM80 over I2C Ctrl/Data reg. 50 kHz 100 kHz HW LM80 over B2_I2C_SW register 0 400 kHz SW Note: The clock generated by the hardware is dependend on the PCI clock. If the PCI bus clock is 33 MHz, the I2C/VPD clock is 50 kHz. */intro(){}#endif#ifdef SK_DIAG/* * I2C Fast Mode timing values used by the LM80. * If new devices are added to the I2C bus the timing values have to be checked. */#ifndef I2C_SLOW_TIMING#define T_CLK_LOW 1300L /* clock low time in ns */#define T_CLK_HIGH 600L /* clock high time in ns */#define T_DATA_IN_SETUP 100L /* data in Set-up Time */#define T_START_HOLD 600L /* start condition hold time */#define T_START_SETUP 600L /* start condition Set-up time */#define T_STOP_SETUP 600L /* stop condition Set-up time */#define T_BUS_IDLE 1300L /* time the bus must free after Tx */#define T_CLK_2_DATA_OUT 900L /* max. clock low to data output valid */#else /* I2C_SLOW_TIMING *//* I2C Standard Mode Timing */#define T_CLK_LOW 4700L /* clock low time in ns */#define T_CLK_HIGH 4000L /* clock high time in ns */#define T_DATA_IN_SETUP 250L /* data in Set-up Time */#define T_START_HOLD 4000L /* start condition hold time */#define T_START_SETUP 4700L /* start condition Set-up time */#define T_STOP_SETUP 4000L /* stop condition Set-up time */#define T_BUS_IDLE 4700L /* time the bus must free after Tx */#endif /* !I2C_SLOW_TIMING */#define NS2BCLK(x) (((x)*125)/10000)/* * I2C Wire Operations * * About I2C_CLK_LOW(): * * The Data Direction bit (I2C_DATA_DIR) has to be set to input when setting * clock to low, to prevent the ASIC and the I2C data client from driving the * serial data line simultaneously (ASIC: last bit of a byte = '1', I2C client * send an 'ACK'). See also Concentrator Bugreport No. 10192. */#define I2C_DATA_HIGH(IoC) SK_I2C_SET_BIT(IoC, I2C_DATA)#define I2C_DATA_LOW(IoC) SK_I2C_CLR_BIT(IoC, I2C_DATA)#define I2C_DATA_OUT(IoC) SK_I2C_SET_BIT(IoC, I2C_DATA_DIR)#define I2C_DATA_IN(IoC) SK_I2C_CLR_BIT(IoC, I2C_DATA_DIR | I2C_DATA)#define I2C_CLK_HIGH(IoC) SK_I2C_SET_BIT(IoC, I2C_CLK)#define I2C_CLK_LOW(IoC) SK_I2C_CLR_BIT(IoC, I2C_CLK | I2C_DATA_DIR)#define I2C_START_COND(IoC) SK_I2C_CLR_BIT(IoC, I2C_CLK)#define NS2CLKT(x) ((x*125L)/10000)/*--------------- I2C Interface Register Functions --------------- *//* * sending one bit */void SkI2cSndBit(SK_IOC IoC, /* I/O Context */SK_U8 Bit) /* Bit to send */{ I2C_DATA_OUT(IoC); if (Bit) { I2C_DATA_HIGH(IoC); } else { I2C_DATA_LOW(IoC); } SkDgWaitTime(IoC, NS2BCLK(T_DATA_IN_SETUP)); I2C_CLK_HIGH(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_HIGH)); I2C_CLK_LOW(IoC);} /* SkI2cSndBit*//* * Signal a start to the I2C Bus. * * A start is signaled when data goes to low in a high clock cycle. * * Ends with Clock Low. * * Status: not tested */void SkI2cStart(SK_IOC IoC) /* I/O Context */{ /* Init data and Clock to output lines */ /* Set Data high */ I2C_DATA_OUT(IoC); I2C_DATA_HIGH(IoC); /* Set Clock high */ I2C_CLK_HIGH(IoC); SkDgWaitTime(IoC, NS2BCLK(T_START_SETUP)); /* Set Data Low */ I2C_DATA_LOW(IoC); SkDgWaitTime(IoC, NS2BCLK(T_START_HOLD)); /* Clock low without Data to Input */ I2C_START_COND(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_LOW));} /* SkI2cStart */void SkI2cStop(SK_IOC IoC) /* I/O Context */{ /* Init data and Clock to output lines */ /* Set Data low */ I2C_DATA_OUT(IoC); I2C_DATA_LOW(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_2_DATA_OUT)); /* Set Clock high */ I2C_CLK_HIGH(IoC); SkDgWaitTime(IoC, NS2BCLK(T_STOP_SETUP)); /* * Set Data High: Do it by setting the Data Line to Input. * Because of a pull up resistor the Data Line * floods to high. */ I2C_DATA_IN(IoC); /* * When I2C activity is stopped * o DATA should be set to input and * o CLOCK should be set to high! */ SkDgWaitTime(IoC, NS2BCLK(T_BUS_IDLE));} /* SkI2cStop *//* * Receive just one bit via the I2C bus. * * Note: Clock must be set to LOW before calling this function. * * Returns The received bit. */int SkI2cRcvBit(SK_IOC IoC) /* I/O Context */{ int Bit; SK_U8 I2cSwCtrl; /* Init data as input line */ I2C_DATA_IN(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_2_DATA_OUT)); I2C_CLK_HIGH(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_HIGH)); SK_I2C_GET_SW(IoC, &I2cSwCtrl); Bit = (I2cSwCtrl & I2C_DATA) ? 1 : 0; I2C_CLK_LOW(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_LOW-T_CLK_2_DATA_OUT)); return(Bit);} /* SkI2cRcvBit *//* * Receive an ACK. * * returns 0 If acknowledged * 1 in case of an error */int SkI2cRcvAck(SK_IOC IoC) /* I/O Context */{ /* * Received bit must be zero. */ return(SkI2cRcvBit(IoC) != 0);} /* SkI2cRcvAck */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -