2020-09-04 09:38:01 +08:00
|
|
|
/*
|
2022-06-22 13:41:06 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2020-09-04 09:38:01 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2017-08-24 chinesebear first version
|
|
|
|
* 2020-08-10 lizhirui porting to ls2k
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SYNOP_GMAC_PLAT_H
|
|
|
|
#define SYNOP_GMAC_PLAT_H 1
|
|
|
|
|
|
|
|
/* sw
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
*/
|
|
|
|
#include "synopGMAC_types.h"
|
|
|
|
#include "synopGMAC_debug.h"
|
|
|
|
//#include "mii.h"
|
|
|
|
//#include "GMAC_Pmon.h"
|
|
|
|
//#include "synopGMAC_Host.h"
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "mips_addrspace.h"
|
|
|
|
//sw: copy the type define into here
|
|
|
|
#define IOCTL_READ_REGISTER SIOCDEVPRIVATE+1
|
|
|
|
#define IOCTL_WRITE_REGISTER SIOCDEVPRIVATE+2
|
|
|
|
#define IOCTL_READ_IPSTRUCT SIOCDEVPRIVATE+3
|
|
|
|
#define IOCTL_READ_RXDESC SIOCDEVPRIVATE+4
|
|
|
|
#define IOCTL_READ_TXDESC SIOCDEVPRIVATE+5
|
|
|
|
#define IOCTL_POWER_DOWN SIOCDEVPRIVATE+6
|
|
|
|
|
|
|
|
#define SYNOP_GMAC0 1
|
|
|
|
|
|
|
|
typedef int bool;
|
|
|
|
//typedef unsigned long dma_addr_t;
|
|
|
|
|
|
|
|
#define KUSEG_ADDR 0x0
|
|
|
|
#define CACHED_MEMORY_ADDR KSEG0BASE
|
|
|
|
#define UNCACHED_MEMORY_ADDR KSEG0BASE
|
|
|
|
#define KSEG2_ADDR KSEG2BASE
|
|
|
|
#define MAX_MEM_ADDR KSEG3BASE
|
|
|
|
#define RESERVED_ADDR KSEG3BASE
|
|
|
|
|
|
|
|
#define CACHED_TO_PHYS(x) ((uint64_t)(x) - CACHED_MEMORY_ADDR)
|
|
|
|
#define PHYS_TO_CACHED(x) ((uint64_t)(x) + CACHED_MEMORY_ADDR)
|
|
|
|
#define UNCACHED_TO_PHYS(x) ((uint64_t)(x) - UNCACHED_MEMORY_ADDR)
|
|
|
|
#define PHYS_TO_UNCACHED(x) ((uint64_t)(x) + UNCACHED_MEMORY_ADDR)
|
|
|
|
#define VA_TO_CINDEX(x) (PHYS_TO_CACHED(UNCACHED_TO_PHYS(x)))
|
|
|
|
#define CACHED_TO_UNCACHED(x) (PHYS_TO_UNCACHED(CACHED_TO_PHYS(x)))
|
|
|
|
|
|
|
|
#define VA_TO_PA(x) CACHED_TO_PHYS(x)
|
|
|
|
|
|
|
|
/* sw
|
2022-06-22 13:41:06 +08:00
|
|
|
#define TR0(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
|
2020-09-04 09:38:01 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#undef TR
|
|
|
|
# define TR(fmt, args...) printk(KERN_CRIT "SynopGMAC: " fmt, ##args)
|
|
|
|
#else
|
2022-06-22 13:41:06 +08:00
|
|
|
# define TR(fmt, args...) // not debugging: nothing
|
2020-09-04 09:38:01 +08:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
/*
|
2022-06-22 13:41:06 +08:00
|
|
|
#define TR0(fmt, args...) printf("SynopGMAC: " fmt, ##args)
|
2020-09-04 09:38:01 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
#ifdef DEBUG
|
|
|
|
#undef TR
|
|
|
|
# define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
|
|
|
|
#else
|
2022-06-22 13:41:06 +08:00
|
|
|
//# define TR(fmt, args...) // not debugging: nothing
|
|
|
|
#define TR(fmt, args...) printf("SynopGMAC: " fmt, ##args)
|
2020-09-04 09:38:01 +08:00
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
//sw: nothing to display
|
2022-06-22 13:41:06 +08:00
|
|
|
#define TR0(fmt, args...) //rt_kprintf(fmt, ##args)
|
|
|
|
#define TR(fmt, args...) //rt_kprintf(fmt, ##args)
|
2020-09-04 09:38:01 +08:00
|
|
|
|
|
|
|
//typedef int bool;
|
|
|
|
enum synopGMAC_boolean
|
2022-06-22 13:41:06 +08:00
|
|
|
{
|
2020-09-04 09:38:01 +08:00
|
|
|
false = 0,
|
2022-06-22 13:41:06 +08:00
|
|
|
true = 1
|
2020-09-04 09:38:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_DELAY_VARIABLE 10
|
|
|
|
#define DEFAULT_LOOP_VARIABLE 10000
|
|
|
|
|
|
|
|
/* There are platform related endian conversions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define LE32_TO_CPU __le32_to_cpu
|
|
|
|
#define BE32_TO_CPU __be32_to_cpu
|
|
|
|
#define CPU_TO_LE32 __cpu_to_le32
|
|
|
|
|
|
|
|
/* Error Codes */
|
|
|
|
#define ESYNOPGMACNOERR 0
|
|
|
|
#define ESYNOPGMACNOMEM 1
|
|
|
|
#define ESYNOPGMACPHYERR 2
|
|
|
|
#define ESYNOPGMACBUSY 3
|
|
|
|
|
|
|
|
struct Network_interface_data
|
|
|
|
{
|
|
|
|
u32 unit;
|
|
|
|
u64 addr;
|
|
|
|
u32 data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These are the wrapper function prototypes for OS/platform related routines
|
2022-06-22 13:41:06 +08:00
|
|
|
*/
|
2020-09-04 09:38:01 +08:00
|
|
|
void * plat_alloc_memory(u32 );
|
|
|
|
void plat_free_memory(void *);
|
|
|
|
|
|
|
|
//void * plat_alloc_consistent_dmaable_memory(struct pci_dev *, u32, u32 *);
|
|
|
|
//void plat_free_consistent_dmaable_memory (struct pci_dev *, u32, void *, u32);
|
|
|
|
void plat_delay(u32);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Low level function to read register contents from Hardware.
|
2022-06-22 13:41:06 +08:00
|
|
|
*
|
|
|
|
* @param[in] pointer to the base of register map
|
2020-09-04 09:38:01 +08:00
|
|
|
* @param[in] Offset from the base
|
2022-06-22 13:41:06 +08:00
|
|
|
* \return Returns the register contents
|
2020-09-04 09:38:01 +08:00
|
|
|
*/
|
|
|
|
static u32 synopGMACReadReg(u64 RegBase, u32 RegOffset)
|
|
|
|
{
|
|
|
|
u64 addr;
|
|
|
|
u32 data;
|
|
|
|
|
|
|
|
addr = RegBase + (u32)RegOffset;
|
|
|
|
data = *(volatile u32 *)addr;
|
|
|
|
|
|
|
|
#if SYNOP_REG_DEBUG
|
|
|
|
TR("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, (u32)RegBase, RegOffset, data );
|
|
|
|
#endif
|
|
|
|
// rt_kprintf("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, (u32)RegBase, RegOffset, data );
|
|
|
|
return data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Low level function to write to a register in Hardware.
|
2022-06-22 13:41:06 +08:00
|
|
|
*
|
|
|
|
* @param[in] pointer to the base of register map
|
2020-09-04 09:38:01 +08:00
|
|
|
* @param[in] Offset from the base
|
2022-06-22 13:41:06 +08:00
|
|
|
* @param[in] Data to be written
|
|
|
|
* \return void
|
2020-09-04 09:38:01 +08:00
|
|
|
*/
|
|
|
|
static void synopGMACWriteReg(u64 RegBase, u32 RegOffset, u32 RegData )
|
|
|
|
{
|
|
|
|
u64 addr;
|
|
|
|
addr = RegBase + (u32)RegOffset;
|
|
|
|
// rt_kprintf("%s RegBase = 0x%08x RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__,(u32) RegBase, RegOffset, RegData );
|
|
|
|
#if SYNOP_REG_DEBUG
|
|
|
|
TR("%s RegBase = 0x%p RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__,(u32) RegBase, RegOffset, RegData );
|
|
|
|
#endif
|
|
|
|
*(volatile u32 *)addr = RegData;
|
|
|
|
/*if(addr == 0xbfe1100c)
|
|
|
|
DEBUG_MES("regdata = %08x\n", RegData);*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Low level function to set bits of a register in Hardware.
|
2022-06-22 13:41:06 +08:00
|
|
|
*
|
|
|
|
* @param[in] pointer to the base of register map
|
2020-09-04 09:38:01 +08:00
|
|
|
* @param[in] Offset from the base
|
2022-06-22 13:41:06 +08:00
|
|
|
* @param[in] Bit mask to set bits to logical 1
|
|
|
|
* \return void
|
2020-09-04 09:38:01 +08:00
|
|
|
*/
|
|
|
|
static void synopGMACSetBits(u64 RegBase, u32 RegOffset, u32 BitPos)
|
|
|
|
{
|
|
|
|
//u64 addr = (u64)RegBase + (u64)RegOffset;
|
|
|
|
u32 data;
|
|
|
|
data = synopGMACReadReg(RegBase, RegOffset);
|
2022-06-22 13:41:06 +08:00
|
|
|
data |= BitPos;
|
2020-09-04 09:38:01 +08:00
|
|
|
synopGMACWriteReg(RegBase, RegOffset, data);
|
|
|
|
// writel(data,(void *)addr);
|
|
|
|
#if SYNOP_REG_DEBUG
|
|
|
|
TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Low level function to clear bits of a register in Hardware.
|
2022-06-22 13:41:06 +08:00
|
|
|
*
|
|
|
|
* @param[in] pointer to the base of register map
|
2020-09-04 09:38:01 +08:00
|
|
|
* @param[in] Offset from the base
|
2022-06-22 13:41:06 +08:00
|
|
|
* @param[in] Bit mask to clear bits to logical 0
|
|
|
|
* \return void
|
2020-09-04 09:38:01 +08:00
|
|
|
*/
|
|
|
|
static void synopGMACClearBits(u64 RegBase, u32 RegOffset, u32 BitPos)
|
|
|
|
{
|
|
|
|
u32 data;
|
|
|
|
data = synopGMACReadReg(RegBase, RegOffset);
|
2022-06-22 13:41:06 +08:00
|
|
|
data &= (~BitPos);
|
2020-09-04 09:38:01 +08:00
|
|
|
synopGMACWriteReg(RegBase, RegOffset, data);
|
|
|
|
#if SYNOP_REG_DEBUG
|
|
|
|
TR("%s !!!!!!!!!!!!! RegOffset = 0x%08x RegData = 0x%08x\n", __FUNCTION__, RegOffset, data );
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Low level function to Check the setting of the bits.
|
2022-06-22 13:41:06 +08:00
|
|
|
*
|
|
|
|
* @param[in] pointer to the base of register map
|
2020-09-04 09:38:01 +08:00
|
|
|
* @param[in] Offset from the base
|
2022-06-22 13:41:06 +08:00
|
|
|
* @param[in] Bit mask to set bits to logical 1
|
2020-09-04 09:38:01 +08:00
|
|
|
* \return returns TRUE if set to '1' returns FALSE if set to '0'. Result undefined there are no bit set in the BitPos argument.
|
2022-06-22 13:41:06 +08:00
|
|
|
*
|
2020-09-04 09:38:01 +08:00
|
|
|
*/
|
|
|
|
static bool synopGMACCheckBits(u64 RegBase, u32 RegOffset, u32 BitPos)
|
|
|
|
{
|
|
|
|
u32 data;
|
|
|
|
data = synopGMACReadReg(RegBase, RegOffset);
|
2022-06-22 13:41:06 +08:00
|
|
|
data &= BitPos;
|
2020-09-04 09:38:01 +08:00
|
|
|
|
2022-06-22 13:41:06 +08:00
|
|
|
if(data)
|
2020-09-04 09:38:01 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-22 13:41:06 +08:00
|
|
|
else
|
2020-09-04 09:38:01 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-11 11:44:49 +08:00
|
|
|
#endif
|