1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * (C)Copyright 1998,1999 SysKonnect,
5 * a business unit of Schneider & Koch & Co. Datensysteme GmbH.
7 * See the file "skfddi.c" for further information.
9 * The information in this file is provided "AS IS" without warranty.
11 ******************************************************************************/
14 * Timer Driver for FBI board (timer chip 82C54)
20 * 28-Jun-1994 sw Edit v1.6.
21 * MCA: Added support for the SK-NET FDDI-FM2 adapter. The
22 * following functions have been added(+) or modified(*):
23 * hwt_start(*), hwt_stop(*), hwt_restart(*), hwt_read(*)
31 static const char ID_sccs
[] = "@(#)hwt.c 1.13 97/04/23 (C) SK " ;
35 * Prototypes of local functions.
37 /* 28-Jun-1994 sw - Note: hwt_restart() is also used in module 'drvfbi.c'. */
38 /*static void hwt_restart() ; */
40 /************************
44 * Start hardware timer (clock ticks are 16us).
50 * smc - A pointer to the SMT Context structure.
52 * time - The time in units of 16us to load the timer with.
56 ************************/
57 #define HWT_MAX (65000)
59 void hwt_start(struct s_smc
*smc
, u_long time
)
66 smc
->hw
.t_start
= time
;
77 outpd(ADDR(B2_TI_INI
), (u_long
) cnt
* 200) ; /* Load timer value. */
78 outpw(ADDR(B2_TI_CRTL
), TIM_START
) ; /* Start timer. */
80 smc
->hw
.timer_activ
= TRUE
;
83 /************************
87 * Stop hardware timer.
90 * struct s_smc *smc) ;
92 * smc - A pointer to the SMT Context structure.
96 ************************/
97 void hwt_stop(struct s_smc
*smc
)
99 outpw(ADDR(B2_TI_CRTL
), TIM_STOP
) ;
100 outpw(ADDR(B2_TI_CRTL
), TIM_CL_IRQ
) ;
102 smc
->hw
.timer_activ
= FALSE
;
105 /************************
109 * Initialize hardware timer.
112 * struct s_smc *smc) ;
114 * smc - A pointer to the SMT Context structure.
118 ************************/
119 void hwt_init(struct s_smc
*smc
)
121 smc
->hw
.t_start
= 0 ;
123 smc
->hw
.timer_activ
= FALSE
;
128 /************************
132 * Clear timer interrupt.
135 * struct s_smc *smc) ;
137 * smc - A pointer to the SMT Context structure.
141 ************************/
142 void hwt_restart(struct s_smc
*smc
)
147 /************************
151 * Stop hardware timer and read time elapsed since last start.
153 * u_long hwt_read(smc) ;
155 * smc - A pointer to the SMT Context structure.
157 * The elapsed time since last start in units of 16us.
159 ************************/
160 u_long
hwt_read(struct s_smc
*smc
)
165 if (smc
->hw
.timer_activ
) {
167 tr
= (u_short
)((inpd(ADDR(B2_TI_VAL
))/200) & 0xffff) ;
170 /* Check if timer expired (or wraparound). */
171 if ((tr
> smc
->hw
.t_start
) || (is
& IS_TIMINT
)) {
173 smc
->hw
.t_stop
= smc
->hw
.t_start
;
176 smc
->hw
.t_stop
= smc
->hw
.t_start
- tr
;
178 return smc
->hw
.t_stop
;
182 /************************
186 * Stop hardware timer and read timer value and start the timer again.
188 * u_long hwt_read(smc) ;
190 * smc - A pointer to the SMT Context structure.
192 * current timer value in units of 80ns.
194 ************************/
195 u_long
hwt_quick_read(struct s_smc
*smc
)
200 interval
= inpd(ADDR(B2_TI_INI
)) ;
201 outpw(ADDR(B2_TI_CRTL
), TIM_STOP
) ;
202 time
= inpd(ADDR(B2_TI_VAL
)) ;
203 outpd(ADDR(B2_TI_INI
),time
) ;
204 outpw(ADDR(B2_TI_CRTL
), TIM_START
) ;
205 outpd(ADDR(B2_TI_INI
),interval
) ;
210 /************************
212 * hwt_wait_time(smc,start,duration)
214 * This function returnes after the amount of time is elapsed
215 * since the start time.
217 * para start start time
218 * duration time to wait
220 * NOTE: The function will return immediately, if the timer is not
222 ************************/
223 void hwt_wait_time(struct s_smc
*smc
, u_long start
, long int duration
)
230 * check if timer is running
232 if (smc
->hw
.timer_activ
== FALSE
||
233 hwt_quick_read(smc
) == hwt_quick_read(smc
)) {
237 interval
= inpd(ADDR(B2_TI_INI
)) ;
238 if (interval
> duration
) {
240 diff
= (long)(start
- hwt_quick_read(smc
)) ;
244 } while (diff
<= duration
) ;
251 if (hwt_quick_read(smc
) >= start
) {
257 if (hwt_quick_read(smc
) < start
) {
261 } while (diff
<= duration
) ;