]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/sk98lin/skgehwt.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[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$
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.3.1  2011-02-28 14:53:19  lothar
31  *      imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
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 /*
82         Event queue and dispatcher
83 */
84 static const char SysKonnectFileId[] =
85         "$Header$" ;
86
87 #include "h/skdrv1st.h"         /* Driver Specific Definitions */
88 #include "h/skdrv2nd.h"         /* Adapter Control- and Driver specific Def. */
89
90 #ifdef __C2MAN__
91 /*
92         Hardware Timer function queue management.
93
94         General Description:
95
96  */
97 intro()
98 {}
99 #endif
100
101 /*
102  * Prototypes of local functions.
103  */
104 #define SK_HWT_MAX      (65000)
105
106 /* correction factor */
107 #define SK_HWT_FAC      (1000 * (SK_U32)pAC->GIni.GIHstClkFact / 100)
108
109 /*
110  * Initialize hardware timer.
111  *
112  * Must be called during init level 1.
113  */
114 void    SkHwtInit(
115 SK_AC   *pAC,   /* Adapters context */
116 SK_IOC  Ioc)    /* IoContext */
117 {
118         pAC->Hwt.TStart = 0 ;
119         pAC->Hwt.TStop  = 0 ;
120         pAC->Hwt.TActive = SK_FALSE ;
121
122         SkHwtStop(pAC,Ioc) ;
123 }
124
125 /*
126  *
127  * Start hardware timer (clock ticks are 16us).
128  *
129  */
130 void    SkHwtStart(
131 SK_AC   *pAC,   /* Adapters context */
132 SK_IOC  Ioc,    /* IoContext */
133 SK_U32  Time)   /* Time in units of 16us to load the timer with. */
134 {
135         SK_U32  Cnt ;
136
137         if (Time > SK_HWT_MAX)
138                 Time = SK_HWT_MAX ;
139
140         pAC->Hwt.TStart = Time ;
141         pAC->Hwt.TStop = 0L ;
142
143         Cnt = Time ;
144
145         /*
146          * if time < 16 us
147          *      time = 16 us
148          */
149         if (!Cnt) {
150                 Cnt++ ;
151         }
152
153         SK_OUT32(Ioc, B2_TI_INI, Cnt * SK_HWT_FAC) ;
154         SK_OUT16(Ioc, B2_TI_CRTL, TIM_START) ;  /* Start timer. */
155
156         pAC->Hwt.TActive = SK_TRUE ;
157 }
158
159 /*
160  * Stop hardware timer.
161  * and clear the timer IRQ
162  */
163 void    SkHwtStop(
164 SK_AC   *pAC,   /* Adapters context */
165 SK_IOC  Ioc)    /* IoContext */
166 {
167         SK_OUT16(Ioc, B2_TI_CRTL, TIM_STOP) ;
168         SK_OUT16(Ioc, B2_TI_CRTL, TIM_CLR_IRQ) ;
169
170         pAC->Hwt.TActive = SK_FALSE ;
171 }
172
173
174 /*
175  *      Stop hardware timer and read time elapsed since last start.
176  *
177  * returns
178  *      The elapsed time since last start in units of 16us.
179  *
180  */
181 SK_U32  SkHwtRead(
182 SK_AC   *pAC,   /* Adapters context */
183 SK_IOC  Ioc)    /* IoContext */
184 {
185         SK_U32  TRead ;
186         SK_U32  IStatus ;
187
188         if (pAC->Hwt.TActive) {
189                 SkHwtStop(pAC,Ioc) ;
190
191                 SK_IN32(Ioc, B2_TI_VAL, &TRead);
192                 TRead /= SK_HWT_FAC;
193
194                 SK_IN32(Ioc, B0_ISRC, &IStatus);
195
196                 /* Check if timer expired (or wraparound). */
197                 if ((TRead > pAC->Hwt.TStart) || (IStatus & IS_TIMINT)) {
198                         SkHwtStop(pAC,Ioc) ;
199                         pAC->Hwt.TStop = pAC->Hwt.TStart ;
200                 } else {
201                         pAC->Hwt.TStop = pAC->Hwt.TStart - TRead ;
202                 }
203         }
204         return (pAC->Hwt.TStop) ;
205 }
206
207 /*
208  * interrupt source= timer
209  */
210 void    SkHwtIsr(
211 SK_AC   *pAC,   /* Adapters context */
212 SK_IOC  Ioc)    /* IoContext */
213 {
214         SkHwtStop(pAC,Ioc);
215         pAC->Hwt.TStop = pAC->Hwt.TStart;
216         SkTimerDone(pAC,Ioc) ;
217 }
218 /* End of file */