Linux 2.6.20.7
[linux/fpc-iii.git] / drivers / net / sk98lin / skgehwt.c
blobdb670993c2df3216f01c54f224f2c55d8ca8386b
1 /******************************************************************************
3 * Name: skgehwt.c
4 * Project: Gigabit Ethernet Adapters, Event Scheduler Module
5 * Version: $Revision: 1.15 $
6 * Date: $Date: 2003/09/16 13:41:23 $
7 * Purpose: Hardware Timer
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2002 SysKonnect GmbH.
14 * (C)Copyright 2002-2003 Marvell.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * The information in this file is provided "AS IS" without warranty.
23 ******************************************************************************/
26 * Event queue and dispatcher
28 #if (defined(DEBUG) || ((!defined(LINT)) && (!defined(SK_SLIM))))
29 static const char SysKonnectFileId[] =
30 "@(#) $Id: skgehwt.c,v 1.15 2003/09/16 13:41:23 rschmidt Exp $ (C) Marvell.";
31 #endif
33 #include "h/skdrv1st.h" /* Driver Specific Definitions */
34 #include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
36 #ifdef __C2MAN__
38 * Hardware Timer function queue management.
40 intro()
42 #endif
45 * Prototypes of local functions.
47 #define SK_HWT_MAX (65000)
49 /* correction factor */
50 #define SK_HWT_FAC (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
53 * Initialize hardware timer.
55 * Must be called during init level 1.
57 void SkHwtInit(
58 SK_AC *pAC, /* Adapters context */
59 SK_IOC Ioc) /* IoContext */
61 pAC->Hwt.TStart = 0 ;
62 pAC->Hwt.TStop = 0 ;
63 pAC->Hwt.TActive = SK_FALSE;
65 SkHwtStop(pAC, Ioc);
70 * Start hardware timer (clock ticks are 16us).
73 void SkHwtStart(
74 SK_AC *pAC, /* Adapters context */
75 SK_IOC Ioc, /* IoContext */
76 SK_U32 Time) /* Time in units of 16us to load the timer with. */
78 SK_U32 Cnt;
80 if (Time > SK_HWT_MAX)
81 Time = SK_HWT_MAX;
83 pAC->Hwt.TStart = Time;
84 pAC->Hwt.TStop = 0L;
86 Cnt = Time;
89 * if time < 16 us
90 * time = 16 us
92 if (!Cnt) {
93 Cnt++;
96 SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC);
98 SK_OUT16(Ioc, B2_TI_CTRL, TIM_START); /* Start timer. */
100 pAC->Hwt.TActive = SK_TRUE;
104 * Stop hardware timer.
105 * and clear the timer IRQ
107 void SkHwtStop(
108 SK_AC *pAC, /* Adapters context */
109 SK_IOC Ioc) /* IoContext */
111 SK_OUT16(Ioc, B2_TI_CTRL, TIM_STOP);
113 SK_OUT16(Ioc, B2_TI_CTRL, TIM_CLR_IRQ);
115 pAC->Hwt.TActive = SK_FALSE;
120 * Stop hardware timer and read time elapsed since last start.
122 * returns
123 * The elapsed time since last start in units of 16us.
126 SK_U32 SkHwtRead(
127 SK_AC *pAC, /* Adapters context */
128 SK_IOC Ioc) /* IoContext */
130 SK_U32 TRead;
131 SK_U32 IStatus;
133 if (pAC->Hwt.TActive) {
135 SkHwtStop(pAC, Ioc);
137 SK_IN32(Ioc, B2_TI_VAL, &TRead);
138 TRead /= SK_HWT_FAC;
140 SK_IN32(Ioc, B0_ISRC, &IStatus);
142 /* Check if timer expired (or wraped around) */
143 if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
145 SkHwtStop(pAC, Ioc);
147 pAC->Hwt.TStop = pAC->Hwt.TStart;
149 else {
151 pAC->Hwt.TStop = pAC->Hwt.TStart - TRead;
154 return(pAC->Hwt.TStop);
158 * interrupt source= timer
160 void SkHwtIsr(
161 SK_AC *pAC, /* Adapters context */
162 SK_IOC Ioc) /* IoContext */
164 SkHwtStop(pAC, Ioc);
166 pAC->Hwt.TStop = pAC->Hwt.TStart;
168 SkTimerDone(pAC, Ioc);
171 /* End of file */