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 * Prototypes of local functions.
33 /* 28-Jun-1994 sw - Note: hwt_restart() is also used in module 'drvfbi.c'. */
34 /*static void hwt_restart() ; */
36 /************************
40 * Start hardware timer (clock ticks are 16us).
46 * smc - A pointer to the SMT Context structure.
48 * time - The time in units of 16us to load the timer with.
52 ************************/
53 #define HWT_MAX (65000)
55 void hwt_start(struct s_smc *smc, u_long time)
62 smc->hw.t_start = time ;
73 outpd(ADDR(B2_TI_INI), (u_long) cnt * 200) ; /* Load timer value. */
74 outpw(ADDR(B2_TI_CRTL), TIM_START) ; /* Start timer. */
76 smc->hw.timer_activ = TRUE ;
79 /************************
83 * Stop hardware timer.
86 * struct s_smc *smc) ;
88 * smc - A pointer to the SMT Context structure.
92 ************************/
93 void hwt_stop(struct s_smc *smc)
95 outpw(ADDR(B2_TI_CRTL), TIM_STOP) ;
96 outpw(ADDR(B2_TI_CRTL), TIM_CL_IRQ) ;
98 smc->hw.timer_activ = FALSE ;
101 /************************
105 * Initialize hardware timer.
108 * struct s_smc *smc) ;
110 * smc - A pointer to the SMT Context structure.
114 ************************/
115 void hwt_init(struct s_smc *smc)
117 smc->hw.t_start = 0 ;
119 smc->hw.timer_activ = FALSE ;
124 /************************
128 * Clear timer interrupt.
131 * struct s_smc *smc) ;
133 * smc - A pointer to the SMT Context structure.
137 ************************/
138 void hwt_restart(struct s_smc *smc)
143 /************************
147 * Stop hardware timer and read time elapsed since last start.
149 * u_long hwt_read(smc) ;
151 * smc - A pointer to the SMT Context structure.
153 * The elapsed time since last start in units of 16us.
155 ************************/
156 u_long hwt_read(struct s_smc *smc)
161 if (smc->hw.timer_activ) {
163 tr = (u_short)((inpd(ADDR(B2_TI_VAL))/200) & 0xffff) ;
166 /* Check if timer expired (or wraparound). */
167 if ((tr > smc->hw.t_start) || (is & IS_TIMINT)) {
169 smc->hw.t_stop = smc->hw.t_start ;
172 smc->hw.t_stop = smc->hw.t_start - tr ;
174 return smc->hw.t_stop;
178 /************************
182 * Stop hardware timer and read timer value and start the timer again.
184 * u_long hwt_read(smc) ;
186 * smc - A pointer to the SMT Context structure.
188 * current timer value in units of 80ns.
190 ************************/
191 u_long hwt_quick_read(struct s_smc *smc)
196 interval = inpd(ADDR(B2_TI_INI)) ;
197 outpw(ADDR(B2_TI_CRTL), TIM_STOP) ;
198 time = inpd(ADDR(B2_TI_VAL)) ;
199 outpd(ADDR(B2_TI_INI),time) ;
200 outpw(ADDR(B2_TI_CRTL), TIM_START) ;
201 outpd(ADDR(B2_TI_INI),interval) ;
206 /************************
208 * hwt_wait_time(smc,start,duration)
210 * This function returnes after the amount of time is elapsed
211 * since the start time.
213 * para start start time
214 * duration time to wait
216 * NOTE: The function will return immediately, if the timer is not
218 ************************/
219 void hwt_wait_time(struct s_smc *smc, u_long start, long int duration)
226 * check if timer is running
228 if (smc->hw.timer_activ == FALSE ||
229 hwt_quick_read(smc) == hwt_quick_read(smc)) {
233 interval = inpd(ADDR(B2_TI_INI)) ;
234 if (interval > duration) {
236 diff = (long)(start - hwt_quick_read(smc)) ;
240 } while (diff <= duration) ;
247 if (hwt_quick_read(smc) >= start) {
253 if (hwt_quick_read(smc) < start) {
257 } while (diff <= duration) ;