📄 dm9000.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: dm9000.c
** Last modified Date: 2005-05-12
** Last Version: 1.0
** Descriptions: This is a Kernel module for uClinux 2.4.x .
** This module let uClinux 2.4.x can use rtl8019.
**------------------------------------------------------------------------------------------------------
** Created by: Chenmingji
** Created date: 2005-05-12
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#define IN_DM9000
#include "config.h"
#include "dm9000.h"
#include "externflashdev.h"
/********************************************************************************************************
function announce
********************************************************************************************************/
#define DM9KS_ID 0x90000A46
#define DM9010_ID 0x90100A46
#define DM9KS_VID_L 0x28
#define DM9KS_VID_H 0x29
#define DM9KS_PID_L 0x2A
#define DM9KS_PID_H 0x2B
static int net_init(struct net_device *dev);
static int net_open(struct net_device *dev);
static int net_release(struct net_device *dev);
static int net_config(struct net_device *dev, struct ifmap *map);
static int net_tx(struct sk_buff *skb, struct net_device *dev);
static int net_irq_handle(int irq, void *dev_id, struct pt_regs *regs);
static int net_set_mac_address(struct net_device *dev, void *addr);
static int net_set_mac();
int net_init_module(void);
void net_cleanup(void);
int initflag = 0;
static void net_tasklet(unsigned long);
/********************************************************************************************************
define announce
********************************************************************************************************/
static struct net_device *DM9000Dev;
module_init(net_init_module);
module_exit(net_cleanup);
DECLARE_TASKLET(ZLG_net_tasklet, net_tasklet, (unsigned long)(&DM9000Dev));
MODULE_LICENSE("Proprietary");
MODULE_DESCRIPTION("Guangzou ZLG-MCU Development Co.,LTD.\ngraduate school\nhttp://www.zlgmcu.com");
MODULE_SUPPORTED_DEVICE("uClinux2.4.x LPC2200 DM9000");
MODULE_AUTHOR("chenmingji");
/*********************************************************************************************************
** "全局和静态变量在这里定义"
** global variables and static variables define here
********************************************************************************************************/
static unsigned int usage;
static u32 PinSel0Save;
static board_info_t NetDriverInfo[1];
/********************************************************************************************************/
static struct net_device net_net =
{
name: "eth0",
init: net_init,
base_addr: IOaddress0,
irq: NET_IRQ,
watchdog_timeo: NET_TIMEOUT,
};
#include "externflashdev.c"
/*********************************************************************************************************
** Function name: ior
**
** Descriptions: read a reg form dm9000
**
** input parameters: board_info_t *db ;dm9000 status struct
** reg ;reg address of dm9000
** Returned value: uint8 ;reg value
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static uint8 ior(board_info_t *db, uint8 reg)
{
unsigned int i;
unsigned int rt;
outb(reg, db->ioaddr);
for (i = 0; i < BUS_DELAY; i++)
{
}
rt = inb(db->io_data);
for (i = 0; i < BUS_DELAY; i++)
{
}
return rt;
}
/*********************************************************************************************************
** Function name: iow
**
** Descriptions: write a value to a dm9000 reg
**
** input parameters: board_info_t *db ;dm9000 status struct
** reg ;reg address of dm9000
** value ;reg value
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void iow(board_info_t *db, uint8 reg, uint8 value)
{
unsigned int i;
outb(reg, db->ioaddr);
for(i = 0; i<BUS_DELAY; i++)
{
}
outb(value, db->io_data);
for(i = 0; i<BUS_DELAY; i++)
{
}
}
/*********************************************************************************************************
** Function name: phy_write
**
** Descriptions: write a value to PHY device reg
**
** input parameters: board_info_t *db ;dm9000 status struct
** reg ;reg address of PHY device
** value ;reg value
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void phy_write(board_info_t *db, uint8 reg, uint16 value)
{
/* Fill the phyxcer register into REG_0C */
iow(db, 0xc, DM9000_PHY | reg);
/* Fill the written data into REG_0D & REG_0E */
iow(db, 0xd, (value & 0xff));
iow(db, 0xe, ( (value >> 8) & 0xff));
iow(db, 0xb, 0xa); /* Issue phyxcer write command */
udelay(500); /* Wait write complete */
iow(db, 0xb, 0x0); /* Clear phyxcer write command */
}
/*********************************************************************************************************
** Function name: set_PHY_mode
**
** Descriptions: set the PHY device working
**
** input parameters: board_info_t *db ;dm9000 status struct
**
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2004/02/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void set_PHY_mode(board_info_t *db)
{
unsigned int phy_reg4 = 0x01e1, phy_reg0=0x1000;
iow(db,0x1f,0x01); /* must powerdown phy first */
if ( !(db->op_mode & DM9000_AUTO))
{
switch(db->op_mode)
{
case DM9000_10MHD:
phy_reg4 = 0x21; /* 10M HALF DUPLEX*/
phy_reg0 = 0x0000;
break;
case DM9000_10MFD:
phy_reg4 = 0x41; /* 10M FULL DUPLEX*/
phy_reg0 = 0x1100;
break;
case DM9000_100MHD:
phy_reg4 = 0x81; /* 100M HALF DUPLEX*/
phy_reg0 = 0x2000;
break;
case DM9000_100MFD:
phy_reg4 = 0x101;/* 100M HALF DUPLEX */
phy_reg0 =0x3100;
break;
default:
break;
}
}
phy_write(db, 4, phy_reg4); /* Set PHY media mode */
phy_write(db, 0, phy_reg0); /* Tmp */
iow(db, 0x1e, 0x01); /* Let GPIO0 output */
iow(db, 0x1f, 0x00); /* Enable PHY */
}
/*********************************************************************************************************
** Function name: device_init
** Descriptions: device init
** Input: dev: information of device
**
** Output: 0: OK
** other: errno
** Created by: Chenmingji
** Created Date: 2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int device_init(struct net_device *dev)
{
unsigned long flag;
uint8 i;
uint32 ulData;
board_info_t *db = dev->priv;
local_irq_save(flag);
/* 硬件复位复位 */
//Hardware_Initial0();
//PINSEL0 |= 0x0000c000;
//IO0DIR = IO0DIR | 0x00000040;
IO0DIR |= 0x40;
db->ioaddr = IOaddress0;
db->io_data = IOaddress0 + 0x00400000;
/* RESET device */
/*Hardware Reset*/
IO0SET |= 0x00000040;/*Hardware_Reset_Set0();*/
udelay(500);
IO0CLR |= 0x00000040;/*Hardware_Reset_Clr0();*/
udelay(500);
IO0SET |= 0x00000040;/*Hardware_Reset_Set0();*/
udelay(500);
/*software reset*/
iow(db, 0, 1);
udelay(500); /* delay 100us */
/* I/O mode */
db->io_mode = ior(db, 0xfe) >> 6; /* ISR bit7:6 keeps I/O mode *///read the io mode (8/16/32bits)
/* NIC Type: FASTETHER, HOMERUN, LONGRUN */
db->nic_type = FASTETHER_NIC; //identify_nic(db); //just check for dm9801 or dm9802
/* GPIO0 on pre-activate PHY */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -