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