]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/net/sk98lin/skgehwt.c
85xx: Drop FIT support to allow u-boot image to fit in 512k
[people/ms/u-boot.git] / drivers / net / sk98lin / skgehwt.c
CommitLineData
7152b1d0
WD
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.
42d1f039 32 *
7152b1d0
WD
33 * Revision 1.12 1998/10/15 15:11:34 gklug
34 * fix: ID_sccs to SysKonnectFileId
42d1f039 35 *
7152b1d0
WD
36 * Revision 1.11 1998/10/08 15:27:51 gklug
37 * chg: correction factor is host clock dependent
42d1f039 38 *
7152b1d0
WD
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
42d1f039 44 *
7152b1d0
WD
45 * Revision 1.8 1998/08/24 13:04:44 gklug
46 * fix: typo
42d1f039 47 *
7152b1d0
WD
48 * Revision 1.7 1998/08/19 09:50:49 gklug
49 * fix: remove struct keyword from c-code (see CCC) add typedefs
42d1f039 50 *
7152b1d0
WD
51 * Revision 1.6 1998/08/17 09:59:02 gklug
52 * fix: typos
42d1f039 53 *
7152b1d0
WD
54 * Revision 1.5 1998/08/14 07:09:10 gklug
55 * fix: chg pAc -> pAC
42d1f039 56 *
7152b1d0
WD
57 * Revision 1.4 1998/08/10 14:14:52 gklug
58 * rmv: unneccessary SK_ADDR macro
42d1f039 59 *
7152b1d0
WD
60 * Revision 1.3 1998/08/07 12:53:44 gklug
61 * fix: first compiled version
42d1f039 62 *
7152b1d0
WD
63 * Revision 1.2 1998/08/07 09:19:29 gklug
64 * adapt functions to the C coding conventions
65 * rmv unneccessary functions.
42d1f039 66 *
7152b1d0
WD
67 * Revision 1.1 1998/08/05 11:28:36 gklug
68 * first version: adapted from SMT/FDDI
42d1f039
WD
69 *
70 *
71 *
7152b1d0
WD
72 *
73 ******************************************************************************/
74
75
149dded2
WD
76#include <config.h>
77
7152b1d0
WD
78/*
79 Event queue and dispatcher
80*/
81static 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 */
94intro()
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 */
111void SkHwtInit(
112SK_AC *pAC, /* Adapters context */
113SK_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 */
127void SkHwtStart(
128SK_AC *pAC, /* Adapters context */
129SK_IOC Ioc, /* IoContext */
130SK_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 */
160void SkHwtStop(
161SK_AC *pAC, /* Adapters context */
162SK_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 */
178SK_U32 SkHwtRead(
179SK_AC *pAC, /* Adapters context */
180SK_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 */
207void SkHwtIsr(
208SK_AC *pAC, /* Adapters context */
209SK_IOC Ioc) /* IoContext */
210{
211 SkHwtStop(pAC,Ioc);
212 pAC->Hwt.TStop = pAC->Hwt.TStart;
213 SkTimerDone(pAC,Ioc) ;
214}
7152b1d0 215/* End of file */