ski2c.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /******************************************************************************
  2. *
  3. * Name: ski2c.c
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.57 $
  6. * Date: $Date: 2003/01/28 09:17:38 $
  7. * Purpose: Functions 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.c,v $
  27. * Revision 1.57 2003/01/28 09:17:38 rschmidt
  28. * Fixed handling for sensors on YUKON Fiber.
  29. * Editorial changes.
  30. *
  31. * Revision 1.56 2002/12/19 14:20:41 rschmidt
  32. * Added debugging code in SkI2cWait().
  33. * Replaced all I2C-write operations with function SkI2cWrite().
  34. * Fixed compiler warning because of uninitialized 'Time' in SkI2cEvent().
  35. * Editorial changes.
  36. *
  37. * Revision 1.55 2002/10/15 07:23:55 rschmidt
  38. * Added setting of the GIYukon32Bit bool variable to distinguish
  39. * 32-bit adapters.
  40. * Editorial changes (TWSI).
  41. *
  42. * Revision 1.54 2002/08/13 09:05:06 rschmidt
  43. * Added new thresholds if VAUX is not available (GIVauxAvail).
  44. * Merged defines for PHY PLL 3V3 voltage (A and B).
  45. * Editorial changes.
  46. *
  47. * Revision 1.53 2002/08/08 11:04:53 rwahl
  48. * Added missing comment for revision 1.51
  49. *
  50. * Revision 1.52 2002/08/08 10:09:02 jschmalz
  51. * Sensor init state caused wrong error log entry
  52. *
  53. * Revision 1.51 2002/08/06 09:43:03 jschmalz
  54. * Extensions and changes for Yukon
  55. *
  56. * Revision 1.50 2002/08/02 12:09:22 rschmidt
  57. * Added support for YUKON sensors.
  58. * Editorial changes.
  59. *
  60. * Revision 1.49 2002/07/30 11:07:52 rschmidt
  61. * Replaced MaxSens init by update for Copper in SkI2cInit1(),
  62. * because it was already initialized in SkI2cInit0().
  63. * Editorial changes.
  64. *
  65. * Revision 1.48 2001/08/16 12:44:33 afischer
  66. * LM80 sensor init values corrected
  67. *
  68. * Revision 1.47 2001/04/05 11:38:09 rassmann
  69. * Set SenState to idle in SkI2cWaitIrq().
  70. * Changed error message in SkI2cWaitIrq().
  71. *
  72. * Revision 1.46 2001/04/02 14:03:35 rassmann
  73. * Changed pAC to IoC in SK_IN32().
  74. *
  75. * Revision 1.45 2001/03/21 12:12:49 rassmann
  76. * Resetting I2C_READY interrupt in SkI2cInit1().
  77. *
  78. * Revision 1.44 2000/08/07 15:49:03 gklug
  79. * Fix: SK_INFAST only in NetWare driver.
  80. *
  81. * Revision 1.43 2000/08/03 14:28:17 rassmann
  82. * Added function to wait for I2C being ready before resetting the board.
  83. * Replaced one duplicate "out of range" message with correct one.
  84. *
  85. * Revision 1.42 1999/11/22 13:35:12 cgoos
  86. * Changed license header to GPL.
  87. *
  88. * Revision 1.41 1999/09/14 14:11:30 malthoff
  89. * The 1000BT Dual Link adapter has got only one Fan.
  90. * The second Fan has been removed.
  91. *
  92. * Revision 1.40 1999/05/27 13:37:27 malthoff
  93. * Set divisor of 1 for fan count calculation.
  94. *
  95. * Revision 1.39 1999/05/20 14:54:43 malthoff
  96. * I2c.DummyReads is not used in Diagnostics.
  97. *
  98. * Revision 1.38 1999/05/20 09:20:56 cgoos
  99. * Changes for 1000Base-T (up to 9 sensors and fans).
  100. *
  101. * Revision 1.37 1999/03/25 15:11:36 gklug
  102. * fix: reset error flag if sensor reads correct value
  103. *
  104. * Revision 1.36 1999/01/07 14:11:16 gklug
  105. * fix: break added
  106. *
  107. * Revision 1.35 1999/01/05 15:31:49 gklug
  108. * fix: CLEAR STAT command is now added correctly
  109. *
  110. * Revision 1.34 1998/12/01 13:45:16 gklug
  111. * fix: introduced Init level, because we don't need reinits
  112. *
  113. * Revision 1.33 1998/11/09 14:54:25 malthoff
  114. * Modify I2C Transfer Timeout handling for Diagnostics.
  115. *
  116. * Revision 1.32 1998/11/03 06:54:35 gklug
  117. * fix: Need dummy reads at the beginning to init sensors
  118. *
  119. * Revision 1.31 1998/11/03 06:42:42 gklug
  120. * fix: select correctVIO range only if between warning levels
  121. *
  122. * Revision 1.30 1998/11/02 07:36:53 gklug
  123. * fix: Error should not include WARNING message
  124. *
  125. * Revision 1.29 1998/10/30 15:07:43 malthoff
  126. * Disable 'I2C does not compelete' error log for diagnostics.
  127. *
  128. * Revision 1.28 1998/10/22 09:48:11 gklug
  129. * fix: SysKonnectFileId typo
  130. *
  131. * Revision 1.27 1998/10/20 09:59:46 gklug
  132. * add: parameter to SkOsGetTime
  133. *
  134. * Revision 1.26 1998/10/09 06:10:59 malthoff
  135. * Remove ID_sccs by SysKonnectFileId.
  136. *
  137. * Revision 1.25 1998/09/08 12:40:26 gklug
  138. * fix: syntax error in if clause
  139. *
  140. * Revision 1.24 1998/09/08 12:19:42 gklug
  141. * chg: INIT Level checking
  142. *
  143. * Revision 1.23 1998/09/08 07:37:20 gklug
  144. * fix: log error if PCI_IO voltage sensor could not be initialized
  145. *
  146. * Revision 1.22 1998/09/04 08:30:03 malthoff
  147. * Bugfixes during SK_DIAG testing:
  148. * - correct NS2BCLK() macro
  149. * - correct SkI2cSndDev()
  150. * - correct SkI2cWait() loop waiting for an event
  151. *
  152. * Revision 1.21 1998/08/27 14:46:01 gklug
  153. * chg: if-then-else replaced by switch
  154. *
  155. * Revision 1.20 1998/08/27 14:40:07 gklug
  156. * test: integral types
  157. *
  158. * Revision 1.19 1998/08/25 07:51:54 gklug
  159. * fix: typos for compiling
  160. *
  161. * Revision 1.18 1998/08/25 06:12:24 gklug
  162. * add: count errors and warnings
  163. * fix: check not the sensor state but the ErrFlag!
  164. *
  165. * Revision 1.17 1998/08/25 05:56:48 gklug
  166. * add: CheckSensor function
  167. *
  168. * Revision 1.16 1998/08/20 11:41:10 gklug
  169. * chg: omit STRCPY macro by using char * as Sensor Description
  170. *
  171. * Revision 1.15 1998/08/20 11:37:35 gklug
  172. * chg: change Ioc to IoC
  173. *
  174. * Revision 1.14 1998/08/20 11:32:52 gklug
  175. * fix: Para compile error
  176. *
  177. * Revision 1.13 1998/08/20 11:27:41 gklug
  178. * fix: Compile bugs with new awrning constants
  179. *
  180. * Revision 1.12 1998/08/20 08:53:05 gklug
  181. * fix: compiler errors
  182. * add: Threshold values
  183. *
  184. * Revision 1.11 1998/08/19 12:39:22 malthoff
  185. * Compiler Fix: Some names have changed.
  186. *
  187. * Revision 1.10 1998/08/19 12:20:56 gklug
  188. * fix: remove struct from C files (see CCC)
  189. *
  190. * Revision 1.9 1998/08/19 06:28:46 malthoff
  191. * SkOsGetTime returns SK_U64 now.
  192. *
  193. * Revision 1.8 1998/08/17 13:53:33 gklug
  194. * fix: Parameter of event function and its result
  195. *
  196. * Revision 1.7 1998/08/17 07:02:15 malthoff
  197. * Modify the functions for accessing the I2C SW Registers.
  198. * Modify SkI2cWait().
  199. * Put Lm80RcvReg into sklm80.c
  200. * Remove Compiler Errors.
  201. *
  202. * Revision 1.6 1998/08/14 07:13:20 malthoff
  203. * remove pAc with pAC
  204. * remove smc with pAC
  205. * change names to new convention
  206. *
  207. * Revision 1.5 1998/08/14 06:24:49 gklug
  208. * add: init level 1 and 2
  209. *
  210. * Revision 1.4 1998/08/12 14:31:12 gklug
  211. * add: error log for unknown event
  212. *
  213. * Revision 1.3 1998/08/12 13:37:04 gklug
  214. * add: Init 0 function
  215. *
  216. * Revision 1.2 1998/08/11 07:27:15 gklug
  217. * add: functions of the interface
  218. * adapt rest of source to C coding Conventions
  219. * rmv: unnecessary code taken from Mona Lisa
  220. *
  221. * Revision 1.1 1998/06/19 14:28:43 malthoff
  222. * Created. Sources taken from ML Projekt.
  223. * Sources have to be reworked for GE.
  224. *
  225. *
  226. ******************************************************************************/
  227. #include <config.h>
  228. #ifdef CONFIG_SK98
  229. /*
  230. * I2C Protocol
  231. */
  232. static const char SysKonnectFileId[] =
  233. "$Id: ski2c.c,v 1.57 2003/01/28 09:17:38 rschmidt Exp $";
  234. #include "h/skdrv1st.h" /* Driver Specific Definitions */
  235. #include "h/lm80.h"
  236. #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
  237. #ifdef __C2MAN__
  238. /*
  239. I2C protocol implementation.
  240. General Description:
  241. The I2C protocol is used for the temperature sensors and for
  242. the serial EEPROM which hold the configuration.
  243. This file covers functions that allow to read write and do
  244. some bulk requests a specified I2C address.
  245. The Genesis has 2 I2C buses. One for the EEPROM which holds
  246. the VPD Data and one for temperature and voltage sensor.
  247. The following picture shows the I2C buses, I2C devices and
  248. their control registers.
  249. Note: The VPD functions are in skvpd.c
  250. .
  251. . PCI Config I2C Bus for VPD Data:
  252. .
  253. . +------------+
  254. . | VPD EEPROM |
  255. . +------------+
  256. . |
  257. . | <-- I2C
  258. . |
  259. . +-----------+-----------+
  260. . | |
  261. . +-----------------+ +-----------------+
  262. . | PCI_VPD_ADR_REG | | PCI_VPD_DAT_REG |
  263. . +-----------------+ +-----------------+
  264. .
  265. .
  266. . I2C Bus for LM80 sensor:
  267. .
  268. . +-----------------+
  269. . | Temperature and |
  270. . | Voltage Sensor |
  271. . | LM80 |
  272. . +-----------------+
  273. . |
  274. . |
  275. . I2C --> |
  276. . |
  277. . +----+
  278. . +-------------->| OR |<--+
  279. . | +----+ |
  280. . +------+------+ |
  281. . | | |
  282. . +--------+ +--------+ +----------+
  283. . | B2_I2C | | B2_I2C | | B2_I2C |
  284. . | _CTRL | | _DATA | | _SW |
  285. . +--------+ +--------+ +----------+
  286. .
  287. The I2C bus may be driven by the B2_I2C_SW or by the B2_I2C_CTRL
  288. and B2_I2C_DATA registers.
  289. For driver software it is recommended to use the I2C control and
  290. data register, because I2C bus timing is done by the ASIC and
  291. an interrupt may be received when the I2C request is completed.
  292. Clock Rate Timing: MIN MAX generated by
  293. VPD EEPROM: 50 kHz 100 kHz HW
  294. LM80 over I2C Ctrl/Data reg. 50 kHz 100 kHz HW
  295. LM80 over B2_I2C_SW register 0 400 kHz SW
  296. Note: The clock generated by the hardware is dependend on the
  297. PCI clock. If the PCI bus clock is 33 MHz, the I2C/VPD
  298. clock is 50 kHz.
  299. */
  300. intro()
  301. {}
  302. #endif
  303. #ifdef SK_DIAG
  304. /*
  305. * I2C Fast Mode timing values used by the LM80.
  306. * If new devices are added to the I2C bus the timing values have to be checked.
  307. */
  308. #ifndef I2C_SLOW_TIMING
  309. #define T_CLK_LOW 1300L /* clock low time in ns */
  310. #define T_CLK_HIGH 600L /* clock high time in ns */
  311. #define T_DATA_IN_SETUP 100L /* data in Set-up Time */
  312. #define T_START_HOLD 600L /* start condition hold time */
  313. #define T_START_SETUP 600L /* start condition Set-up time */
  314. #define T_STOP_SETUP 600L /* stop condition Set-up time */
  315. #define T_BUS_IDLE 1300L /* time the bus must free after Tx */
  316. #define T_CLK_2_DATA_OUT 900L /* max. clock low to data output valid */
  317. #else /* I2C_SLOW_TIMING */
  318. /* I2C Standard Mode Timing */
  319. #define T_CLK_LOW 4700L /* clock low time in ns */
  320. #define T_CLK_HIGH 4000L /* clock high time in ns */
  321. #define T_DATA_IN_SETUP 250L /* data in Set-up Time */
  322. #define T_START_HOLD 4000L /* start condition hold time */
  323. #define T_START_SETUP 4700L /* start condition Set-up time */
  324. #define T_STOP_SETUP 4000L /* stop condition Set-up time */
  325. #define T_BUS_IDLE 4700L /* time the bus must free after Tx */
  326. #endif /* !I2C_SLOW_TIMING */
  327. #define NS2BCLK(x) (((x)*125)/10000)
  328. /*
  329. * I2C Wire Operations
  330. *
  331. * About I2C_CLK_LOW():
  332. *
  333. * The Data Direction bit (I2C_DATA_DIR) has to be set to input when setting
  334. * clock to low, to prevent the ASIC and the I2C data client from driving the
  335. * serial data line simultaneously (ASIC: last bit of a byte = '1', I2C client
  336. * send an 'ACK'). See also Concentrator Bugreport No. 10192.
  337. */
  338. #define I2C_DATA_HIGH(IoC) SK_I2C_SET_BIT(IoC, I2C_DATA)
  339. #define I2C_DATA_LOW(IoC) SK_I2C_CLR_BIT(IoC, I2C_DATA)
  340. #define I2C_DATA_OUT(IoC) SK_I2C_SET_BIT(IoC, I2C_DATA_DIR)
  341. #define I2C_DATA_IN(IoC) SK_I2C_CLR_BIT(IoC, I2C_DATA_DIR | I2C_DATA)
  342. #define I2C_CLK_HIGH(IoC) SK_I2C_SET_BIT(IoC, I2C_CLK)
  343. #define I2C_CLK_LOW(IoC) SK_I2C_CLR_BIT(IoC, I2C_CLK | I2C_DATA_DIR)
  344. #define I2C_START_COND(IoC) SK_I2C_CLR_BIT(IoC, I2C_CLK)
  345. #define NS2CLKT(x) ((x*125L)/10000)
  346. /*--------------- I2C Interface Register Functions --------------- */
  347. /*
  348. * sending one bit
  349. */
  350. void SkI2cSndBit(
  351. SK_IOC IoC, /* I/O Context */
  352. SK_U8 Bit) /* Bit to send */
  353. {
  354. I2C_DATA_OUT(IoC);
  355. if (Bit) {
  356. I2C_DATA_HIGH(IoC);
  357. }
  358. else {
  359. I2C_DATA_LOW(IoC);
  360. }
  361. SkDgWaitTime(IoC, NS2BCLK(T_DATA_IN_SETUP));
  362. I2C_CLK_HIGH(IoC);
  363. SkDgWaitTime(IoC, NS2BCLK(T_CLK_HIGH));
  364. I2C_CLK_LOW(IoC);
  365. } /* SkI2cSndBit*/
  366. /*
  367. * Signal a start to the I2C Bus.
  368. *
  369. * A start is signaled when data goes to low in a high clock cycle.
  370. *
  371. * Ends with Clock Low.
  372. *
  373. * Status: not tested
  374. */
  375. void SkI2cStart(
  376. SK_IOC IoC) /* I/O Context */
  377. {
  378. /* Init data and Clock to output lines */
  379. /* Set Data high */
  380. I2C_DATA_OUT(IoC);
  381. I2C_DATA_HIGH(IoC);
  382. /* Set Clock high */
  383. I2C_CLK_HIGH(IoC);
  384. SkDgWaitTime(IoC, NS2BCLK(T_START_SETUP));
  385. /* Set Data Low */
  386. I2C_DATA_LOW(IoC);
  387. SkDgWaitTime(IoC, NS2BCLK(T_START_HOLD));
  388. /* Clock low without Data to Input */
  389. I2C_START_COND(IoC);
  390. SkDgWaitTime(IoC, NS2BCLK(T_CLK_LOW));
  391. } /* SkI2cStart */
  392. void SkI2cStop(
  393. SK_IOC IoC) /* I/O Context */
  394. {
  395. /* Init data and Clock to output lines */
  396. /* Set Data low */
  397. I2C_DATA_OUT(IoC);
  398. I2C_DATA_LOW(IoC);
  399. SkDgWaitTime(IoC, NS2BCLK(T_CLK_2_DATA_OUT));
  400. /* Set Clock high */
  401. I2C_CLK_HIGH(IoC);
  402. SkDgWaitTime(IoC, NS2BCLK(T_STOP_SETUP));
  403. /*
  404. * Set Data High: Do it by setting the Data Line to Input.
  405. * Because of a pull up resistor the Data Line
  406. * floods to high.
  407. */
  408. I2C_DATA_IN(IoC);
  409. /*
  410. * When I2C activity is stopped
  411. * o DATA should be set to input and
  412. * o CLOCK should be set to high!
  413. */
  414. SkDgWaitTime(IoC, NS2BCLK(T_BUS_IDLE));
  415. } /* SkI2cStop */
  416. /*
  417. * Receive just one bit via the I2C bus.
  418. *
  419. * Note: Clock must be set to LOW before calling this function.
  420. *
  421. * Returns The received bit.
  422. */
  423. int SkI2cRcvBit(
  424. SK_IOC IoC) /* I/O Context */
  425. {
  426. int Bit;
  427. SK_U8 I2cSwCtrl;
  428. /* Init data as input line */
  429. I2C_DATA_IN(IoC);
  430. SkDgWaitTime(IoC, NS2BCLK(T_CLK_2_DATA_OUT));
  431. I2C_CLK_HIGH(IoC);
  432. SkDgWaitTime(IoC, NS2BCLK(T_CLK_HIGH));
  433. SK_I2C_GET_SW(IoC, &I2cSwCtrl);
  434. Bit = (I2cSwCtrl & I2C_DATA) ? 1 : 0;
  435. I2C_CLK_LOW(IoC);
  436. SkDgWaitTime(IoC, NS2BCLK(T_CLK_LOW-T_CLK_2_DATA_OUT));
  437. return(Bit);
  438. } /* SkI2cRcvBit */
  439. /*
  440. * Receive an ACK.
  441. *
  442. * returns 0 If acknowledged
  443. * 1 in case of an error
  444. */
  445. int SkI2cRcvAck(
  446. SK_IOC IoC) /* I/O Context */
  447. {
  448. /*
  449. * Received bit must be zero.
  450. */
  451. return(SkI2cRcvBit(IoC) != 0);
  452. } /* SkI2cRcvAck */
  453. /*
  454. * Send an NACK.
  455. */
  456. void SkI2cSndNAck(
  457. SK_IOC IoC) /* I/O Context */
  458. {
  459. /*
  460. * Received bit must be zero.
  461. */
  462. SkI2cSndBit(IoC, 1);
  463. } /* SkI2cSndNAck */
  464. /*
  465. * Send an ACK.
  466. */
  467. void SkI2cSndAck(
  468. SK_IOC IoC) /* I/O Context */
  469. {
  470. /*
  471. * Received bit must be zero.
  472. *
  473. */
  474. SkI2cSndBit(IoC, 0);
  475. } /* SkI2cSndAck */
  476. /*
  477. * Send one byte to the I2C device and wait for ACK.
  478. *
  479. * Return acknowleged status.
  480. */
  481. int SkI2cSndByte(
  482. SK_IOC IoC, /* I/O Context */
  483. int Byte) /* byte to send */
  484. {
  485. int i;
  486. for (i = 0; i < 8; i++) {
  487. if (Byte & (1<<(7-i))) {
  488. SkI2cSndBit(IoC, 1);
  489. }
  490. else {
  491. SkI2cSndBit(IoC, 0);
  492. }
  493. }
  494. return(SkI2cRcvAck(IoC));
  495. } /* SkI2cSndByte */
  496. /*
  497. * Receive one byte and ack it.
  498. *
  499. * Return byte.
  500. */
  501. int SkI2cRcvByte(
  502. SK_IOC IoC, /* I/O Context */
  503. int Last) /* Last Byte Flag */
  504. {
  505. int i;
  506. int Byte = 0;
  507. for (i = 0; i < 8; i++) {
  508. Byte <<= 1;
  509. Byte |= SkI2cRcvBit(IoC);
  510. }
  511. if (Last) {
  512. SkI2cSndNAck(IoC);
  513. }
  514. else {
  515. SkI2cSndAck(IoC);
  516. }
  517. return(Byte);
  518. } /* SkI2cRcvByte */
  519. /*
  520. * Start dialog and send device address
  521. *
  522. * Return 0 if acknowleged, 1 in case of an error
  523. */
  524. int SkI2cSndDev(
  525. SK_IOC IoC, /* I/O Context */
  526. int Addr, /* Device Address */
  527. int Rw) /* Read / Write Flag */
  528. {
  529. SkI2cStart(IoC);
  530. Rw = ~Rw;
  531. Rw &= I2C_WRITE;
  532. return(SkI2cSndByte(IoC, (Addr<<1) | Rw));
  533. } /* SkI2cSndDev */
  534. #endif /* SK_DIAG */
  535. /*----------------- I2C CTRL Register Functions ----------*/
  536. /*
  537. * waits for a completion of an I2C transfer
  538. *
  539. * returns 0: success, transfer completes
  540. * 1: error, transfer does not complete, I2C transfer
  541. * killed, wait loop terminated.
  542. */
  543. int SkI2cWait(
  544. SK_AC *pAC, /* Adapter Context */
  545. SK_IOC IoC, /* I/O Context */
  546. int Event) /* complete event to wait for (I2C_READ or I2C_WRITE) */
  547. {
  548. SK_U64 StartTime;
  549. SK_U64 CurrentTime;
  550. SK_U32 I2cCtrl;
  551. StartTime = SkOsGetTime(pAC);
  552. do {
  553. CurrentTime = SkOsGetTime(pAC);
  554. if (CurrentTime - StartTime > SK_TICKS_PER_SEC / 8) {
  555. SK_I2C_STOP(IoC);
  556. #ifndef SK_DIAG
  557. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E002, SKERR_I2C_E002MSG);
  558. #endif /* !SK_DIAG */
  559. return(1);
  560. }
  561. SK_I2C_GET_CTL(IoC, &I2cCtrl);
  562. #ifdef xYUKON_DBG
  563. printf("StartTime=%lu, CurrentTime=%lu\n",
  564. StartTime, CurrentTime);
  565. if (kbhit()) {
  566. return(1);
  567. }
  568. #endif /* YUKON_DBG */
  569. } while ((I2cCtrl & I2C_FLAG) == (SK_U32)Event << 31);
  570. return(0);
  571. } /* SkI2cWait */
  572. /*
  573. * waits for a completion of an I2C transfer
  574. *
  575. * Returns
  576. * Nothing
  577. */
  578. void SkI2cWaitIrq(
  579. SK_AC *pAC, /* Adapter Context */
  580. SK_IOC IoC) /* I/O Context */
  581. {
  582. SK_SENSOR *pSen;
  583. SK_U64 StartTime;
  584. SK_U32 IrqSrc;
  585. pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
  586. if (pSen->SenState == SK_SEN_IDLE) {
  587. return;
  588. }
  589. StartTime = SkOsGetTime(pAC);
  590. do {
  591. if (SkOsGetTime(pAC) - StartTime > SK_TICKS_PER_SEC / 8) {
  592. SK_I2C_STOP(IoC);
  593. #ifndef SK_DIAG
  594. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E016, SKERR_I2C_E016MSG);
  595. #endif /* !SK_DIAG */
  596. return;
  597. }
  598. SK_IN32(IoC, B0_ISRC, &IrqSrc);
  599. } while ((IrqSrc & IS_I2C_READY) == 0);
  600. pSen->SenState = SK_SEN_IDLE;
  601. return;
  602. } /* SkI2cWaitIrq */
  603. /*
  604. * writes a single byte or 4 bytes into the I2C device
  605. *
  606. * returns 0: success
  607. * 1: error
  608. */
  609. int SkI2cWrite(
  610. SK_AC *pAC, /* Adapter Context */
  611. SK_IOC IoC, /* I/O Context */
  612. SK_U32 I2cData, /* I2C Data to write */
  613. int I2cDev, /* I2C Device Address */
  614. int I2cReg, /* I2C Device Register Address */
  615. int I2cBurst) /* I2C Burst Flag */
  616. {
  617. SK_OUT32(IoC, B2_I2C_DATA, I2cData);
  618. SK_I2C_CTL(IoC, I2C_WRITE, I2cDev, I2cReg, I2cBurst);
  619. return(SkI2cWait(pAC, IoC, I2C_WRITE));
  620. } /* SkI2cWrite*/
  621. #ifdef SK_DIAG
  622. /*
  623. * reads a single byte or 4 bytes from the I2C device
  624. *
  625. * returns the word read
  626. */
  627. SK_U32 SkI2cRead(
  628. SK_AC *pAC, /* Adapter Context */
  629. SK_IOC IoC, /* I/O Context */
  630. int I2cDev, /* I2C Device Address */
  631. int I2cReg, /* I2C Device Register Address */
  632. int I2cBurst) /* I2C Burst Flag */
  633. {
  634. SK_U32 Data;
  635. SK_OUT32(IoC, B2_I2C_DATA, 0);
  636. SK_I2C_CTL(IoC, I2C_READ, I2cDev, I2cReg, I2cBurst);
  637. if (SkI2cWait(pAC, IoC, I2C_READ) != 0) {
  638. w_print("%s\n", SKERR_I2C_E002MSG);
  639. }
  640. SK_IN32(IoC, B2_I2C_DATA, &Data);
  641. return(Data);
  642. } /* SkI2cRead */
  643. #endif /* SK_DIAG */
  644. /*
  645. * read a sensor's value
  646. *
  647. * This function reads a sensor's value from the I2C sensor chip. The sensor
  648. * is defined by its index into the sensors database in the struct pAC points
  649. * to.
  650. * Returns
  651. * 1 if the read is completed
  652. * 0 if the read must be continued (I2C Bus still allocated)
  653. */
  654. int SkI2cReadSensor(
  655. SK_AC *pAC, /* Adapter Context */
  656. SK_IOC IoC, /* I/O Context */
  657. SK_SENSOR *pSen) /* Sensor to be read */
  658. {
  659. if (pSen->SenRead != NULL) {
  660. return((*pSen->SenRead)(pAC, IoC, pSen));
  661. }
  662. else
  663. return(0); /* no success */
  664. } /* SkI2cReadSensor*/
  665. /*
  666. * Do the Init state 0 initialization
  667. */
  668. static int SkI2cInit0(
  669. SK_AC *pAC) /* Adapter Context */
  670. {
  671. int i;
  672. /* Begin with first sensor */
  673. pAC->I2c.CurrSens = 0;
  674. /* Begin with timeout control for state machine */
  675. pAC->I2c.TimerMode = SK_TIMER_WATCH_STATEMACHINE;
  676. /* Set sensor number to zero */
  677. pAC->I2c.MaxSens = 0;
  678. #ifndef SK_DIAG
  679. /* Initialize Number of Dummy Reads */
  680. pAC->I2c.DummyReads = SK_MAX_SENSORS;
  681. #endif
  682. for (i = 0; i < SK_MAX_SENSORS; i++) {
  683. pAC->I2c.SenTable[i].SenDesc = "unknown";
  684. pAC->I2c.SenTable[i].SenType = SK_SEN_UNKNOWN;
  685. pAC->I2c.SenTable[i].SenThreErrHigh = 0;
  686. pAC->I2c.SenTable[i].SenThreErrLow = 0;
  687. pAC->I2c.SenTable[i].SenThreWarnHigh = 0;
  688. pAC->I2c.SenTable[i].SenThreWarnLow = 0;
  689. pAC->I2c.SenTable[i].SenReg = LM80_FAN2_IN;
  690. pAC->I2c.SenTable[i].SenInit = SK_SEN_DYN_INIT_NONE;
  691. pAC->I2c.SenTable[i].SenValue = 0;
  692. pAC->I2c.SenTable[i].SenErrFlag = SK_SEN_ERR_NOT_PRESENT;
  693. pAC->I2c.SenTable[i].SenErrCts = 0;
  694. pAC->I2c.SenTable[i].SenBegErrTS = 0;
  695. pAC->I2c.SenTable[i].SenState = SK_SEN_IDLE;
  696. pAC->I2c.SenTable[i].SenRead = NULL;
  697. pAC->I2c.SenTable[i].SenDev = 0;
  698. }
  699. /* Now we are "INIT data"ed */
  700. pAC->I2c.InitLevel = SK_INIT_DATA;
  701. return(0);
  702. } /* SkI2cInit0*/
  703. /*
  704. * Do the init state 1 initialization
  705. *
  706. * initialize the following register of the LM80:
  707. * Configuration register:
  708. * - START, noINT, activeLOW, noINT#Clear, noRESET, noCI, noGPO#, noINIT
  709. *
  710. * Interrupt Mask Register 1:
  711. * - all interrupts are Disabled (0xff)
  712. *
  713. * Interrupt Mask Register 2:
  714. * - all interrupts are Disabled (0xff) Interrupt modi doesn't matter.
  715. *
  716. * Fan Divisor/RST_OUT register:
  717. * - Divisors set to 1 (bits 00), all others 0s.
  718. *
  719. * OS# Configuration/Temperature resolution Register:
  720. * - all 0s
  721. *
  722. */
  723. static int SkI2cInit1(
  724. SK_AC *pAC, /* Adapter Context */
  725. SK_IOC IoC) /* I/O Context */
  726. {
  727. int i;
  728. SK_U8 I2cSwCtrl;
  729. SK_GEPORT *pPrt; /* GIni Port struct pointer */
  730. if (pAC->I2c.InitLevel != SK_INIT_DATA) {
  731. /* ReInit not needed in I2C module */
  732. return(0);
  733. }
  734. /* Set the Direction of I2C-Data Pin to IN */
  735. SK_I2C_CLR_BIT(IoC, I2C_DATA_DIR | I2C_DATA);
  736. /* Check for 32-Bit Yukon with Low at I2C-Data Pin */
  737. SK_I2C_GET_SW(IoC, &I2cSwCtrl);
  738. if ((I2cSwCtrl & I2C_DATA) == 0) {
  739. /* this is a 32-Bit board */
  740. pAC->GIni.GIYukon32Bit = SK_TRUE;
  741. return(0);
  742. }
  743. /* Check for 64 Bit Yukon without sensors */
  744. if (SkI2cWrite(pAC, IoC, 0, LM80_ADDR, LM80_CFG, 0) != 0) {
  745. return(0);
  746. }
  747. (void)SkI2cWrite(pAC, IoC, 0xff, LM80_ADDR, LM80_IMSK_1, 0);
  748. (void)SkI2cWrite(pAC, IoC, 0xff, LM80_ADDR, LM80_IMSK_2, 0);
  749. (void)SkI2cWrite(pAC, IoC, 0, LM80_ADDR, LM80_FAN_CTRL, 0);
  750. (void)SkI2cWrite(pAC, IoC, 0, LM80_ADDR, LM80_TEMP_CTRL, 0);
  751. (void)SkI2cWrite(pAC, IoC, LM80_CFG_START, LM80_ADDR, LM80_CFG, 0);
  752. /*
  753. * MaxSens has to be updated here, because PhyType is not
  754. * set when performing Init Level 0
  755. */
  756. pAC->I2c.MaxSens = 5;
  757. pPrt = &pAC->GIni.GP[0];
  758. if (pAC->GIni.GIGenesis) {
  759. if (pPrt->PhyType == SK_PHY_BCOM) {
  760. if (pAC->GIni.GIMacsFound == 1) {
  761. pAC->I2c.MaxSens += 1;
  762. }
  763. else {
  764. pAC->I2c.MaxSens += 3;
  765. }
  766. }
  767. }
  768. else {
  769. pAC->I2c.MaxSens += 3;
  770. }
  771. for (i = 0; i < pAC->I2c.MaxSens; i++) {
  772. switch (i) {
  773. case 0:
  774. pAC->I2c.SenTable[i].SenDesc = "Temperature";
  775. pAC->I2c.SenTable[i].SenType = SK_SEN_TEMP;
  776. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_TEMP_HIGH_ERR;
  777. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_TEMP_HIGH_WARN;
  778. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_TEMP_LOW_WARN;
  779. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_TEMP_LOW_ERR;
  780. pAC->I2c.SenTable[i].SenReg = LM80_TEMP_IN;
  781. break;
  782. case 1:
  783. pAC->I2c.SenTable[i].SenDesc = "Voltage PCI";
  784. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  785. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PCI_5V_HIGH_ERR;
  786. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PCI_5V_HIGH_WARN;
  787. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PCI_5V_LOW_WARN;
  788. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PCI_5V_LOW_ERR;
  789. pAC->I2c.SenTable[i].SenReg = LM80_VT0_IN;
  790. break;
  791. case 2:
  792. pAC->I2c.SenTable[i].SenDesc = "Voltage PCI-IO";
  793. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  794. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PCI_IO_5V_HIGH_ERR;
  795. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PCI_IO_5V_HIGH_WARN;
  796. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PCI_IO_3V3_LOW_WARN;
  797. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PCI_IO_3V3_LOW_ERR;
  798. pAC->I2c.SenTable[i].SenReg = LM80_VT1_IN;
  799. pAC->I2c.SenTable[i].SenInit = SK_SEN_DYN_INIT_PCI_IO;
  800. break;
  801. case 3:
  802. pAC->I2c.SenTable[i].SenDesc = "Voltage ASIC";
  803. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  804. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_VDD_HIGH_ERR;
  805. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_VDD_HIGH_WARN;
  806. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_VDD_LOW_WARN;
  807. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_VDD_LOW_ERR;
  808. pAC->I2c.SenTable[i].SenReg = LM80_VT2_IN;
  809. break;
  810. case 4:
  811. if (pAC->GIni.GIGenesis) {
  812. if (pPrt->PhyType == SK_PHY_BCOM) {
  813. pAC->I2c.SenTable[i].SenDesc = "Voltage PHY A PLL";
  814. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PLL_3V3_HIGH_ERR;
  815. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PLL_3V3_HIGH_WARN;
  816. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PLL_3V3_LOW_WARN;
  817. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PLL_3V3_LOW_ERR;
  818. }
  819. else {
  820. pAC->I2c.SenTable[i].SenDesc = "Voltage PMA";
  821. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PLL_3V3_HIGH_ERR;
  822. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PLL_3V3_HIGH_WARN;
  823. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PLL_3V3_LOW_WARN;
  824. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PLL_3V3_LOW_ERR;
  825. }
  826. }
  827. else {
  828. pAC->I2c.SenTable[i].SenDesc = "Voltage VAUX";
  829. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_VAUX_3V3_HIGH_ERR;
  830. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_VAUX_3V3_HIGH_WARN;
  831. if (pAC->GIni.GIVauxAvail) {
  832. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_VAUX_3V3_LOW_WARN;
  833. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_VAUX_3V3_LOW_ERR;
  834. }
  835. else {
  836. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_VAUX_0V_WARN_ERR;
  837. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_VAUX_0V_WARN_ERR;
  838. }
  839. }
  840. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  841. pAC->I2c.SenTable[i].SenReg = LM80_VT3_IN;
  842. break;
  843. case 5:
  844. if (pAC->GIni.GIGenesis) {
  845. pAC->I2c.SenTable[i].SenDesc = "Voltage PHY 2V5";
  846. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PHY_2V5_HIGH_ERR;
  847. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PHY_2V5_HIGH_WARN;
  848. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PHY_2V5_LOW_WARN;
  849. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PHY_2V5_LOW_ERR;
  850. }
  851. else {
  852. pAC->I2c.SenTable[i].SenDesc = "Voltage ASIC-Co 1V5";
  853. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_CORE_1V5_HIGH_ERR;
  854. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_CORE_1V5_HIGH_WARN;
  855. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_CORE_1V5_LOW_WARN;
  856. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_CORE_1V5_LOW_ERR;
  857. }
  858. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  859. pAC->I2c.SenTable[i].SenReg = LM80_VT4_IN;
  860. break;
  861. case 6:
  862. if (pAC->GIni.GIGenesis) {
  863. pAC->I2c.SenTable[i].SenDesc = "Voltage PHY B PLL";
  864. }
  865. else {
  866. pAC->I2c.SenTable[i].SenDesc = "Voltage PHY 3V3";
  867. }
  868. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  869. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PLL_3V3_HIGH_ERR;
  870. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PLL_3V3_HIGH_WARN;
  871. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PLL_3V3_LOW_WARN;
  872. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PLL_3V3_LOW_ERR;
  873. pAC->I2c.SenTable[i].SenReg = LM80_VT5_IN;
  874. break;
  875. case 7:
  876. if (pAC->GIni.GIGenesis) {
  877. pAC->I2c.SenTable[i].SenDesc = "Speed Fan";
  878. pAC->I2c.SenTable[i].SenType = SK_SEN_FAN;
  879. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_FAN_HIGH_ERR;
  880. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_FAN_HIGH_WARN;
  881. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_FAN_LOW_WARN;
  882. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_FAN_LOW_ERR;
  883. pAC->I2c.SenTable[i].SenReg = LM80_FAN2_IN;
  884. }
  885. else {
  886. pAC->I2c.SenTable[i].SenDesc = "Voltage PHY 2V5";
  887. pAC->I2c.SenTable[i].SenType = SK_SEN_VOLT;
  888. pAC->I2c.SenTable[i].SenThreErrHigh = SK_SEN_PHY_2V5_HIGH_ERR;
  889. pAC->I2c.SenTable[i].SenThreWarnHigh = SK_SEN_PHY_2V5_HIGH_WARN;
  890. pAC->I2c.SenTable[i].SenThreWarnLow = SK_SEN_PHY_2V5_LOW_WARN;
  891. pAC->I2c.SenTable[i].SenThreErrLow = SK_SEN_PHY_2V5_LOW_ERR;
  892. pAC->I2c.SenTable[i].SenReg = LM80_VT6_IN;
  893. }
  894. break;
  895. default:
  896. SK_ERR_LOG(pAC, SK_ERRCL_INIT | SK_ERRCL_SW,
  897. SKERR_I2C_E001, SKERR_I2C_E001MSG);
  898. break;
  899. }
  900. pAC->I2c.SenTable[i].SenValue = 0;
  901. pAC->I2c.SenTable[i].SenErrFlag = SK_SEN_ERR_OK;
  902. pAC->I2c.SenTable[i].SenErrCts = 0;
  903. pAC->I2c.SenTable[i].SenBegErrTS = 0;
  904. pAC->I2c.SenTable[i].SenState = SK_SEN_IDLE;
  905. pAC->I2c.SenTable[i].SenRead = SkLm80ReadSensor;
  906. pAC->I2c.SenTable[i].SenDev = LM80_ADDR;
  907. }
  908. #ifndef SK_DIAG
  909. pAC->I2c.DummyReads = pAC->I2c.MaxSens;
  910. #endif /* !SK_DIAG */
  911. /* Clear I2C IRQ */
  912. SK_OUT32(IoC, B2_I2C_IRQ, I2C_CLR_IRQ);
  913. /* Now we are I/O initialized */
  914. pAC->I2c.InitLevel = SK_INIT_IO;
  915. return(0);
  916. } /* SkI2cInit1 */
  917. /*
  918. * Init level 2: Start first sensor read.
  919. */
  920. static int SkI2cInit2(
  921. SK_AC *pAC, /* Adapter Context */
  922. SK_IOC IoC) /* I/O Context */
  923. {
  924. int ReadComplete;
  925. SK_SENSOR *pSen;
  926. if (pAC->I2c.InitLevel != SK_INIT_IO) {
  927. /* ReInit not needed in I2C module */
  928. /* Init0 and Init2 not permitted */
  929. return(0);
  930. }
  931. pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
  932. ReadComplete = SkI2cReadSensor(pAC, IoC, pSen);
  933. if (ReadComplete) {
  934. SK_ERR_LOG(pAC, SK_ERRCL_INIT, SKERR_I2C_E008, SKERR_I2C_E008MSG);
  935. }
  936. /* Now we are correctly initialized */
  937. pAC->I2c.InitLevel = SK_INIT_RUN;
  938. return(0);
  939. } /* SkI2cInit2*/
  940. /*
  941. * Initialize I2C devices
  942. *
  943. * Get the first voltage value and discard it.
  944. * Go into temperature read mode. A default pointer is not set.
  945. *
  946. * The things to be done depend on the init level in the parameter list:
  947. * Level 0:
  948. * Initialize only the data structures. Do NOT access hardware.
  949. * Level 1:
  950. * Initialize hardware through SK_IN / SK_OUT commands. Do NOT use interrupts.
  951. * Level 2:
  952. * Everything is possible. Interrupts may be used from now on.
  953. *
  954. * return:
  955. * 0 = success
  956. * other = error.
  957. */
  958. int SkI2cInit(
  959. SK_AC *pAC, /* Adapter Context */
  960. SK_IOC IoC, /* I/O Context needed in levels 1 and 2 */
  961. int Level) /* Init Level */
  962. {
  963. switch (Level) {
  964. case SK_INIT_DATA:
  965. return(SkI2cInit0(pAC));
  966. case SK_INIT_IO:
  967. return(SkI2cInit1(pAC, IoC));
  968. case SK_INIT_RUN:
  969. return(SkI2cInit2(pAC, IoC));
  970. default:
  971. break;
  972. }
  973. return(0);
  974. } /* SkI2cInit */
  975. #ifndef SK_DIAG
  976. /*
  977. * Interrupt service function for the I2C Interface
  978. *
  979. * Clears the Interrupt source
  980. *
  981. * Reads the register and check it for sending a trap.
  982. *
  983. * Starts the timer if necessary.
  984. */
  985. void SkI2cIsr(
  986. SK_AC *pAC, /* Adapter Context */
  987. SK_IOC IoC) /* I/O Context */
  988. {
  989. SK_EVPARA Para;
  990. /* Clear I2C IRQ */
  991. SK_OUT32(IoC, B2_I2C_IRQ, I2C_CLR_IRQ);
  992. Para.Para64 = 0;
  993. SkEventQueue(pAC, SKGE_I2C, SK_I2CEV_IRQ, Para);
  994. } /* SkI2cIsr */
  995. /*
  996. * Check this sensors Value against the threshold and send events.
  997. */
  998. static void SkI2cCheckSensor(
  999. SK_AC *pAC, /* Adapter Context */
  1000. SK_SENSOR *pSen)
  1001. {
  1002. SK_EVPARA ParaLocal;
  1003. SK_BOOL TooHigh; /* Is sensor too high? */
  1004. SK_BOOL TooLow; /* Is sensor too low? */
  1005. SK_U64 CurrTime; /* Current Time */
  1006. SK_BOOL DoTrapSend; /* We need to send a trap */
  1007. SK_BOOL DoErrLog; /* We need to log the error */
  1008. SK_BOOL IsError; /* We need to log the error */
  1009. /* Check Dummy Reads first */
  1010. if (pAC->I2c.DummyReads > 0) {
  1011. pAC->I2c.DummyReads--;
  1012. return;
  1013. }
  1014. /* Get the current time */
  1015. CurrTime = SkOsGetTime(pAC);
  1016. /* Set para to the most useful setting: The current sensor. */
  1017. ParaLocal.Para64 = (SK_U64)pAC->I2c.CurrSens;
  1018. /* Check the Value against the thresholds. First: Error Thresholds */
  1019. TooHigh = (pSen->SenValue > pSen->SenThreErrHigh);
  1020. TooLow = (pSen->SenValue < pSen->SenThreErrLow);
  1021. IsError = SK_FALSE;
  1022. if (TooHigh || TooLow) {
  1023. /* Error condition is satisfied */
  1024. DoTrapSend = SK_TRUE;
  1025. DoErrLog = SK_TRUE;
  1026. /* Now error condition is satisfied */
  1027. IsError = SK_TRUE;
  1028. if (pSen->SenErrFlag == SK_SEN_ERR_ERR) {
  1029. /* This state is the former one */
  1030. /* So check first whether we have to send a trap */
  1031. if (pSen->SenLastErrTrapTS + SK_SEN_ERR_TR_HOLD >
  1032. CurrTime) {
  1033. /*
  1034. * Do NOT send the Trap. The hold back time
  1035. * has to run out first.
  1036. */
  1037. DoTrapSend = SK_FALSE;
  1038. }
  1039. /* Check now whether we have to log an Error */
  1040. if (pSen->SenLastErrLogTS + SK_SEN_ERR_LOG_HOLD >
  1041. CurrTime) {
  1042. /*
  1043. * Do NOT log the error. The hold back time
  1044. * has to run out first.
  1045. */
  1046. DoErrLog = SK_FALSE;
  1047. }
  1048. }
  1049. else {
  1050. /* We came from a different state -> Set Begin Time Stamp */
  1051. pSen->SenBegErrTS = CurrTime;
  1052. pSen->SenErrFlag = SK_SEN_ERR_ERR;
  1053. }
  1054. if (DoTrapSend) {
  1055. /* Set current Time */
  1056. pSen->SenLastErrTrapTS = CurrTime;
  1057. pSen->SenErrCts++;
  1058. /* Queue PNMI Event */
  1059. SkEventQueue(pAC, SKGE_PNMI, (TooHigh ?
  1060. SK_PNMI_EVT_SEN_ERR_UPP :
  1061. SK_PNMI_EVT_SEN_ERR_LOW),
  1062. ParaLocal);
  1063. }
  1064. if (DoErrLog) {
  1065. /* Set current Time */
  1066. pSen->SenLastErrLogTS = CurrTime;
  1067. if (pSen->SenType == SK_SEN_TEMP) {
  1068. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E011,
  1069. SKERR_I2C_E011MSG);
  1070. } else if (pSen->SenType == SK_SEN_VOLT) {
  1071. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E012,
  1072. SKERR_I2C_E012MSG);
  1073. } else
  1074. {
  1075. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E015,
  1076. SKERR_I2C_E015MSG);
  1077. }
  1078. }
  1079. }
  1080. /* Check the Value against the thresholds */
  1081. /* 2nd: Warning thresholds */
  1082. TooHigh = (pSen->SenValue > pSen->SenThreWarnHigh);
  1083. TooLow = (pSen->SenValue < pSen->SenThreWarnLow);
  1084. if (!IsError && (TooHigh || TooLow)) {
  1085. /* Error condition is satisfied */
  1086. DoTrapSend = SK_TRUE;
  1087. DoErrLog = SK_TRUE;
  1088. if (pSen->SenErrFlag == SK_SEN_ERR_WARN) {
  1089. /* This state is the former one */
  1090. /* So check first whether we have to send a trap */
  1091. if (pSen->SenLastWarnTrapTS + SK_SEN_WARN_TR_HOLD >
  1092. CurrTime) {
  1093. /*
  1094. * Do NOT send the Trap. The hold back time
  1095. * has to run out first.
  1096. */
  1097. DoTrapSend = SK_FALSE;
  1098. }
  1099. /* Check now whether we have to log an Error */
  1100. if (pSen->SenLastWarnLogTS + SK_SEN_WARN_LOG_HOLD >
  1101. CurrTime) {
  1102. /*
  1103. * Do NOT log the error. The hold back time
  1104. * has to run out first.
  1105. */
  1106. DoErrLog = SK_FALSE;
  1107. }
  1108. }
  1109. else {
  1110. /* We came from a different state -> Set Begin Time Stamp */
  1111. pSen->SenBegWarnTS = CurrTime;
  1112. pSen->SenErrFlag = SK_SEN_ERR_WARN;
  1113. }
  1114. if (DoTrapSend) {
  1115. /* Set current Time */
  1116. pSen->SenLastWarnTrapTS = CurrTime;
  1117. pSen->SenWarnCts++;
  1118. /* Queue PNMI Event */
  1119. SkEventQueue(pAC, SKGE_PNMI, (TooHigh ?
  1120. SK_PNMI_EVT_SEN_WAR_UPP :
  1121. SK_PNMI_EVT_SEN_WAR_LOW),
  1122. ParaLocal);
  1123. }
  1124. if (DoErrLog) {
  1125. /* Set current Time */
  1126. pSen->SenLastWarnLogTS = CurrTime;
  1127. if (pSen->SenType == SK_SEN_TEMP) {
  1128. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E009,
  1129. SKERR_I2C_E009MSG);
  1130. } else if (pSen->SenType == SK_SEN_VOLT) {
  1131. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E010,
  1132. SKERR_I2C_E010MSG);
  1133. } else
  1134. {
  1135. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E014,
  1136. SKERR_I2C_E014MSG);
  1137. }
  1138. }
  1139. }
  1140. /* Check for NO error at all */
  1141. if (!IsError && !TooHigh && !TooLow) {
  1142. /* Set o.k. Status if no error and no warning condition */
  1143. pSen->SenErrFlag = SK_SEN_ERR_OK;
  1144. }
  1145. /* End of check against the thresholds */
  1146. /* Bug fix AF: 16.Aug.2001: Correct the init base
  1147. * of LM80 sensor.
  1148. */
  1149. if (pSen->SenInit == SK_SEN_DYN_INIT_PCI_IO) {
  1150. pSen->SenInit = SK_SEN_DYN_INIT_NONE;
  1151. if (pSen->SenValue > SK_SEN_PCI_IO_RANGE_LIMITER) {
  1152. /* 5V PCI-IO Voltage */
  1153. pSen->SenThreWarnLow = SK_SEN_PCI_IO_5V_LOW_WARN;
  1154. pSen->SenThreErrLow = SK_SEN_PCI_IO_5V_LOW_ERR;
  1155. }
  1156. else {
  1157. /* 3.3V PCI-IO Voltage */
  1158. pSen->SenThreWarnHigh = SK_SEN_PCI_IO_3V3_HIGH_WARN;
  1159. pSen->SenThreErrHigh = SK_SEN_PCI_IO_3V3_HIGH_ERR;
  1160. }
  1161. }
  1162. #if 0
  1163. /* Dynamic thresholds also for VAUX of LM80 sensor */
  1164. if (pSen->SenInit == SK_SEN_DYN_INIT_VAUX) {
  1165. pSen->SenInit = SK_SEN_DYN_INIT_NONE;
  1166. /* 3.3V VAUX Voltage */
  1167. if (pSen->SenValue > SK_SEN_VAUX_RANGE_LIMITER) {
  1168. pSen->SenThreWarnLow = SK_SEN_VAUX_3V3_LOW_WARN;
  1169. pSen->SenThreErrLow = SK_SEN_VAUX_3V3_LOW_ERR;
  1170. }
  1171. /* 0V VAUX Voltage */
  1172. else {
  1173. pSen->SenThreWarnHigh = SK_SEN_VAUX_0V_WARN_ERR;
  1174. pSen->SenThreErrHigh = SK_SEN_VAUX_0V_WARN_ERR;
  1175. }
  1176. }
  1177. /*
  1178. * Check initialization state:
  1179. * The VIO Thresholds need adaption
  1180. */
  1181. if (!pSen->SenInit && pSen->SenReg == LM80_VT1_IN &&
  1182. pSen->SenValue > SK_SEN_WARNLOW2C &&
  1183. pSen->SenValue < SK_SEN_WARNHIGH2) {
  1184. pSen->SenThreErrLow = SK_SEN_ERRLOW2C;
  1185. pSen->SenThreWarnLow = SK_SEN_WARNLOW2C;
  1186. pSen->SenInit = SK_TRUE;
  1187. }
  1188. if (!pSen->SenInit && pSen->SenReg == LM80_VT1_IN &&
  1189. pSen->SenValue > SK_SEN_WARNLOW2 &&
  1190. pSen->SenValue < SK_SEN_WARNHIGH2C) {
  1191. pSen->SenThreErrHigh = SK_SEN_ERRHIGH2C;
  1192. pSen->SenThreWarnHigh = SK_SEN_WARNHIGH2C;
  1193. pSen->SenInit = SK_TRUE;
  1194. }
  1195. #endif
  1196. if (pSen->SenInit != SK_SEN_DYN_INIT_NONE) {
  1197. SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_I2C_E013, SKERR_I2C_E013MSG);
  1198. }
  1199. } /* SkI2cCheckSensor*/
  1200. /*
  1201. * The only Event to be served is the timeout event
  1202. *
  1203. */
  1204. int SkI2cEvent(
  1205. SK_AC *pAC, /* Adapter Context */
  1206. SK_IOC IoC, /* I/O Context */
  1207. SK_U32 Event, /* Module specific Event */
  1208. SK_EVPARA Para) /* Event specific Parameter */
  1209. {
  1210. int ReadComplete;
  1211. SK_SENSOR *pSen;
  1212. SK_U32 Time;
  1213. SK_EVPARA ParaLocal;
  1214. int i;
  1215. /* New case: no sensors */
  1216. if (pAC->I2c.MaxSens == 0) {
  1217. return(0);
  1218. }
  1219. switch (Event) {
  1220. case SK_I2CEV_IRQ:
  1221. pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
  1222. ReadComplete = SkI2cReadSensor(pAC, IoC, pSen);
  1223. if (ReadComplete) {
  1224. /* Check sensor against defined thresholds */
  1225. SkI2cCheckSensor (pAC, pSen);
  1226. /* Increment Current sensor and set appropriate Timeout */
  1227. pAC->I2c.CurrSens++;
  1228. if (pAC->I2c.CurrSens >= pAC->I2c.MaxSens) {
  1229. pAC->I2c.CurrSens = 0;
  1230. Time = SK_I2C_TIM_LONG;
  1231. }
  1232. else {
  1233. Time = SK_I2C_TIM_SHORT;
  1234. }
  1235. /* Start Timer */
  1236. ParaLocal.Para64 = (SK_U64)0;
  1237. pAC->I2c.TimerMode = SK_TIMER_NEW_GAUGING;
  1238. SkTimerStart(pAC, IoC, &pAC->I2c.SenTimer, Time,
  1239. SKGE_I2C, SK_I2CEV_TIM, ParaLocal);
  1240. }
  1241. else {
  1242. /* Start Timer */
  1243. ParaLocal.Para64 = (SK_U64)0;
  1244. pAC->I2c.TimerMode = SK_TIMER_WATCH_STATEMACHINE;
  1245. SkTimerStart(pAC, IoC, &pAC->I2c.SenTimer, SK_I2C_TIM_WATCH,
  1246. SKGE_I2C, SK_I2CEV_TIM, ParaLocal);
  1247. }
  1248. break;
  1249. case SK_I2CEV_TIM:
  1250. if (pAC->I2c.TimerMode == SK_TIMER_NEW_GAUGING) {
  1251. ParaLocal.Para64 = (SK_U64)0;
  1252. SkTimerStop(pAC, IoC, &pAC->I2c.SenTimer);
  1253. pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
  1254. ReadComplete = SkI2cReadSensor(pAC, IoC, pSen);
  1255. if (ReadComplete) {
  1256. /* Check sensor against defined thresholds */
  1257. SkI2cCheckSensor (pAC, pSen);
  1258. /* Increment Current sensor and set appropriate Timeout */
  1259. pAC->I2c.CurrSens++;
  1260. if (pAC->I2c.CurrSens == pAC->I2c.MaxSens) {
  1261. pAC->I2c.CurrSens = 0;
  1262. Time = SK_I2C_TIM_LONG;
  1263. }
  1264. else {
  1265. Time = SK_I2C_TIM_SHORT;
  1266. }
  1267. /* Start Timer */
  1268. ParaLocal.Para64 = (SK_U64)0;
  1269. pAC->I2c.TimerMode = SK_TIMER_NEW_GAUGING;
  1270. SkTimerStart(pAC, IoC, &pAC->I2c.SenTimer, Time,
  1271. SKGE_I2C, SK_I2CEV_TIM, ParaLocal);
  1272. }
  1273. }
  1274. else {
  1275. pSen = &pAC->I2c.SenTable[pAC->I2c.CurrSens];
  1276. pSen->SenErrFlag = SK_SEN_ERR_FAULTY;
  1277. SK_I2C_STOP(IoC);
  1278. /* Increment Current sensor and set appropriate Timeout */
  1279. pAC->I2c.CurrSens++;
  1280. if (pAC->I2c.CurrSens == pAC->I2c.MaxSens) {
  1281. pAC->I2c.CurrSens = 0;
  1282. Time = SK_I2C_TIM_LONG;
  1283. }
  1284. else {
  1285. Time = SK_I2C_TIM_SHORT;
  1286. }
  1287. /* Start Timer */
  1288. ParaLocal.Para64 = (SK_U64)0;
  1289. pAC->I2c.TimerMode = SK_TIMER_NEW_GAUGING;
  1290. SkTimerStart(pAC, IoC, &pAC->I2c.SenTimer, Time,
  1291. SKGE_I2C, SK_I2CEV_TIM, ParaLocal);
  1292. }
  1293. break;
  1294. case SK_I2CEV_CLEAR:
  1295. for (i = 0; i < SK_MAX_SENSORS; i++) {
  1296. pAC->I2c.SenTable[i].SenErrFlag = SK_SEN_ERR_OK;
  1297. pAC->I2c.SenTable[i].SenErrCts = 0;
  1298. pAC->I2c.SenTable[i].SenWarnCts = 0;
  1299. pAC->I2c.SenTable[i].SenBegErrTS = 0;
  1300. pAC->I2c.SenTable[i].SenBegWarnTS = 0;
  1301. pAC->I2c.SenTable[i].SenLastErrTrapTS = (SK_U64)0;
  1302. pAC->I2c.SenTable[i].SenLastErrLogTS = (SK_U64)0;
  1303. pAC->I2c.SenTable[i].SenLastWarnTrapTS = (SK_U64)0;
  1304. pAC->I2c.SenTable[i].SenLastWarnLogTS = (SK_U64)0;
  1305. }
  1306. break;
  1307. default:
  1308. SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_I2C_E006, SKERR_I2C_E006MSG);
  1309. }
  1310. return(0);
  1311. } /* SkI2cEvent*/
  1312. #endif /* !SK_DIAG */
  1313. #endif /* CONFIG_SK98 */