fixed rpi4 eth driver
This commit is contained in:
parent
921f98788e
commit
1641caa378
|
@ -14,7 +14,7 @@ CONFIG_RT_ALIGN_SIZE=4
|
||||||
CONFIG_RT_THREAD_PRIORITY_32=y
|
CONFIG_RT_THREAD_PRIORITY_32=y
|
||||||
# CONFIG_RT_THREAD_PRIORITY_256 is not set
|
# CONFIG_RT_THREAD_PRIORITY_256 is not set
|
||||||
CONFIG_RT_THREAD_PRIORITY_MAX=32
|
CONFIG_RT_THREAD_PRIORITY_MAX=32
|
||||||
CONFIG_RT_TICK_PER_SECOND=100
|
CONFIG_RT_TICK_PER_SECOND=1000
|
||||||
CONFIG_RT_USING_OVERFLOW_CHECK=y
|
CONFIG_RT_USING_OVERFLOW_CHECK=y
|
||||||
CONFIG_RT_USING_HOOK=y
|
CONFIG_RT_USING_HOOK=y
|
||||||
CONFIG_RT_USING_IDLE_HOOK=y
|
CONFIG_RT_USING_IDLE_HOOK=y
|
||||||
|
@ -54,6 +54,7 @@ CONFIG_RT_USING_MEMPOOL=y
|
||||||
# CONFIG_RT_USING_NOHEAP is not set
|
# CONFIG_RT_USING_NOHEAP is not set
|
||||||
CONFIG_RT_USING_SMALL_MEM=y
|
CONFIG_RT_USING_SMALL_MEM=y
|
||||||
# CONFIG_RT_USING_SLAB is not set
|
# CONFIG_RT_USING_SLAB is not set
|
||||||
|
# CONFIG_RT_USING_USERHEAP is not set
|
||||||
# CONFIG_RT_USING_MEMTRACE is not set
|
# CONFIG_RT_USING_MEMTRACE is not set
|
||||||
CONFIG_RT_USING_HEAP=y
|
CONFIG_RT_USING_HEAP=y
|
||||||
|
|
||||||
|
@ -149,6 +150,7 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||||
# CONFIG_RT_USING_HWTIMER is not set
|
# CONFIG_RT_USING_HWTIMER is not set
|
||||||
# CONFIG_RT_USING_CPUTIME is not set
|
# CONFIG_RT_USING_CPUTIME is not set
|
||||||
# CONFIG_RT_USING_I2C is not set
|
# CONFIG_RT_USING_I2C is not set
|
||||||
|
# CONFIG_RT_USING_PHY is not set
|
||||||
CONFIG_RT_USING_PIN=y
|
CONFIG_RT_USING_PIN=y
|
||||||
# CONFIG_RT_USING_ADC is not set
|
# CONFIG_RT_USING_ADC is not set
|
||||||
# CONFIG_RT_USING_DAC is not set
|
# CONFIG_RT_USING_DAC is not set
|
||||||
|
@ -376,6 +378,7 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||||
# CONFIG_PKG_USING_AGILE_JSMN is not set
|
# CONFIG_PKG_USING_AGILE_JSMN is not set
|
||||||
# CONFIG_PKG_USING_PDULIB is not set
|
# CONFIG_PKG_USING_PDULIB is not set
|
||||||
# CONFIG_PKG_USING_BTSTACK is not set
|
# CONFIG_PKG_USING_BTSTACK is not set
|
||||||
|
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# security packages
|
# security packages
|
||||||
|
@ -402,6 +405,7 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||||
# CONFIG_PKG_USING_WAVPLAYER is not set
|
# CONFIG_PKG_USING_WAVPLAYER is not set
|
||||||
# CONFIG_PKG_USING_TJPGD is not set
|
# CONFIG_PKG_USING_TJPGD is not set
|
||||||
# CONFIG_PKG_USING_HELIX is not set
|
# CONFIG_PKG_USING_HELIX is not set
|
||||||
|
# CONFIG_PKG_USING_AZUREGUIX is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# tools packages
|
# tools packages
|
||||||
|
@ -449,7 +453,15 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||||
# CONFIG_PKG_USING_RAMDISK is not set
|
# CONFIG_PKG_USING_RAMDISK is not set
|
||||||
# CONFIG_PKG_USING_MININI is not set
|
# CONFIG_PKG_USING_MININI is not set
|
||||||
# CONFIG_PKG_USING_QBOOT is not set
|
# CONFIG_PKG_USING_QBOOT is not set
|
||||||
|
|
||||||
|
#
|
||||||
|
# Micrium: Micrium software products porting for RT-Thread
|
||||||
|
#
|
||||||
# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
|
# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
|
||||||
|
# CONFIG_PKG_USING_UC_CRC is not set
|
||||||
|
# CONFIG_PKG_USING_UC_CLK is not set
|
||||||
|
# CONFIG_PKG_USING_UC_COMMON is not set
|
||||||
|
# CONFIG_PKG_USING_UC_MODBUS is not set
|
||||||
# CONFIG_PKG_USING_PPOOL is not set
|
# CONFIG_PKG_USING_PPOOL is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -505,6 +517,8 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||||
# CONFIG_PKG_USING_WK2124 is not set
|
# CONFIG_PKG_USING_WK2124 is not set
|
||||||
# CONFIG_PKG_USING_LY68L6400 is not set
|
# CONFIG_PKG_USING_LY68L6400 is not set
|
||||||
# CONFIG_PKG_USING_DM9051 is not set
|
# CONFIG_PKG_USING_DM9051 is not set
|
||||||
|
# CONFIG_PKG_USING_SSD1306 is not set
|
||||||
|
# CONFIG_PKG_USING_QKEY is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
# miscellaneous packages
|
# miscellaneous packages
|
||||||
|
@ -534,11 +548,13 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||||
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
|
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
|
||||||
# CONFIG_PKG_USING_HELLO is not set
|
# CONFIG_PKG_USING_HELLO is not set
|
||||||
# CONFIG_PKG_USING_VI is not set
|
# CONFIG_PKG_USING_VI is not set
|
||||||
|
# CONFIG_PKG_USING_KI is not set
|
||||||
# CONFIG_PKG_USING_NNOM is not set
|
# CONFIG_PKG_USING_NNOM is not set
|
||||||
# CONFIG_PKG_USING_LIBANN is not set
|
# CONFIG_PKG_USING_LIBANN is not set
|
||||||
# CONFIG_PKG_USING_ELAPACK is not set
|
# CONFIG_PKG_USING_ELAPACK is not set
|
||||||
# CONFIG_PKG_USING_ARMv7M_DWT is not set
|
# CONFIG_PKG_USING_ARMv7M_DWT is not set
|
||||||
# CONFIG_PKG_USING_VT100 is not set
|
# CONFIG_PKG_USING_VT100 is not set
|
||||||
|
# CONFIG_PKG_USING_TETRIS is not set
|
||||||
# CONFIG_PKG_USING_ULAPACK is not set
|
# CONFIG_PKG_USING_ULAPACK is not set
|
||||||
# CONFIG_PKG_USING_UKAL is not set
|
# CONFIG_PKG_USING_UKAL is not set
|
||||||
# CONFIG_PKG_USING_CRCLIB is not set
|
# CONFIG_PKG_USING_CRCLIB is not set
|
||||||
|
@ -584,6 +600,8 @@ CONFIG_RT_LWIP_USING_PING=y
|
||||||
# CONFIG_PKG_USING_DCM is not set
|
# CONFIG_PKG_USING_DCM is not set
|
||||||
# CONFIG_PKG_USING_EMQ is not set
|
# CONFIG_PKG_USING_EMQ is not set
|
||||||
# CONFIG_PKG_USING_CFGM is not set
|
# CONFIG_PKG_USING_CFGM is not set
|
||||||
|
# CONFIG_PKG_USING_RT_CMSIS_DAP is not set
|
||||||
|
# CONFIG_PKG_USING_VIRTUAL_DEVICE is not set
|
||||||
CONFIG_BCM2711_SOC=y
|
CONFIG_BCM2711_SOC=y
|
||||||
# CONFIG_BSP_SUPPORT_FPU is not set
|
# CONFIG_BSP_SUPPORT_FPU is not set
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include "cp15.h"
|
#include "cp15.h"
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
|
#include "mbox.h"
|
||||||
|
|
||||||
struct mem_desc platform_mem_desc[] = {
|
struct mem_desc platform_mem_desc[] = {
|
||||||
{0x0, 0x6400000, 0x0, NORMAL_MEM},
|
{0x0, 0x6400000, 0x0, NORMAL_MEM},
|
||||||
|
@ -36,21 +37,25 @@ void rt_hw_timer_isr(int vector, void *parameter)
|
||||||
|
|
||||||
void rt_hw_timer_init(void)
|
void rt_hw_timer_init(void)
|
||||||
{
|
{
|
||||||
rt_hw_interrupt_install(ARM_TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
|
rt_uint32_t apb_clock = 0;
|
||||||
rt_hw_interrupt_umask(ARM_TIMER_IRQ);
|
rt_uint32_t timer_clock = 1000000;
|
||||||
/* timer_clock = apb_clock/(pre_divider + 1) */
|
/* timer_clock = apb_clock/(pre_divider + 1) */
|
||||||
ARM_TIMER_PREDIV = (250 - 1);
|
apb_clock = bcm271x_mbox_clock_get_rate(CORE_CLK_ID);
|
||||||
|
ARM_TIMER_PREDIV = (apb_clock/timer_clock - 1);
|
||||||
|
|
||||||
ARM_TIMER_RELOAD = 0;
|
ARM_TIMER_RELOAD = 0;
|
||||||
ARM_TIMER_LOAD = 0;
|
ARM_TIMER_LOAD = 0;
|
||||||
ARM_TIMER_IRQCLR = 0;
|
ARM_TIMER_IRQCLR = 0;
|
||||||
ARM_TIMER_CTRL = 0;
|
ARM_TIMER_CTRL = 0;
|
||||||
|
|
||||||
ARM_TIMER_RELOAD = 10000;
|
ARM_TIMER_RELOAD = 1000000/RT_TICK_PER_SECOND;
|
||||||
ARM_TIMER_LOAD = 10000;
|
ARM_TIMER_LOAD = 1000000/RT_TICK_PER_SECOND;
|
||||||
|
|
||||||
/* 23-bit counter, enable interrupt, enable timer */
|
/* 23-bit counter, enable interrupt, enable timer */
|
||||||
ARM_TIMER_CTRL = (1 << 1) | (1 << 5) | (1 << 7);
|
ARM_TIMER_CTRL = (1 << 1) | (1 << 5) | (1 << 7);
|
||||||
|
|
||||||
|
rt_hw_interrupt_install(ARM_TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
|
||||||
|
rt_hw_interrupt_umask(ARM_TIMER_IRQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
void idle_wfi(void)
|
void idle_wfi(void)
|
||||||
|
|
|
@ -19,6 +19,15 @@
|
||||||
#include "raspi4.h"
|
#include "raspi4.h"
|
||||||
#include "drv_eth.h"
|
#include "drv_eth.h"
|
||||||
|
|
||||||
|
//#define ETH_RX_POLL
|
||||||
|
|
||||||
|
#define DBG_LEVEL DBG_LOG
|
||||||
|
#include <rtdbg.h>
|
||||||
|
#define LOG_TAG "drv.eth"
|
||||||
|
|
||||||
|
static int link_speed = 0;
|
||||||
|
static int link_flag = 0;
|
||||||
|
|
||||||
#define RECV_CACHE_BUF (1024)
|
#define RECV_CACHE_BUF (1024)
|
||||||
#define SEND_DATA_NO_CACHE (0x08200000)
|
#define SEND_DATA_NO_CACHE (0x08200000)
|
||||||
#define RECV_DATA_NO_CACHE (0x08400000)
|
#define RECV_DATA_NO_CACHE (0x08400000)
|
||||||
|
@ -34,6 +43,11 @@
|
||||||
|
|
||||||
#define BIT(nr) (1UL << (nr))
|
#define BIT(nr) (1UL << (nr))
|
||||||
|
|
||||||
|
static rt_thread_t link_thread_tid = RT_NULL;
|
||||||
|
#define LINK_THREAD_STACK_SIZE (1024)
|
||||||
|
#define LINK_THREAD_PRIORITY (20)
|
||||||
|
#define LINK_THREAD_TIMESLICE (10)
|
||||||
|
|
||||||
static rt_uint32_t tx_index = 0;
|
static rt_uint32_t tx_index = 0;
|
||||||
static rt_uint32_t rx_index = 0;
|
static rt_uint32_t rx_index = 0;
|
||||||
static rt_uint32_t index_flag = 0;
|
static rt_uint32_t index_flag = 0;
|
||||||
|
@ -54,6 +68,7 @@ struct rt_eth_dev
|
||||||
};
|
};
|
||||||
static struct rt_eth_dev eth_dev;
|
static struct rt_eth_dev eth_dev;
|
||||||
static struct rt_semaphore sem_lock;
|
static struct rt_semaphore sem_lock;
|
||||||
|
static struct rt_semaphore link_ack;
|
||||||
|
|
||||||
static inline rt_uint32_t read32(void *addr)
|
static inline rt_uint32_t read32(void *addr)
|
||||||
{
|
{
|
||||||
|
@ -65,16 +80,33 @@ static inline void write32(void *addr, rt_uint32_t value)
|
||||||
(*((volatile unsigned int*)(addr))) = value;
|
(*((volatile unsigned int*)(addr))) = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eth_rx_irq(void *param)
|
static void eth_rx_irq(int irq, void *param)
|
||||||
|
{
|
||||||
|
#ifndef ETH_RX_POLL
|
||||||
|
rt_uint32_t val = 0;
|
||||||
|
val = read32(MAC_REG + GENET_INTRL2_CPU_STAT);
|
||||||
|
val &= ~read32(MAC_REG + GENET_INTRL2_CPU_STAT_MASK);
|
||||||
|
write32(MAC_REG + GENET_INTRL2_CPU_CLEAR, val);
|
||||||
|
if (val & GENET_IRQ_RXDMA_DONE)
|
||||||
{
|
{
|
||||||
eth_device_ready(ð_dev.parent);
|
eth_device_ready(ð_dev.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (val & GENET_IRQ_TXDMA_DONE)
|
||||||
|
{
|
||||||
|
//todo
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
eth_device_ready(ð_dev.parent);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* We only support RGMII (as used on the RPi4). */
|
/* We only support RGMII (as used on the RPi4). */
|
||||||
static int bcmgenet_interface_set(void)
|
static int bcmgenet_interface_set(void)
|
||||||
{
|
{
|
||||||
int phy_mode = PHY_INTERFACE_MODE_RGMII;
|
int phy_mode = PHY_INTERFACE_MODE_RGMII;
|
||||||
switch (phy_mode) {
|
switch (phy_mode)
|
||||||
|
{
|
||||||
case PHY_INTERFACE_MODE_RGMII:
|
case PHY_INTERFACE_MODE_RGMII:
|
||||||
case PHY_INTERFACE_MODE_RGMII_RXID:
|
case PHY_INTERFACE_MODE_RGMII_RXID:
|
||||||
write32(MAC_REG + SYS_PORT_CTRL, PORT_MODE_EXT_GPHY);
|
write32(MAC_REG + SYS_PORT_CTRL, PORT_MODE_EXT_GPHY);
|
||||||
|
@ -158,7 +190,6 @@ static int bcmgenet_mdio_write(rt_uint32_t addr, rt_uint32_t reg, rt_uint32_t va
|
||||||
reg_val = read32(MAC_REG + MDIO_CMD);
|
reg_val = read32(MAC_REG + MDIO_CMD);
|
||||||
|
|
||||||
return reg_val & 0xffff;
|
return reg_val & 0xffff;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bcmgenet_mdio_read(rt_uint32_t addr, rt_uint32_t reg)
|
static int bcmgenet_mdio_read(rt_uint32_t addr, rt_uint32_t reg)
|
||||||
|
@ -209,7 +240,7 @@ static int get_ethernet_uid(void)
|
||||||
|
|
||||||
if (BCM54213PE_VERSION_B1 == uid)
|
if (BCM54213PE_VERSION_B1 == uid)
|
||||||
{
|
{
|
||||||
rt_kprintf("version is B1\n");
|
LOG_I("version is B1\n");
|
||||||
}
|
}
|
||||||
return uid;
|
return uid;
|
||||||
}
|
}
|
||||||
|
@ -236,11 +267,13 @@ static void bcmgenet_mdio_init(void)
|
||||||
/* read status reg */
|
/* read status reg */
|
||||||
bcmgenet_mdio_read(1, BCM54213PE_IEEE_EXTENDED_STATUS);
|
bcmgenet_mdio_read(1, BCM54213PE_IEEE_EXTENDED_STATUS);
|
||||||
bcmgenet_mdio_read(1, BCM54213PE_AUTO_NEGOTIATION_ADV);
|
bcmgenet_mdio_read(1, BCM54213PE_AUTO_NEGOTIATION_ADV);
|
||||||
|
|
||||||
bcmgenet_mdio_read(1, BCM54213PE_MII_STATUS);
|
bcmgenet_mdio_read(1, BCM54213PE_MII_STATUS);
|
||||||
bcmgenet_mdio_read(1, BCM54213PE_CONTROL);
|
bcmgenet_mdio_read(1, BCM54213PE_CONTROL);
|
||||||
/* half full duplex capability */
|
/* half full duplex capability */
|
||||||
bcmgenet_mdio_write(1, BCM54213PE_CONTROL, (CONTROL_HALF_DUPLEX_CAPABILITY | CONTROL_FULL_DUPLEX_CAPABILITY));
|
bcmgenet_mdio_write(1, BCM54213PE_CONTROL, (CONTROL_HALF_DUPLEX_CAPABILITY | CONTROL_FULL_DUPLEX_CAPABILITY));
|
||||||
bcmgenet_mdio_read(1, BCM54213PE_MII_CONTROL);
|
bcmgenet_mdio_read(1, BCM54213PE_MII_CONTROL);
|
||||||
|
|
||||||
/* set mii control */
|
/* set mii control */
|
||||||
bcmgenet_mdio_write(1, BCM54213PE_MII_CONTROL, (MII_CONTROL_AUTO_NEGOTIATION_ENABLED | MII_CONTROL_AUTO_NEGOTIATION_RESTART | MII_CONTROL_PHY_FULL_DUPLEX | MII_CONTROL_SPEED_SELECTION));
|
bcmgenet_mdio_write(1, BCM54213PE_MII_CONTROL, (MII_CONTROL_AUTO_NEGOTIATION_ENABLED | MII_CONTROL_AUTO_NEGOTIATION_RESTART | MII_CONTROL_PHY_FULL_DUPLEX | MII_CONTROL_SPEED_SELECTION));
|
||||||
}
|
}
|
||||||
|
@ -284,55 +317,21 @@ static void rx_descs_init(void)
|
||||||
void *desc_base = (void *)RX_DESC_BASE;
|
void *desc_base = (void *)RX_DESC_BASE;
|
||||||
|
|
||||||
len_stat = (RX_BUF_LENGTH << DMA_BUFLENGTH_SHIFT) | DMA_OWN;
|
len_stat = (RX_BUF_LENGTH << DMA_BUFLENGTH_SHIFT) | DMA_OWN;
|
||||||
for (i = 0; i < RX_DESCS; i++) {
|
for (i = 0; i < RX_DESCS; i++)
|
||||||
|
{
|
||||||
write32((desc_base + i * DMA_DESC_SIZE + DMA_DESC_ADDRESS_LO), lower_32_bits((uintptr_t)&rxbuffs[i * RX_BUF_LENGTH]));
|
write32((desc_base + i * DMA_DESC_SIZE + DMA_DESC_ADDRESS_LO), lower_32_bits((uintptr_t)&rxbuffs[i * RX_BUF_LENGTH]));
|
||||||
write32((desc_base + i * DMA_DESC_SIZE + DMA_DESC_ADDRESS_HI), upper_32_bits((uintptr_t)&rxbuffs[i * RX_BUF_LENGTH]));
|
write32((desc_base + i * DMA_DESC_SIZE + DMA_DESC_ADDRESS_HI), upper_32_bits((uintptr_t)&rxbuffs[i * RX_BUF_LENGTH]));
|
||||||
write32((desc_base + i * DMA_DESC_SIZE + DMA_DESC_LENGTH_STATUS), len_stat);
|
write32((desc_base + i * DMA_DESC_SIZE + DMA_DESC_LENGTH_STATUS), len_stat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int phy_startup(void)
|
|
||||||
{
|
|
||||||
int count = 1000000;
|
|
||||||
while ((bcmgenet_mdio_read(1, BCM54213PE_MII_STATUS) & MII_STATUS_LINK_UP) && (--count))
|
|
||||||
DELAY_MICROS(1);
|
|
||||||
if(count > 0)
|
|
||||||
{
|
|
||||||
rt_kprintf("bcmgenet: PHY startup ok!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rt_kprintf("bcmgenet: PHY startup err!\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bcmgenet_mdio_read(1, BCM54213PE_STATUS) == 0)
|
|
||||||
{
|
|
||||||
//todo
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rt_kprintf("bcmgenet: BCM54213PE_STATUS err!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bcmgenet_mdio_read(1, BCM54213PE_CONTROL) == (CONTROL_FULL_DUPLEX_CAPABILITY| CONTROL_HALF_DUPLEX_CAPABILITY))
|
|
||||||
{
|
|
||||||
//todo
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rt_kprintf("bcmgenet: BCM54213PE_CONTROL err!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int bcmgenet_adjust_link(void)
|
static int bcmgenet_adjust_link(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t speed;
|
rt_uint32_t speed;
|
||||||
rt_uint32_t phy_dev_speed = SPEED_100;
|
rt_uint32_t phy_dev_speed = link_speed;
|
||||||
|
|
||||||
switch (phy_dev_speed) {
|
switch (phy_dev_speed)
|
||||||
|
{
|
||||||
case SPEED_1000:
|
case SPEED_1000:
|
||||||
speed = UMAC_SPEED_1000;
|
speed = UMAC_SPEED_1000;
|
||||||
break;
|
break;
|
||||||
|
@ -358,6 +357,14 @@ static int bcmgenet_adjust_link(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void link_irq(void *param)
|
||||||
|
{
|
||||||
|
if ((bcmgenet_mdio_read(1, BCM54213PE_MII_STATUS) & MII_STATUS_LINK_UP) != 0)
|
||||||
|
{
|
||||||
|
rt_sem_release(&link_ack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int bcmgenet_gmac_eth_start(void)
|
static int bcmgenet_gmac_eth_start(void)
|
||||||
{
|
{
|
||||||
rt_uint32_t ret;
|
rt_uint32_t ret;
|
||||||
|
@ -375,16 +382,10 @@ static int bcmgenet_gmac_eth_start(void)
|
||||||
/* Enable RX/TX DMA */
|
/* Enable RX/TX DMA */
|
||||||
bcmgenet_enable_dma();
|
bcmgenet_enable_dma();
|
||||||
|
|
||||||
/* read PHY properties over the wire from generic PHY set-up */
|
|
||||||
ret = phy_startup();
|
|
||||||
if (ret) {
|
|
||||||
rt_kprintf("bcmgenet: PHY startup failed: %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update MAC registers based on PHY property */
|
/* Update MAC registers based on PHY property */
|
||||||
ret = bcmgenet_adjust_link();
|
ret = bcmgenet_adjust_link();
|
||||||
if (ret) {
|
if(ret)
|
||||||
|
{
|
||||||
rt_kprintf("bcmgenet: adjust PHY link failed: %d\n", ret);
|
rt_kprintf("bcmgenet: adjust PHY link failed: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -410,6 +411,8 @@ static int bcmgenet_gmac_eth_start(void)
|
||||||
rx_tx_en |= (CMD_TX_EN | CMD_RX_EN);
|
rx_tx_en |= (CMD_TX_EN | CMD_RX_EN);
|
||||||
|
|
||||||
write32(MAC_REG + UMAC_CMD, rx_tx_en);
|
write32(MAC_REG + UMAC_CMD, rx_tx_en);
|
||||||
|
//IRQ
|
||||||
|
write32(MAC_REG + GENET_INTRL2_CPU_CLEAR_MASK, GENET_IRQ_TXDMA_DONE | GENET_IRQ_RXDMA_DONE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,6 +427,7 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp)
|
||||||
if(prod_index == index_flag)
|
if(prod_index == index_flag)
|
||||||
{
|
{
|
||||||
cur_recv_cnt = index_flag;
|
cur_recv_cnt = index_flag;
|
||||||
|
index_flag = 0x7fffffff;
|
||||||
//no buff
|
//no buff
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -452,6 +456,11 @@ static rt_uint32_t bcmgenet_gmac_eth_recv(rt_uint8_t **packetp)
|
||||||
write32(MAC_REG + RDMA_CONS_INDEX, cur_recv_cnt);
|
write32(MAC_REG + RDMA_CONS_INDEX, cur_recv_cnt);
|
||||||
|
|
||||||
cur_recv_cnt = cur_recv_cnt + 1;
|
cur_recv_cnt = cur_recv_cnt + 1;
|
||||||
|
|
||||||
|
if(cur_recv_cnt > 0xffff)
|
||||||
|
{
|
||||||
|
cur_recv_cnt = 0;
|
||||||
|
}
|
||||||
prev_recv_cnt = cur_recv_cnt;
|
prev_recv_cnt = cur_recv_cnt;
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
|
@ -475,37 +484,105 @@ static int bcmgenet_gmac_eth_send(void *packet, int length)
|
||||||
write32((desc_base + DMA_DESC_ADDRESS_HI), 0);
|
write32((desc_base + DMA_DESC_ADDRESS_HI), 0);
|
||||||
write32((desc_base + DMA_DESC_LENGTH_STATUS), len_stat);
|
write32((desc_base + DMA_DESC_LENGTH_STATUS), len_stat);
|
||||||
|
|
||||||
if(++tx_index>= TX_DESCS)
|
tx_index = tx_index + 1;
|
||||||
|
prod_index = prod_index + 1;
|
||||||
|
|
||||||
|
if (prod_index == 0xe000)
|
||||||
|
{
|
||||||
|
write32(MAC_REG + TDMA_PROD_INDEX, 0);
|
||||||
|
prod_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx_index == 256)
|
||||||
{
|
{
|
||||||
tx_index = 0;
|
tx_index = 0;
|
||||||
}
|
}
|
||||||
prod_index++;
|
|
||||||
/* Start Transmisson */
|
/* Start Transmisson */
|
||||||
write32(MAC_REG + TDMA_PROD_INDEX, prod_index);
|
write32(MAC_REG + TDMA_PROD_INDEX, prod_index);
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
cons = read32(MAC_REG + TDMA_CONS_INDEX);
|
cons = read32(MAC_REG + TDMA_CONS_INDEX);
|
||||||
} while ((cons & 0xffff) < prod_index && --tries);
|
} while ((cons & 0xffff) < prod_index && --tries);
|
||||||
|
|
||||||
if (!tries)
|
if (!tries)
|
||||||
{
|
{
|
||||||
|
rt_kprintf("send err! tries is %d\n", tries);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void link_task_entry(void *param)
|
||||||
|
{
|
||||||
|
struct eth_device *eth_device = (struct eth_device *)param;
|
||||||
|
RT_ASSERT(eth_device != RT_NULL);
|
||||||
|
struct rt_eth_dev *dev = ð_dev;
|
||||||
|
//start mdio
|
||||||
|
bcmgenet_mdio_init();
|
||||||
|
//start timer link
|
||||||
|
rt_timer_init(&dev->link_timer, "link_timer",
|
||||||
|
link_irq,
|
||||||
|
NULL,
|
||||||
|
100,
|
||||||
|
RT_TIMER_FLAG_PERIODIC);
|
||||||
|
rt_timer_start(&dev->link_timer);
|
||||||
|
|
||||||
|
//link wait forever
|
||||||
|
rt_sem_take(&link_ack, RT_WAITING_FOREVER);
|
||||||
|
eth_device_linkchange(ð_dev.parent, RT_TRUE); //link up
|
||||||
|
rt_timer_stop(&dev->link_timer);
|
||||||
|
|
||||||
|
//set mac
|
||||||
|
bcmgenet_gmac_write_hwaddr();
|
||||||
|
bcmgenet_gmac_write_hwaddr();
|
||||||
|
|
||||||
|
//check link speed
|
||||||
|
if ((bcmgenet_mdio_read(1, BCM54213PE_STATUS) & (1 << 10)) || (bcmgenet_mdio_read(1, BCM54213PE_STATUS) & (1 << 11)))
|
||||||
|
{
|
||||||
|
link_speed = 1000;
|
||||||
|
rt_kprintf("Support link mode Speed 1000M\n");
|
||||||
|
}
|
||||||
|
else if ((bcmgenet_mdio_read(1, 0x05) & (1 << 7)) || (bcmgenet_mdio_read(1, 0x05) & (1 << 8)) || (bcmgenet_mdio_read(1, 0x05) & (1 << 9)))
|
||||||
|
{
|
||||||
|
link_speed = 100;
|
||||||
|
rt_kprintf("Support link mode Speed 100M\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
link_speed = 10;
|
||||||
|
rt_kprintf("Support link mode Speed 10M\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
bcmgenet_gmac_eth_start();
|
||||||
|
//irq or poll
|
||||||
|
#ifdef ETH_RX_POLL
|
||||||
|
rt_timer_init(&dev->rx_poll_timer, "rx_poll_timer",
|
||||||
|
eth_rx_irq,
|
||||||
|
NULL,
|
||||||
|
1,
|
||||||
|
RT_TIMER_FLAG_PERIODIC);
|
||||||
|
|
||||||
|
rt_timer_start(&dev->rx_poll_timer);
|
||||||
|
#else
|
||||||
|
rt_hw_interrupt_install(ETH_IRQ, eth_rx_irq, NULL, "eth_irq");
|
||||||
|
rt_hw_interrupt_umask(ETH_IRQ);
|
||||||
|
#endif
|
||||||
|
link_flag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
static rt_err_t bcmgenet_eth_init(rt_device_t device)
|
static rt_err_t bcmgenet_eth_init(rt_device_t device)
|
||||||
{
|
{
|
||||||
struct eth_device *eth_device = (struct eth_device *)device;
|
|
||||||
RT_ASSERT(eth_device != RT_NULL);
|
|
||||||
rt_uint32_t ret = 0;
|
rt_uint32_t ret = 0;
|
||||||
rt_uint32_t hw_reg = 0;
|
rt_uint32_t hw_reg = 0;
|
||||||
struct rt_eth_dev *dev = ð_dev;
|
|
||||||
|
|
||||||
/* Read GENET HW version */
|
/* Read GENET HW version */
|
||||||
rt_uint8_t major = 0;
|
rt_uint8_t major = 0;
|
||||||
hw_reg = read32(MAC_REG + SYS_REV_CTRL);
|
hw_reg = read32(MAC_REG + SYS_REV_CTRL);
|
||||||
major = (hw_reg >> 24) & 0x0f;
|
major = (hw_reg >> 24) & 0x0f;
|
||||||
if (major != 6) {
|
if (major != 6)
|
||||||
|
{
|
||||||
if (major == 5)
|
if (major == 5)
|
||||||
major = 4;
|
major = 4;
|
||||||
else if (major == 0)
|
else if (major == 0)
|
||||||
|
@ -514,7 +591,6 @@ static rt_err_t bcmgenet_eth_init(rt_device_t device)
|
||||||
rt_kprintf("Uns upported GENETv%d.%d\n", major, (hw_reg >> 16) & 0x0f);
|
rt_kprintf("Uns upported GENETv%d.%d\n", major, (hw_reg >> 16) & 0x0f);
|
||||||
return RT_ERROR;
|
return RT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set interface */
|
/* set interface */
|
||||||
ret = bcmgenet_interface_set();
|
ret = bcmgenet_interface_set();
|
||||||
if (ret)
|
if (ret)
|
||||||
|
@ -530,21 +606,11 @@ static rt_err_t bcmgenet_eth_init(rt_device_t device)
|
||||||
/* issue soft reset with (rg)mii loopback to ensure a stable rxclk */
|
/* issue soft reset with (rg)mii loopback to ensure a stable rxclk */
|
||||||
write32(MAC_REG + UMAC_CMD, CMD_SW_RESET | CMD_LCL_LOOP_EN);
|
write32(MAC_REG + UMAC_CMD, CMD_SW_RESET | CMD_LCL_LOOP_EN);
|
||||||
|
|
||||||
bcmgenet_mdio_init();
|
link_thread_tid = rt_thread_create("link", link_task_entry, (void *)device,
|
||||||
|
LINK_THREAD_STACK_SIZE,
|
||||||
bcmgenet_gmac_write_hwaddr();
|
LINK_THREAD_PRIORITY, LINK_THREAD_TIMESLICE);
|
||||||
bcmgenet_gmac_write_hwaddr();
|
if (link_thread_tid != RT_NULL)
|
||||||
|
rt_thread_startup(link_thread_tid);
|
||||||
bcmgenet_gmac_eth_start();
|
|
||||||
|
|
||||||
//irq or poll
|
|
||||||
rt_timer_init(&dev->rx_poll_timer, "rx_poll_timer",
|
|
||||||
eth_rx_irq,
|
|
||||||
NULL,
|
|
||||||
1,
|
|
||||||
RT_TIMER_FLAG_PERIODIC);
|
|
||||||
|
|
||||||
rt_timer_start(&dev->rx_poll_timer);
|
|
||||||
|
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
@ -554,8 +620,10 @@ static rt_err_t bcmgenet_eth_control(rt_device_t dev, int cmd, void *args)
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
{
|
{
|
||||||
case NIOCTL_GADDR:
|
case NIOCTL_GADDR:
|
||||||
if (args) rt_memcpy(args, eth_dev.dev_addr, 6);
|
if (args)
|
||||||
else return -RT_ERROR;
|
rt_memcpy(args, eth_dev.dev_addr, 6);
|
||||||
|
else
|
||||||
|
return -RT_ERROR;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -565,15 +633,17 @@ static rt_err_t bcmgenet_eth_control(rt_device_t dev, int cmd, void *args)
|
||||||
|
|
||||||
rt_err_t rt_eth_tx(rt_device_t device, struct pbuf *p)
|
rt_err_t rt_eth_tx(rt_device_t device, struct pbuf *p)
|
||||||
{
|
{
|
||||||
rt_uint32_t sendbuf = SEND_DATA_NO_CACHE;
|
rt_uint32_t sendbuf = (rt_uint32_t)SEND_DATA_NO_CACHE;
|
||||||
/* lock eth device */
|
/* lock eth device */
|
||||||
|
if (link_flag == 1)
|
||||||
|
{
|
||||||
rt_sem_take(&sem_lock, RT_WAITING_FOREVER);
|
rt_sem_take(&sem_lock, RT_WAITING_FOREVER);
|
||||||
//struct rt_eth_dev *dev = (struct rt_eth_dev *) device;
|
|
||||||
pbuf_copy_partial(p, (void *)&send_cache_pbuf[0], p->tot_len, 0);
|
pbuf_copy_partial(p, (void *)&send_cache_pbuf[0], p->tot_len, 0);
|
||||||
rt_memcpy((void *)sendbuf, send_cache_pbuf, p->tot_len);
|
rt_memcpy((void *)sendbuf, send_cache_pbuf, p->tot_len);
|
||||||
|
|
||||||
bcmgenet_gmac_eth_send((void *)sendbuf, p->tot_len);
|
bcmgenet_gmac_eth_send((void *)sendbuf, p->tot_len);
|
||||||
rt_sem_release(&sem_lock);
|
rt_sem_release(&sem_lock);
|
||||||
|
}
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -583,16 +653,17 @@ struct pbuf *rt_eth_rx(rt_device_t device)
|
||||||
int recv_len = 0;
|
int recv_len = 0;
|
||||||
rt_uint32_t addr_point[8];
|
rt_uint32_t addr_point[8];
|
||||||
struct pbuf *pbuf = RT_NULL;
|
struct pbuf *pbuf = RT_NULL;
|
||||||
|
if (link_flag == 1)
|
||||||
|
{
|
||||||
rt_sem_take(&sem_lock, RT_WAITING_FOREVER);
|
rt_sem_take(&sem_lock, RT_WAITING_FOREVER);
|
||||||
|
|
||||||
recv_len = bcmgenet_gmac_eth_recv((rt_uint8_t **)&addr_point[0]);
|
recv_len = bcmgenet_gmac_eth_recv((rt_uint8_t **)&addr_point[0]);
|
||||||
|
|
||||||
if (recv_len > 0)
|
if (recv_len > 0)
|
||||||
{
|
{
|
||||||
pbuf = pbuf_alloc(PBUF_LINK, recv_len, PBUF_RAM);
|
pbuf = pbuf_alloc(PBUF_LINK, recv_len, PBUF_RAM);
|
||||||
rt_memcpy(pbuf->payload, (char *)addr_point[0], recv_len);
|
rt_memcpy(pbuf->payload, (char *)addr_point[0], recv_len);
|
||||||
}
|
}
|
||||||
rt_sem_release(&sem_lock);
|
rt_sem_release(&sem_lock);
|
||||||
|
}
|
||||||
return pbuf;
|
return pbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,11 +672,11 @@ int rt_hw_eth_init(void)
|
||||||
rt_uint8_t mac_addr[6];
|
rt_uint8_t mac_addr[6];
|
||||||
|
|
||||||
rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO);
|
rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO);
|
||||||
|
rt_sem_init(&link_ack, "link_ack", 0, RT_IPC_FLAG_FIFO);
|
||||||
|
|
||||||
memset(ð_dev, 0, sizeof(eth_dev));
|
memset(ð_dev, 0, sizeof(eth_dev));
|
||||||
memset((void *)SEND_DATA_NO_CACHE, 0, sizeof(DMA_DISC_ADDR_SIZE));
|
memset((void *)SEND_DATA_NO_CACHE, 0, sizeof(DMA_DISC_ADDR_SIZE));
|
||||||
memset((void *)RECV_DATA_NO_CACHE, 0, sizeof(DMA_DISC_ADDR_SIZE));
|
memset((void *)RECV_DATA_NO_CACHE, 0, sizeof(DMA_DISC_ADDR_SIZE));
|
||||||
|
|
||||||
bcm271x_mbox_hardware_get_mac_address(&mac_addr[0]);
|
bcm271x_mbox_hardware_get_mac_address(&mac_addr[0]);
|
||||||
|
|
||||||
eth_dev.iobase = MAC_REG;
|
eth_dev.iobase = MAC_REG;
|
||||||
|
@ -629,9 +700,8 @@ int rt_hw_eth_init(void)
|
||||||
eth_dev.parent.eth_tx = rt_eth_tx;
|
eth_dev.parent.eth_tx = rt_eth_tx;
|
||||||
eth_dev.parent.eth_rx = rt_eth_rx;
|
eth_dev.parent.eth_rx = rt_eth_rx;
|
||||||
|
|
||||||
|
|
||||||
eth_device_init(&(eth_dev.parent), "e0");
|
eth_device_init(&(eth_dev.parent), "e0");
|
||||||
eth_device_linkchange(ð_dev.parent, RT_TRUE); //linkup the e0 for lwip to check
|
eth_device_linkchange(ð_dev.parent, RT_FALSE); //link down
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
INIT_COMPONENT_EXPORT(rt_hw_eth_init);
|
INIT_COMPONENT_EXPORT(rt_hw_eth_init);
|
||||||
|
|
|
@ -53,6 +53,17 @@
|
||||||
#define MDIO_REG_SHIFT (16)
|
#define MDIO_REG_SHIFT (16)
|
||||||
#define MDIO_REG_MASK (0x1f)
|
#define MDIO_REG_MASK (0x1f)
|
||||||
|
|
||||||
|
#define GENET_INTRL2_OFF (0x0200)
|
||||||
|
#define GENET_INTRL2_CPU_STAT (GENET_INTRL2_OFF + 0x00)
|
||||||
|
#define GENET_INTRL2_CPU_CLEAR (GENET_INTRL2_OFF + 0x08)
|
||||||
|
#define GENET_INTRL2_CPU_STAT_MASK (GENET_INTRL2_OFF + 0x0c)
|
||||||
|
#define GENET_INTRL2_CPU_SET_MASK (GENET_INTRL2_OFF + 0x10)
|
||||||
|
#define GENET_INTRL2_CPU_CLEAR_MASK (GENET_INTRL2_OFF + 0x14)
|
||||||
|
#define GENET_IRQ_MDIO_ERROR BIT(24)
|
||||||
|
#define GENET_IRQ_MDIO_DONE BIT(23)
|
||||||
|
#define GENET_IRQ_TXDMA_DONE BIT(16)
|
||||||
|
#define GENET_IRQ_RXDMA_DONE BIT(13)
|
||||||
|
|
||||||
#define CMD_TX_EN BIT(0)
|
#define CMD_TX_EN BIT(0)
|
||||||
#define CMD_RX_EN BIT(1)
|
#define CMD_RX_EN BIT(1)
|
||||||
#define UMAC_SPEED_10 (0)
|
#define UMAC_SPEED_10 (0)
|
||||||
|
|
|
@ -134,6 +134,18 @@ enum {
|
||||||
|
|
||||||
#define MBOX_ADDR 0x08000000
|
#define MBOX_ADDR 0x08000000
|
||||||
|
|
||||||
|
#define RES_CLK_ID (0x000000000)
|
||||||
|
#define EMMC_CLK_ID (0x000000001)
|
||||||
|
#define UART_CLK_ID (0x000000002)
|
||||||
|
#define ARM_CLK_ID (0x000000003)
|
||||||
|
#define CORE_CLK_ID (0x000000004)
|
||||||
|
#define V3D_CLK_ID (0x000000005)
|
||||||
|
#define H264_CLK_ID (0x000000006)
|
||||||
|
#define ISP_CLK_ID (0x000000007)
|
||||||
|
#define SDRAM_CLK_ID (0x000000008)
|
||||||
|
#define PIXEL_CLK_ID (0x000000009)
|
||||||
|
#define PWM_CLK_ID (0x00000000a)
|
||||||
|
|
||||||
int mbox_call(unsigned char ch, int mmu_enable);
|
int mbox_call(unsigned char ch, int mmu_enable);
|
||||||
int bcm271x_notify_reboot(void);
|
int bcm271x_notify_reboot(void);
|
||||||
int bcm271x_notify_xhci_reset(void);
|
int bcm271x_notify_xhci_reset(void);
|
||||||
|
|
|
@ -152,6 +152,8 @@ typedef enum {
|
||||||
#define MMC0_BASE_ADDR (PER_BASE+0x300000)
|
#define MMC0_BASE_ADDR (PER_BASE+0x300000)
|
||||||
#define MMC2_BASE_ADDR (PER_BASE+0x340000)
|
#define MMC2_BASE_ADDR (PER_BASE+0x340000)
|
||||||
|
|
||||||
|
#define ETH_IRQ (160+29)
|
||||||
|
|
||||||
/* the basic constants and interfaces needed by gic */
|
/* the basic constants and interfaces needed by gic */
|
||||||
rt_inline rt_uint32_t platform_get_gic_dist_base(void)
|
rt_inline rt_uint32_t platform_get_gic_dist_base(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#define RT_ALIGN_SIZE 4
|
#define RT_ALIGN_SIZE 4
|
||||||
#define RT_THREAD_PRIORITY_32
|
#define RT_THREAD_PRIORITY_32
|
||||||
#define RT_THREAD_PRIORITY_MAX 32
|
#define RT_THREAD_PRIORITY_MAX 32
|
||||||
#define RT_TICK_PER_SECOND 100
|
#define RT_TICK_PER_SECOND 1000
|
||||||
#define RT_USING_OVERFLOW_CHECK
|
#define RT_USING_OVERFLOW_CHECK
|
||||||
#define RT_USING_HOOK
|
#define RT_USING_HOOK
|
||||||
#define RT_USING_IDLE_HOOK
|
#define RT_USING_IDLE_HOOK
|
||||||
|
@ -214,6 +214,9 @@
|
||||||
/* system packages */
|
/* system packages */
|
||||||
|
|
||||||
|
|
||||||
|
/* Micrium: Micrium software products porting for RT-Thread */
|
||||||
|
|
||||||
|
|
||||||
/* peripheral libraries and drivers */
|
/* peripheral libraries and drivers */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue