⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stethernet118.c

📁 Lan9118以太网芯片linux驱动程序
💻 C
字号:
/*****************************************************************************
   
Copyright (c) 2004-2005, SMSC
 
This code and information is provided as is without warranty of any kind,
either expressed or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.
 
File name   :  stethernet118.c  

Description :  Interface code for stpvr2 environment.

Date            Modification                	Name        	
----            ------------                	-------				
18/02/05	Initial release V1.16		Phong Le
*****************************************************************************/

/* constants and macros used in this driver */
#define LAN9118_REG_BASE      0x60000000
#define LAN9118_IRQN          48
#define LAN9118_INT_LEVEL     9
#define LAN9118_INT_MODE      interrupt_trigger_mode_low_level

#define LAN9118_DRVNAME smsclan9118

/* STMicro board constant */
#define	EMIBASEADDR		0x20200000UL
 #define 	EMI_CFGDATA0_B2	0x0180UL
 #define 	EMI_CFGDATA1_B2	0x0188UL
 #define 	EMI_CFGDATA2_B2	0x0190UL
 #define 	EMI_CFGDATA3_B2	0x0198UL

#define	DCACHEBASEADDR	0x30005000UL
 #define 	CACHE_R3BLK_EN	0x38UL

int ngOSIsrAttach9118 (const int irno, void (*handler_f)(void *), void *data);
int ngOSIsrDetach9118 (const int irno);

void st_write_dw (const unsigned long base, const unsigned long offset, const unsigned long data);
void PlatformSetBusTiming (const unsigned long dwIdRev);

void st_write_dw (const unsigned long base, const unsigned long offset, const unsigned long data)
{
	*(unsigned long *) (base + offset) = data;
}

void PlatformSetBusTiming (const unsigned long dwIdRev)
{
	if ((dwIdRev == 0x0118UL) || (dwIdRev == 0x0117UL)) {
	  /* set timing on bank 2 for ethernet access for 118/117 */
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA0_B2, 0x001116f1UL);
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA1_B2, 0x05111121UL);
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA2_B2, 0x05112222UL);
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA3_B2, 0x0000000aUL);
	}
	else if ((dwIdRev == 0x0116UL) || (dwIdRev == 0x0115UL)) {
	  /* set timing on bank 2 for ethernet access for 116/115 */
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA0_B2, 0x001116f1UL);
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA1_B2, 0x0a111121UL);
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA2_B2, 0x0a112222UL);
	  st_write_dw (EMIBASEADDR, EMI_CFGDATA3_B2, 0x0000000aUL);
	}
	else
	{
	  return;
	}
			
	/* turn on data cache for address 0x4000 0000 to 0x407F FFFF */
	st_write_dw (DCACHEBASEADDR, CACHE_R3BLK_EN, 0x0000FFFFUL);
}

#define PHY_ADDR	0xffffffffUL
#define OS_TEXT_OUT	debugmessage

/* constant for eif_linkadv */
#define NG_ETHIF_AUTONEG_10BASET          0x0001
#define NG_ETHIF_AUTONEG_10BASET_FD       0x0002
#define NG_ETHIF_AUTONEG_100BASETX        0x0004
#define NG_ETHIF_AUTONEG_100BASETX_FD     0x0008

/* constant for eif_linkcfg and eif_link */
#define NG_ETHIF_LINK_DOWN            1   /* link down */
#define NG_ETHIF_LINK_10BASET         4   /* 10BASE-T half duplex */
#define NG_ETHIF_LINK_10BASET_FD      5   /* 10BASE-T full duplex */
#define NG_ETHIF_LINK_100BASETX       6   /* 100BASE-TX half duplex */
#define NG_ETHIF_LINK_100BASETX_FD    7   /* 100BASE-TX full duplex */

/* constant for eif_flags */
#if 0
#define NG_ETHIFF_FULLDUPLEX  0x0001    /* force full-duplex mode - DEPRECATED */
#define NG_ETHIFF_10BASET     0x0002    /* select 10BASET output - DEPRECATED */
#define NG_ETHIFF_10BASE2     0x0004    /* select 10BASE2 output - DEPRECATED */
#define NG_ETHIFF_100BASETX   0x0008    /* select 100BASETX output - DEPRECATED */
#endif
#define NG_ETHIFF_AUTONEG     0x0010	/* select auto negotiate */

#define LAN9118_SOURCE
// lint -e960	Violates MISRA Required Rule 87, only preprocessor statements and comments before '#include'
/*lint -save*/
/*lint -e960*/
#include "lan9118.c"
/*lint -restore*/

/* returns member variable 'eif_linkadv' within driver structure */
NGushort GetLinkAdv (const NGifnet * const netp)
{
	if (netp->if_devptr1)
	{
		return ((PLAN9118_DATA) netp->if_devptr1)->eif_linkadv;
	}
	else
	{
		return (NGushort) 0;
	}
}

/* sets member variable 'eif_linkadv' within driver structure */
void SetLinkAdv (const NGifnet * const netp, const NGushort value)
{
	if (netp->if_devptr1)
	{
		((PLAN9118_DATA) netp->if_devptr1)->eif_linkadv = value;
	}
}

/* returns member variable 'eif_linkcfg' within driver structure */
NGubyte GetLinkCfg (const NGifnet * const netp)
{
	if (netp->if_devptr1)
	{
		return ((PLAN9118_DATA) netp->if_devptr1)->eif_linkcfg;
	}
	else
	{
		return (NGubyte) 0;
	}
}

/* sets member variable 'eif_linkcfg' within driver structure */
void SetLinkCfg (const NGifnet * const netp, const NGubyte value)
{
	if (netp->if_devptr1)
	{
		((PLAN9118_DATA) netp->if_devptr1)->eif_linkcfg = value;
	}
}

/* returns member variable 'eif_link' within driver structure */
NGubyte GetLink (const NGifnet * const netp)
{
	if (netp->if_devptr1)
	{
		return ((PLAN9118_DATA) netp->if_devptr1)->eif_link;
	}
	else
	{
		return (NGubyte) 0;
	}
}

/* sets member variable 'eif_link' within driver structure */
void SetLink (const NGifnet * const netp, const NGubyte value)
{
	if (netp->if_devptr1)
	{
		((PLAN9118_DATA) netp->if_devptr1)->eif_link = value;
	}
}

static NGubyte isr_stack [1024];

int ngOSIsrAttach9118 (const int irno, void (*handler_f)(void *), void *data)
{
  /* support for DB558 / Ethernet only */
  if( irno == LAN9118_IRQN) {
    /* initialise the interrupt */
    interrupt_init (LAN9118_INT_LEVEL, isr_stack, sizeof(isr_stack), LAN9118_INT_MODE, interrupt_flags_low_priority);
  
    /* install the DB558 interrupt handler */
    interrupt_install (LAN9118_IRQN, LAN9118_INT_LEVEL, handler_f, data);
  
    /* enable the interrupt */
    interrupt_enable_number (LAN9118_IRQN);
  
    interrupt_enable_mask (1 << LAN9118_INT_LEVEL);

    return NG_EOK;
  }
  else {
    return NG_EINVAL;
  }
}

int ngOSIsrDetach9118 (const int irno)
{
  /* support for DB558 / Ethernet only */
  if( irno == LAN9118_IRQN) {
    /* disable the interrupts */
    interrupt_disable_number (LAN9118_IRQN);
  
    /* uninstall the interrupt */
    interrupt_uninstall (LAN9118_IRQN, LAN9118_INT_LEVEL);
  
    return NG_EOK;
  }
  else {
    return NG_EINVAL;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -