📄 dm9000.c
字号:
/****************************************Copyright (c)**************************************************
** Guangzou ZLG-MCU Development Co.,LTD.
** graduate school
** http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name: rtl8019.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"/********************************************************************************************************
function announce********************************************************************************************************/
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 void net_irq_handle(int irq, void *dev_id, struct pt_regs *regs);
static int net_set_mac_address(struct net_device *dev, void *addr);int net_init_module(void);void net_cleanup(void);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,};
/*********************************************************************************************************
** 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;
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;
board_info_t *db = dev->priv;
local_irq_save(flag);
/* 硬件复位复位 */
Hardware_Initial0();
db->ioaddr = IOaddress0;
db->io_data = IOaddress0 + 4;
/* RESET device */
/*Hardware Reset*/
Hardware_Reset_Clr0();
udelay(500);
Hardware_Reset_Set0();
udelay(500);
Hardware_Reset_Clr0();
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 */
iow(db, 0x1f, 0x00); /*REG_1F bit0 activate internal phyxcer*/
/* Set PHY */
db->op_mode = DM9000_AUTO;//may set it to be each one of DM9000_PHY_mode type.
set_PHY_mode(db);
/* Init needed register value */
db->reg0 = DM9000_REG00;
if ((db->nic_type != FASTETHER_NIC) && (db->op_mode & DM9000_1M_HPNA) )//for dm9801 or dm9802
{
db->reg0 |= DM9000_EXT_MII;
}
/* User passed argument */
db->reg5 = DM9000_REG05;
db->reg8 = DM9000_REG08;
db->reg9 = DM9000_REG09;
db->rega = DM9000_REG0A;
/* Program operating register */
iow(db, 0x00, db->reg0);/* DISCARD LONG\CRC_ERR\mutilcast\Promiscuous\WatchDog,Pass Runt,RX not enable */
iow(db, 0x02, 0X14); /* TX Polling clear *///??????????????enable the PAD //OLD VALUE IS 0X00
iow(db, 0x08, 0x3f); /* Less 3Kb, 600us */
iow(db, 0x09, db->reg9); /* Flow Control : High/Low Water */
iow(db, 0x0a, db->rega); /* Flow Control */
iow(db, 0x2f, 0); /* Special Mode */
iow(db, 0x01, 0x2c); /* clear TX status *///clear wakeup status; clear TX2END and TX1END
iow(db, 0xfe, 0x0f); /* Clear interrupt status */
/* Set address filter table */
for(i = 0; i < 6; i++)
{
db->nic_mac[i] = MyMacID[i];
}
for(i = 0; i < 6; i++)
{
iow(db, 0x10 + i, db->nic_mac[i]); //将芯片物理地址写入到MAC寄存器
}
/* Activate DM9000 */
iow(db, 0x05, db->reg5 | 1); /* RX enable */
iow(db, 0xff, DM9000_REGFF); /* Enable TX/RX interrupt mask */
//udelay(5000);
local_irq_restore(flag);
return 0;}
/*********************************************************************************************************
** Function name: net_init
** Descriptions: net 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 net_init(struct net_device *dev){ ether_setup(dev); /* assign some of the fields */ dev->open = net_open; dev->stop = net_release; dev->set_config = net_config; dev->hard_start_xmit = net_tx;
dev->set_mac_address = net_set_mac_address; dev->flags &= ~(IFF_LOOPBACK | IFF_MULTICAST);
dev->priv = NetDriverInfo; memcpy(dev->dev_addr, MyMacID, dev->addr_len); SET_MODULE_OWNER(dev); return 0;}/*********************************************************************************************************
** Function name: net_config
** Descriptions: config device
** Input: dev: information of device
** map: config data
** Output: 0: OK
** other: errno
** Created by: Chenmingji
** Created Date: 2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int net_config(struct net_device *dev, struct ifmap *map){ return -EBUSY;}
/*********************************************************************************************************
** Function name: net_set_mac_address
** Descriptions: set mac address
** Input: dev: information of device
** addr: config data
** Output: 0: OK
** other: errno
** Created by: Chenmingji
** Created Date: 2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int net_set_mac_address(struct net_device *dev, void *addr)
{
struct sockaddr *mac_addr; int i;
mac_addr = addr; if (netif_running(dev))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -