1
0
uboot-1.1.4-kirkwood/drivers/sk98lin/skgehwt.c

172 lines
3.5 KiB
C
Raw Permalink Normal View History

2024-01-07 23:57:24 +01:00
/******************************************************************************
*
* Name: skgehwt.c
2024-01-09 13:41:15 +01:00
* Project: Gigabit Ethernet Adapters, Event Scheduler Module
* Version: $Revision: 2.2 $
* Date: $Date: 2004/05/28 13:39:04 $
* Purpose: Hardware Timer
2024-01-07 23:57:24 +01:00
*
******************************************************************************/
/******************************************************************************
*
2024-01-09 13:41:15 +01:00
* (C)Copyright 1998-2002 SysKonnect GmbH.
* (C)Copyright 2002-2004 Marvell.
2024-01-07 23:57:24 +01:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The information in this file is provided "AS IS" without warranty.
*
******************************************************************************/
#include <config.h>
2024-01-09 13:41:15 +01:00
2024-01-07 23:57:24 +01:00
#ifdef CONFIG_SK98
/*
2024-01-09 13:41:15 +01:00
* Event queue and dispatcher
*/
#if (defined(DEBUG) || ((!defined(LINT)) && (!defined(SK_SLIM))))
2024-01-07 23:57:24 +01:00
static const char SysKonnectFileId[] =
2024-01-09 13:41:15 +01:00
"@(#) $Id: skgehwt.c,v 2.2 2004/05/28 13:39:04 rschmidt Exp $ (C) Marvell.";
#endif
2024-01-07 23:57:24 +01:00
#include "h/skdrv1st.h" /* Driver Specific Definitions */
#include "h/skdrv2nd.h" /* Adapter Control- and Driver specific Def. */
#ifdef __C2MAN__
/*
2024-01-09 13:41:15 +01:00
* Hardware Timer function queue management.
2024-01-07 23:57:24 +01:00
*/
intro()
{}
#endif
/*
* Prototypes of local functions.
*/
2024-01-09 13:41:15 +01:00
#define SK_HWT_MAX 65000UL * 160 /* ca. 10 sec. */
2024-01-07 23:57:24 +01:00
/* correction factor */
2024-01-09 13:41:15 +01:00
#define SK_HWT_FAC (10 * (SK_U32)pAC->GIni.GIHstClkFact / 16)
2024-01-07 23:57:24 +01:00
/*
* Initialize hardware timer.
*
* Must be called during init level 1.
*/
void SkHwtInit(
SK_AC *pAC, /* Adapters context */
SK_IOC Ioc) /* IoContext */
{
pAC->Hwt.TStart = 0 ;
pAC->Hwt.TStop = 0 ;
2024-01-09 13:41:15 +01:00
pAC->Hwt.TActive = SK_FALSE;
2024-01-07 23:57:24 +01:00
2024-01-09 13:41:15 +01:00
SkHwtStop(pAC, Ioc);
2024-01-07 23:57:24 +01:00
}
/*
*
* Start hardware timer (clock ticks are 16us).
*
*/
void SkHwtStart(
SK_AC *pAC, /* Adapters context */
SK_IOC Ioc, /* IoContext */
2024-01-09 13:41:15 +01:00
SK_U32 Time) /* Time in usec to load the timer */
2024-01-07 23:57:24 +01:00
{
if (Time > SK_HWT_MAX)
2024-01-09 13:41:15 +01:00
Time = SK_HWT_MAX;
2024-01-07 23:57:24 +01:00
2024-01-09 13:41:15 +01:00
pAC->Hwt.TStart = Time;
pAC->Hwt.TStop = 0L;
2024-01-07 23:57:24 +01:00
2024-01-09 13:41:15 +01:00
if (!Time) {
Time = 1L;
2024-01-07 23:57:24 +01:00
}
2024-01-09 13:41:15 +01:00
SK_OUT32(Ioc, B2_TI_INI, Time * SK_HWT_FAC);
SK_OUT16(Ioc, B2_TI_CTRL, TIM_START); /* Start timer */
2024-01-07 23:57:24 +01:00
2024-01-09 13:41:15 +01:00
pAC->Hwt.TActive = SK_TRUE;
2024-01-07 23:57:24 +01:00
}
/*
* Stop hardware timer.
* and clear the timer IRQ
*/
void SkHwtStop(
SK_AC *pAC, /* Adapters context */
SK_IOC Ioc) /* IoContext */
{
2024-01-09 13:41:15 +01:00
SK_OUT16(Ioc, B2_TI_CTRL, TIM_STOP);
2024-01-07 23:57:24 +01:00
2024-01-09 13:41:15 +01:00
SK_OUT16(Ioc, B2_TI_CTRL, TIM_CLR_IRQ);
2024-01-07 23:57:24 +01:00
2024-01-09 13:41:15 +01:00
pAC->Hwt.TActive = SK_FALSE;
}
2024-01-07 23:57:24 +01:00
/*
* Stop hardware timer and read time elapsed since last start.
*
* returns
* The elapsed time since last start in units of 16us.
*
*/
SK_U32 SkHwtRead(
SK_AC *pAC, /* Adapters context */
SK_IOC Ioc) /* IoContext */
{
2024-01-09 13:41:15 +01:00
SK_U32 TRead;
SK_U32 IStatus;
SK_U32 TimerInt;
TimerInt = CHIP_ID_YUKON_2(pAC) ? Y2_IS_TIMINT : IS_TIMINT;
2024-01-07 23:57:24 +01:00
if (pAC->Hwt.TActive) {
2024-01-09 13:41:15 +01:00
SkHwtStop(pAC, Ioc);
2024-01-07 23:57:24 +01:00
SK_IN32(Ioc, B2_TI_VAL, &TRead);
TRead /= SK_HWT_FAC;
SK_IN32(Ioc, B0_ISRC, &IStatus);
2024-01-09 13:41:15 +01:00
/* Check if timer expired (or wrapped around) */
if ((TRead > pAC->Hwt.TStart) || ((IStatus & TimerInt) != 0)) {
SkHwtStop(pAC, Ioc);
pAC->Hwt.TStop = pAC->Hwt.TStart;
}
else {
pAC->Hwt.TStop = pAC->Hwt.TStart - TRead;
2024-01-07 23:57:24 +01:00
}
}
2024-01-09 13:41:15 +01:00
return(pAC->Hwt.TStop);
2024-01-07 23:57:24 +01:00
}
/*
* interrupt source= timer
*/
void SkHwtIsr(
SK_AC *pAC, /* Adapters context */
SK_IOC Ioc) /* IoContext */
{
2024-01-09 13:41:15 +01:00
SkHwtStop(pAC, Ioc);
2024-01-07 23:57:24 +01:00
pAC->Hwt.TStop = pAC->Hwt.TStart;
2024-01-09 13:41:15 +01:00
SkTimerDone(pAC, Ioc);
}
2024-01-07 23:57:24 +01:00
/* End of file */
2024-01-09 13:41:15 +01:00
#endif