📄 dm9000.c
字号:
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);
//iow(db, 0x00, 0x01); /* Enable TX/RX interrupt mask */
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;
net_set_mac();
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))
{
return -EBUSY;
}
/* Set the device copy of the Ethernet address */
memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
for(i = 0; i < 6; i++)
{
MyMacID[i] = mac_addr->sa_data[i];
}
device_init(dev);
return 0;
}
static int net_set_mac()
{
FLASH_CONFIG_SECTOR_S configdata;
read_config_data_from_exflash(&configdata);
if(configdata.config_init_flag == 1)
{
memcpy(&(MyMacID[0]),&(configdata.vrs_mac_addr[0]),6);
}
return 0;
}
/*********************************************************************************************************
** Function name: net_tx
** Descriptions: send data to other machine
** Input: skb: save data for send
** dev: information of device
** Output: 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int net_tx(struct sk_buff *skb, struct net_device *dev)
{
unsigned long flag;
int len;
u16 *data;
board_info_t *db = dev->priv;
netif_stop_queue(dev);
len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len;
data = (u16 *)skb->data;
len = (len + 1) & (~1);
local_irq_save(flag);
iow(db, 0xff, 0x80);
outb(0xf8, db->ioaddr);
outsw(db->io_data, data, len >> 1);
iow(db, 0xfc, len & 0xff);
iow(db, 0xfd, (len >> 8) & 0xff);
iow(db, 0x2, 0x1); /* Cleared after TX complete */
/* Re-enable interrupt*/
iow(db, 0xff, 0x83);
dev->trans_start = jiffies;
local_irq_restore(flag);
dev_kfree_skb(skb);
return 0; /* Our simple device can not fail */
}
/*********************************************************************************************************
** Function name: net_open
** Descriptions: open device
** Input: dev: information of device
**
** Output: 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int net_open(struct net_device *dev)
{
unsigned long flag;
u32 temp;
int i;
int lResult;
board_info_t *db = dev->priv;
if (usage == 0)
{
local_irq_save(flag);
//temp = inl(PINSEL0);
//PinSel0Save = temp & (0x0f << (8 * 2));
//temp |= (3 << (7 * 2));
//temp &= ~(3 << (8 * 2));
//outl(temp, PINSEL0);
PINSEL0 |= (3 << (7 * 2));
//temp = inl(IO0DIR);
//temp |= 1 << 6;
//outl(temp, IO0DIR);
IO0DIR |= 0x00000040;
//outl(1 << 6, IO0CLR);
IO0CLR |= 0x00000040;
//DM9000A_init();
device_init(dev);
//temp = inl(VPBDIV);
//temp = inl(VPBDIV);
temp = VPBDIV;
temp = VPBDIV;
VPBDIV = 0;
//outl(inl(EXTMODE) | (1 << 2), EXTMODE);
EXTMODE = 0x0;
//printk(KERN_ERR "EXTMODE = %08x\n",EXTMODE);
//outl(0, VPBDIV);
//outl(inl(EXTPOLAR) & (~(1 << 2)), EXTPOLAR);
EXTPOLAR = 0x4;
//printk(KERN_ERR "EXTPOLAR = %08x\n",EXTPOLAR);
VPBDIV = temp;
//outl(temp, VPBDIV);
local_irq_restore(flag);
lResult = request_irq(dev->irq, net_irq_handle, SA_INTERRUPT | SA_SAMPLE_RANDOM , "eth0", dev);
}
usage++;
netif_start_queue(dev);
//net_tx(&sk_buf,dev);
return 0; /* success */
}
/*********************************************************************************************************
** Function name: net_release
** Descriptions: release device
** Input: dev: information of device
**
** Output: 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-05-12
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int net_release(struct net_device *dev)
{
unsigned long flag;
u32 temp;
netif_stop_queue(dev);
usage = 0;
//usage--;
//if (usage == 0)
//{
// local_irq_save(flag);
// temp = inl(PINSEL0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -