]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/sk98lin/skgehwt.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / drivers / net / sk98lin / skgehwt.c
1 /******************************************************************************
2  *
3  * Name:        skgehwt.c
4  * Project:     GEnesis, PCI Gigabit Ethernet Adapter
5  * Version:     $Revision: 1.13 $
6  * Date:        $Date: 1999/11/22 13:31:12 $
7  * Purpose:     Hardware Timer.
8  *
9  ******************************************************************************/
10
11 /******************************************************************************
12  *
13  *      (C)Copyright 1998,1999 SysKonnect,
14  *      a business unit of Schneider & Koch & Co. Datensysteme GmbH.
15  *
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.
20  *
21  *      The information in this file is provided "AS IS" without warranty.
22  *
23  ******************************************************************************/
24
25 /******************************************************************************
26  *
27  * History:
28  *
29  *      $Log: skgehwt.c,v $
30  *      Revision 1.13  1999/11/22 13:31:12  cgoos
31  *      Changed license header to GPL.
32  *
33  *      Revision 1.12  1998/10/15 15:11:34  gklug
34  *      fix: ID_sccs to SysKonnectFileId
35  *
36  *      Revision 1.11  1998/10/08 15:27:51  gklug
37  *      chg: correction factor is host clock dependent
38  *
39  *      Revision 1.10  1998/09/15 14:18:31  cgoos
40  *      Changed more BOOLEANs to SK_xxx
41  *
42  *      Revision 1.9  1998/09/15 14:16:06  cgoos
43  *      Changed line 107: FALSE to SK_FALSE
44  *
45  *      Revision 1.8  1998/08/24 13:04:44  gklug
46  *      fix: typo
47  *
48  *      Revision 1.7  1998/08/19 09:50:49  gklug
49  *      fix: remove struct keyword from c-code (see CCC) add typedefs
50  *
51  *      Revision 1.6  1998/08/17 09:59:02  gklug
52  *      fix: typos
53  *
54  *      Revision 1.5  1998/08/14 07:09:10  gklug
55  *      fix: chg pAc -> pAC
56  *
57  *      Revision 1.4  1998/08/10 14:14:52  gklug
58  *      rmv: unneccessary SK_ADDR macro
59  *
60  *      Revision 1.3  1998/08/07 12:53:44  gklug
61  *      fix: first compiled version
62  *
63  *      Revision 1.2  1998/08/07 09:19:29  gklug
64  *      adapt functions to the C coding conventions
65  *      rmv unneccessary functions.
66  *
67  *      Revision 1.1  1998/08/05 11:28:36  gklug
68  *      first version: adapted from SMT/FDDI
69  *
70  *
71  *
72  *
73  ******************************************************************************/
74
75
76 #include <config.h>
77
78 /*
79         Event queue and dispatcher
80 */
81 static const char SysKonnectFileId[] =
82         "$Header: /usr56/projects/ge/schedule/skgehwt.c,v 1.13 1999/11/22 13:31:12 cgoos Exp $" ;
83
84 #include "h/skdrv1st.h"         /* Driver Specific Definitions */
85 #include "h/skdrv2nd.h"         /* Adapter Control- and Driver specific Def. */
86
87 #ifdef __C2MAN__
88 /*
89         Hardware Timer function queue management.
90
91         General Description:
92
93  */
94 intro()
95 {}
96 #endif
97
98 /*
99  * Prototypes of local functions.
100  */
101 #define SK_HWT_MAX      (65000)
102
103 /* correction factor */
104 #define SK_HWT_FAC      (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
105
106 /*
107  * Initialize hardware timer.
108  *
109  * Must be called during init level 1.
110  */
111 void    SkHwtInit(
112 SK_AC   *pAC,   /* Adapters context */
113 SK_IOC  Ioc)    /* IoContext */
114 {
115         pAC->Hwt.TStart = 0 ;
116         pAC->Hwt.TStop  = 0 ;
117         pAC->Hwt.TActive = SK_FALSE ;
118
119         SkHwtStop(pAC,Ioc) ;
120 }
121
122 /*
123  *
124  * Start hardware timer (clock ticks are 16us).
125  *
126  */
127 void    SkHwtStart(
128 SK_AC   *pAC,   /* Adapters context */
129 SK_IOC  Ioc,    /* IoContext */
130 SK_U32  Time)   /* Time in units of 16us to load the timer with. */
131 {
132         SK_U32  Cnt ;
133
134         if (Time > SK_HWT_MAX)
135                 Time = SK_HWT_MAX ;
136
137         pAC->Hwt.TStart = Time ;
138         pAC->Hwt.TStop = 0L ;
139
140         Cnt = Time ;
141
142         /*
143          * if time < 16 us
144          *      time = 16 us
145          */
146         if (!Cnt) {
147                 Cnt++ ;
148         }
149
150         SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC) ;
151         SK_OUT16(Ioc, B2_TI_CRTL, TIM_START) ;  /* Start timer. */
152
153         pAC->Hwt.TActive = SK_TRUE ;
154 }
155
156 /*
157  * Stop hardware timer.
158  * and clear the timer IRQ
159  */
160 void    SkHwtStop(
161 SK_AC   *pAC,   /* Adapters context */
162 SK_IOC  Ioc)    /* IoContext */
163 {
164         SK_OUT16(Ioc, B2_TI_CRTL, TIM_STOP) ;
165         SK_OUT16(Ioc, B2_TI_CRTL, TIM_CLR_IRQ) ;
166
167         pAC->Hwt.TActive = SK_FALSE ;
168 }
169
170
171 /*
172  *      Stop hardware timer and read time elapsed since last start.
173  *
174  * returns
175  *      The elapsed time since last start in units of 16us.
176  *
177  */
178 SK_U32  SkHwtRead(
179 SK_AC   *pAC,   /* Adapters context */
180 SK_IOC  Ioc)    /* IoContext */
181 {
182         SK_U32  TRead ;
183         SK_U32  IStatus ;
184
185         if (pAC->Hwt.TActive) {
186                 SkHwtStop(pAC,Ioc) ;
187
188                 SK_IN32(Ioc, B2_TI_VAL, &TRead);
189                 TRead /= SK_HWT_FAC;
190
191                 SK_IN32(Ioc, B0_ISRC, &IStatus);
192
193                 /* Check if timer expired (or wraparound). */
194                 if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
195                         SkHwtStop(pAC,Ioc) ;
196                         pAC->Hwt.TStop = pAC->Hwt.TStart ;
197                 } else {
198                         pAC->Hwt.TStop = pAC->Hwt.TStart - TRead ;
199                 }
200         }
201         return (pAC->Hwt.TStop) ;
202 }
203
204 /*
205  * interrupt source= timer
206  */
207 void    SkHwtIsr(
208 SK_AC   *pAC,   /* Adapters context */
209 SK_IOC  Ioc)    /* IoContext */
210 {
211         SkHwtStop(pAC,Ioc);
212         pAC->Hwt.TStop = pAC->Hwt.TStart;
213         SkTimerDone(pAC,Ioc) ;
214 }
215 /* End of file */