2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-13 20:23:34 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2011 Michal Simek
|
|
|
|
*
|
|
|
|
* Michal SIMEK <monstr@monstr.eu>
|
|
|
|
*
|
|
|
|
* Based on Xilinx gmac driver:
|
|
|
|
* (C) Copyright 2011 Xilinx
|
|
|
|
*/
|
|
|
|
|
2016-11-15 10:45:42 +00:00
|
|
|
#include <clk.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
#include <common.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2015-11-30 13:14:56 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
#include <net.h>
|
2014-04-25 12:17:38 +00:00
|
|
|
#include <netdev.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
#include <config.h>
|
2015-09-24 18:13:45 +00:00
|
|
|
#include <console.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
#include <malloc.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <miiphy.h>
|
2016-01-23 10:54:33 +00:00
|
|
|
#include <wait_bit.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
#include <watchdog.h>
|
2014-12-06 07:27:53 +00:00
|
|
|
#include <asm/system.h>
|
2013-04-05 15:24:24 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2012-10-15 12:01:23 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2016-09-21 02:28:57 +00:00
|
|
|
#include <linux/errno.h>
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
/* Bit/mask specification */
|
|
|
|
#define ZYNQ_GEM_PHYMNTNC_OP_MASK 0x40020000 /* operation mask bits */
|
|
|
|
#define ZYNQ_GEM_PHYMNTNC_OP_R_MASK 0x20000000 /* read operation */
|
|
|
|
#define ZYNQ_GEM_PHYMNTNC_OP_W_MASK 0x10000000 /* write operation */
|
|
|
|
#define ZYNQ_GEM_PHYMNTNC_PHYAD_SHIFT_MASK 23 /* Shift bits for PHYAD */
|
|
|
|
#define ZYNQ_GEM_PHYMNTNC_PHREG_SHIFT_MASK 18 /* Shift bits for PHREG */
|
|
|
|
|
|
|
|
#define ZYNQ_GEM_RXBUF_EOF_MASK 0x00008000 /* End of frame. */
|
|
|
|
#define ZYNQ_GEM_RXBUF_SOF_MASK 0x00004000 /* Start of frame. */
|
|
|
|
#define ZYNQ_GEM_RXBUF_LEN_MASK 0x00003FFF /* Mask for length field */
|
|
|
|
|
|
|
|
#define ZYNQ_GEM_RXBUF_WRAP_MASK 0x00000002 /* Wrap bit, last BD */
|
|
|
|
#define ZYNQ_GEM_RXBUF_NEW_MASK 0x00000001 /* Used bit.. */
|
|
|
|
#define ZYNQ_GEM_RXBUF_ADD_MASK 0xFFFFFFFC /* Mask for address */
|
|
|
|
|
|
|
|
/* Wrap bit, last descriptor */
|
|
|
|
#define ZYNQ_GEM_TXBUF_WRAP_MASK 0x40000000
|
|
|
|
#define ZYNQ_GEM_TXBUF_LAST_MASK 0x00008000 /* Last buffer */
|
2015-08-17 07:58:54 +00:00
|
|
|
#define ZYNQ_GEM_TXBUF_USED_MASK 0x80000000 /* Used by Hw */
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
#define ZYNQ_GEM_NWCTRL_TXEN_MASK 0x00000008 /* Enable transmit */
|
|
|
|
#define ZYNQ_GEM_NWCTRL_RXEN_MASK 0x00000004 /* Enable receive */
|
|
|
|
#define ZYNQ_GEM_NWCTRL_MDEN_MASK 0x00000010 /* Enable MDIO port */
|
|
|
|
#define ZYNQ_GEM_NWCTRL_STARTTX_MASK 0x00000200 /* Start tx (tx_go) */
|
|
|
|
|
2016-05-16 10:01:37 +00:00
|
|
|
#define ZYNQ_GEM_NWCFG_SPEED100 0x00000001 /* 100 Mbps operation */
|
|
|
|
#define ZYNQ_GEM_NWCFG_SPEED1000 0x00000400 /* 1Gbps operation */
|
|
|
|
#define ZYNQ_GEM_NWCFG_FDEN 0x00000002 /* Full Duplex mode */
|
|
|
|
#define ZYNQ_GEM_NWCFG_FSREM 0x00020000 /* FCS removal */
|
2016-05-16 10:01:38 +00:00
|
|
|
#define ZYNQ_GEM_NWCFG_SGMII_ENBL 0x08000000 /* SGMII Enable */
|
2016-05-16 10:01:37 +00:00
|
|
|
#define ZYNQ_GEM_NWCFG_PCS_SEL 0x00000800 /* PCS select */
|
2015-09-08 15:20:01 +00:00
|
|
|
#ifdef CONFIG_ARM64
|
2016-05-16 10:01:37 +00:00
|
|
|
#define ZYNQ_GEM_NWCFG_MDCCLKDIV 0x00100000 /* Div pclk by 64, max 160MHz */
|
2015-09-08 15:20:01 +00:00
|
|
|
#else
|
2016-05-16 10:01:37 +00:00
|
|
|
#define ZYNQ_GEM_NWCFG_MDCCLKDIV 0x000c0000 /* Div pclk by 48, max 120MHz */
|
2015-09-08 15:20:01 +00:00
|
|
|
#endif
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2014-07-08 10:01:03 +00:00
|
|
|
#ifdef CONFIG_ARM64
|
|
|
|
# define ZYNQ_GEM_DBUS_WIDTH (1 << 21) /* 64 bit bus */
|
|
|
|
#else
|
|
|
|
# define ZYNQ_GEM_DBUS_WIDTH (0 << 21) /* 32 bit bus */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ZYNQ_GEM_NWCFG_INIT (ZYNQ_GEM_DBUS_WIDTH | \
|
|
|
|
ZYNQ_GEM_NWCFG_FDEN | \
|
2012-09-13 20:23:34 +00:00
|
|
|
ZYNQ_GEM_NWCFG_FSREM | \
|
|
|
|
ZYNQ_GEM_NWCFG_MDCCLKDIV)
|
|
|
|
|
|
|
|
#define ZYNQ_GEM_NWSR_MDIOIDLE_MASK 0x00000004 /* PHY management idle */
|
|
|
|
|
|
|
|
#define ZYNQ_GEM_DMACR_BLENGTH 0x00000004 /* INCR4 AHB bursts */
|
|
|
|
/* Use full configured addressable space (8 Kb) */
|
|
|
|
#define ZYNQ_GEM_DMACR_RXSIZE 0x00000300
|
|
|
|
/* Use full configured addressable space (4 Kb) */
|
|
|
|
#define ZYNQ_GEM_DMACR_TXSIZE 0x00000400
|
|
|
|
/* Set with binary 00011000 to use 1536 byte(1*max length frame/buffer) */
|
|
|
|
#define ZYNQ_GEM_DMACR_RXBUF 0x00180000
|
|
|
|
|
2018-11-26 10:57:38 +00:00
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
# define ZYNQ_GEM_DMA_BUS_WIDTH BIT(30) /* 64 bit bus */
|
|
|
|
#else
|
|
|
|
# define ZYNQ_GEM_DMA_BUS_WIDTH (0 << 30) /* 32 bit bus */
|
|
|
|
#endif
|
|
|
|
|
2012-09-13 20:23:34 +00:00
|
|
|
#define ZYNQ_GEM_DMACR_INIT (ZYNQ_GEM_DMACR_BLENGTH | \
|
|
|
|
ZYNQ_GEM_DMACR_RXSIZE | \
|
|
|
|
ZYNQ_GEM_DMACR_TXSIZE | \
|
2018-11-26 10:57:38 +00:00
|
|
|
ZYNQ_GEM_DMACR_RXBUF | \
|
|
|
|
ZYNQ_GEM_DMA_BUS_WIDTH)
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-08-17 07:57:46 +00:00
|
|
|
#define ZYNQ_GEM_TSR_DONE 0x00000020 /* Tx done mask */
|
|
|
|
|
2016-03-25 07:23:44 +00:00
|
|
|
#define ZYNQ_GEM_PCS_CTL_ANEG_ENBL 0x1000
|
|
|
|
|
2018-11-26 10:57:39 +00:00
|
|
|
#define ZYNQ_GEM_DCFG_DBG6_DMA_64B BIT(23)
|
|
|
|
|
2013-04-22 12:41:09 +00:00
|
|
|
/* Use MII register 1 (MII status register) to detect PHY */
|
|
|
|
#define PHY_DETECT_REG 1
|
|
|
|
|
|
|
|
/* Mask used to verify certain PHY features (or register contents)
|
|
|
|
* in the register above:
|
|
|
|
* 0x1000: 10Mbps full duplex support
|
|
|
|
* 0x0800: 10Mbps half duplex support
|
|
|
|
* 0x0008: Auto-negotiation support
|
|
|
|
*/
|
|
|
|
#define PHY_DETECT_MASK 0x1808
|
|
|
|
|
2013-11-08 17:25:48 +00:00
|
|
|
/* TX BD status masks */
|
|
|
|
#define ZYNQ_GEM_TXBUF_FRMLEN_MASK 0x000007ff
|
|
|
|
#define ZYNQ_GEM_TXBUF_EXHAUSTED 0x08000000
|
|
|
|
#define ZYNQ_GEM_TXBUF_UNDERRUN 0x10000000
|
|
|
|
|
2013-11-21 21:39:01 +00:00
|
|
|
/* Clock frequencies for different speeds */
|
|
|
|
#define ZYNQ_GEM_FREQUENCY_10 2500000UL
|
|
|
|
#define ZYNQ_GEM_FREQUENCY_100 25000000UL
|
|
|
|
#define ZYNQ_GEM_FREQUENCY_1000 125000000UL
|
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
#define RXCLK_EN BIT(0)
|
|
|
|
|
2012-09-13 20:23:34 +00:00
|
|
|
/* Device registers */
|
|
|
|
struct zynq_gem_regs {
|
2015-10-05 09:49:43 +00:00
|
|
|
u32 nwctrl; /* 0x0 - Network Control reg */
|
|
|
|
u32 nwcfg; /* 0x4 - Network Config reg */
|
|
|
|
u32 nwsr; /* 0x8 - Network Status reg */
|
2012-09-13 20:23:34 +00:00
|
|
|
u32 reserved1;
|
2015-10-05 09:49:43 +00:00
|
|
|
u32 dmacr; /* 0x10 - DMA Control reg */
|
|
|
|
u32 txsr; /* 0x14 - TX Status reg */
|
|
|
|
u32 rxqbase; /* 0x18 - RX Q Base address reg */
|
|
|
|
u32 txqbase; /* 0x1c - TX Q Base address reg */
|
|
|
|
u32 rxsr; /* 0x20 - RX Status reg */
|
2012-09-13 20:23:34 +00:00
|
|
|
u32 reserved2[2];
|
2015-10-05 09:49:43 +00:00
|
|
|
u32 idr; /* 0x2c - Interrupt Disable reg */
|
2012-09-13 20:23:34 +00:00
|
|
|
u32 reserved3;
|
2015-10-05 09:49:43 +00:00
|
|
|
u32 phymntnc; /* 0x34 - Phy Maintaince reg */
|
2012-09-13 20:23:34 +00:00
|
|
|
u32 reserved4[18];
|
2015-10-05 09:49:43 +00:00
|
|
|
u32 hashl; /* 0x80 - Hash Low address reg */
|
|
|
|
u32 hashh; /* 0x84 - Hash High address reg */
|
2012-09-13 20:23:34 +00:00
|
|
|
#define LADDR_LOW 0
|
|
|
|
#define LADDR_HIGH 1
|
2015-10-05 09:49:43 +00:00
|
|
|
u32 laddr[4][LADDR_HIGH + 1]; /* 0x8c - Specific1 addr low/high reg */
|
|
|
|
u32 match[4]; /* 0xa8 - Type ID1 Match reg */
|
2012-09-13 20:23:34 +00:00
|
|
|
u32 reserved6[18];
|
2015-10-05 10:49:48 +00:00
|
|
|
#define STAT_SIZE 44
|
|
|
|
u32 stat[STAT_SIZE]; /* 0x100 - Octects transmitted Low reg */
|
2016-03-25 07:23:44 +00:00
|
|
|
u32 reserved9[20];
|
|
|
|
u32 pcscntrl;
|
2018-11-26 10:57:39 +00:00
|
|
|
u32 rserved12[36];
|
|
|
|
u32 dcfg6; /* 0x294 Design config reg6 */
|
|
|
|
u32 reserved7[106];
|
2015-09-26 06:50:07 +00:00
|
|
|
u32 transmit_q1_ptr; /* 0x440 - Transmit priority queue 1 */
|
|
|
|
u32 reserved8[15];
|
|
|
|
u32 receive_q1_ptr; /* 0x480 - Receive priority queue 1 */
|
2018-11-26 10:57:38 +00:00
|
|
|
u32 reserved10[17];
|
|
|
|
u32 upper_txqbase; /* 0x4C8 - Upper tx_q base addr */
|
|
|
|
u32 reserved11[2];
|
|
|
|
u32 upper_rxqbase; /* 0x4D4 - Upper rx_q base addr */
|
2012-09-13 20:23:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* BD descriptors */
|
|
|
|
struct emac_bd {
|
|
|
|
u32 addr; /* Next descriptor pointer */
|
|
|
|
u32 status;
|
2018-11-26 10:57:38 +00:00
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
u32 addr_hi;
|
|
|
|
u32 reserved;
|
|
|
|
#endif
|
2012-09-13 20:23:34 +00:00
|
|
|
};
|
|
|
|
|
2019-05-22 12:12:20 +00:00
|
|
|
/* Reduce amount of BUFs if you have limited amount of memory */
|
2015-04-15 06:45:01 +00:00
|
|
|
#define RX_BUF 32
|
2013-11-08 17:25:48 +00:00
|
|
|
/* Page table entries are set to 1MB, or multiples of 1MB
|
|
|
|
* (not < 1MB). driver uses less bd's so use 1MB bdspace.
|
|
|
|
*/
|
|
|
|
#define BD_SPACE 0x100000
|
|
|
|
/* BD separation space */
|
2015-08-17 07:45:53 +00:00
|
|
|
#define BD_SEPRN_SPACE (RX_BUF * sizeof(struct emac_bd))
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-09-26 06:50:07 +00:00
|
|
|
/* Setup the first free TX descriptor */
|
|
|
|
#define TX_FREE_DESC 2
|
|
|
|
|
2012-09-13 20:23:34 +00:00
|
|
|
/* Initialized, rxbd_current, rx_first_buf must be 0 after init */
|
|
|
|
struct zynq_gem_priv {
|
2013-11-08 17:25:48 +00:00
|
|
|
struct emac_bd *tx_bd;
|
|
|
|
struct emac_bd *rx_bd;
|
|
|
|
char *rxbuffers;
|
2012-09-13 20:23:34 +00:00
|
|
|
u32 rxbd_current;
|
|
|
|
u32 rx_first_buf;
|
|
|
|
int phyaddr;
|
2013-01-24 12:04:12 +00:00
|
|
|
int init;
|
2015-11-30 09:24:15 +00:00
|
|
|
struct zynq_gem_regs *iobase;
|
2016-05-30 08:43:11 +00:00
|
|
|
struct zynq_gem_regs *mdiobase;
|
2015-10-07 14:42:56 +00:00
|
|
|
phy_interface_t interface;
|
2012-09-13 20:23:34 +00:00
|
|
|
struct phy_device *phydev;
|
2018-07-16 12:55:45 +00:00
|
|
|
ofnode phy_of_node;
|
2012-09-13 20:23:34 +00:00
|
|
|
struct mii_dev *bus;
|
2021-02-03 10:10:48 +00:00
|
|
|
struct clk rx_clk;
|
|
|
|
struct clk tx_clk;
|
2018-04-12 10:22:17 +00:00
|
|
|
u32 max_speed;
|
2017-11-23 07:26:55 +00:00
|
|
|
bool int_pcs;
|
2018-11-26 10:57:39 +00:00
|
|
|
bool dma_64bit;
|
2021-02-03 10:10:48 +00:00
|
|
|
u32 clk_en_info;
|
2012-09-13 20:23:34 +00:00
|
|
|
};
|
|
|
|
|
2018-06-13 08:00:30 +00:00
|
|
|
static int phy_setup_op(struct zynq_gem_priv *priv, u32 phy_addr, u32 regnum,
|
2015-11-30 09:24:15 +00:00
|
|
|
u32 op, u16 *data)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
|
|
|
u32 mgtcr;
|
2016-05-30 08:43:11 +00:00
|
|
|
struct zynq_gem_regs *regs = priv->mdiobase;
|
2016-12-12 08:47:26 +00:00
|
|
|
int err;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2018-01-23 16:14:55 +00:00
|
|
|
err = wait_for_bit_le32(®s->nwsr, ZYNQ_GEM_NWSR_MDIOIDLE_MASK,
|
|
|
|
true, 20000, false);
|
2016-12-12 08:47:26 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
/* Construct mgtcr mask for the operation */
|
|
|
|
mgtcr = ZYNQ_GEM_PHYMNTNC_OP_MASK | op |
|
|
|
|
(phy_addr << ZYNQ_GEM_PHYMNTNC_PHYAD_SHIFT_MASK) |
|
|
|
|
(regnum << ZYNQ_GEM_PHYMNTNC_PHREG_SHIFT_MASK) | *data;
|
|
|
|
|
|
|
|
/* Write mgtcr and wait for completion */
|
|
|
|
writel(mgtcr, ®s->phymntnc);
|
|
|
|
|
2018-01-23 16:14:55 +00:00
|
|
|
err = wait_for_bit_le32(®s->nwsr, ZYNQ_GEM_NWSR_MDIOIDLE_MASK,
|
|
|
|
true, 20000, false);
|
2016-12-12 08:47:26 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
if (op == ZYNQ_GEM_PHYMNTNC_OP_R_MASK)
|
|
|
|
*data = readl(®s->phymntnc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-13 08:00:30 +00:00
|
|
|
static int phyread(struct zynq_gem_priv *priv, u32 phy_addr,
|
2015-11-30 09:24:15 +00:00
|
|
|
u32 regnum, u16 *val)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2018-06-13 08:00:30 +00:00
|
|
|
int ret;
|
2015-10-07 14:34:51 +00:00
|
|
|
|
2015-11-30 09:24:15 +00:00
|
|
|
ret = phy_setup_op(priv, phy_addr, regnum,
|
|
|
|
ZYNQ_GEM_PHYMNTNC_OP_R_MASK, val);
|
2015-10-07 14:34:51 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
debug("%s: phy_addr %d, regnum 0x%x, val 0x%x\n", __func__,
|
|
|
|
phy_addr, regnum, *val);
|
|
|
|
|
|
|
|
return ret;
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2018-06-13 08:00:30 +00:00
|
|
|
static int phywrite(struct zynq_gem_priv *priv, u32 phy_addr,
|
2015-11-30 09:24:15 +00:00
|
|
|
u32 regnum, u16 data)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2015-10-07 14:34:51 +00:00
|
|
|
debug("%s: phy_addr %d, regnum 0x%x, data 0x%x\n", __func__, phy_addr,
|
|
|
|
regnum, data);
|
|
|
|
|
2015-11-30 09:24:15 +00:00
|
|
|
return phy_setup_op(priv, phy_addr, regnum,
|
|
|
|
ZYNQ_GEM_PHYMNTNC_OP_W_MASK, &data);
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_setup_mac(struct udevice *dev)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
|
|
|
u32 i, macaddrlow, macaddrhigh;
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
|
|
|
struct zynq_gem_regs *regs = priv->iobase;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
/* Set the MAC bits [31:0] in BOT */
|
2015-11-30 13:14:56 +00:00
|
|
|
macaddrlow = pdata->enetaddr[0];
|
|
|
|
macaddrlow |= pdata->enetaddr[1] << 8;
|
|
|
|
macaddrlow |= pdata->enetaddr[2] << 16;
|
|
|
|
macaddrlow |= pdata->enetaddr[3] << 24;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
/* Set MAC bits [47:32] in TOP */
|
2015-11-30 13:14:56 +00:00
|
|
|
macaddrhigh = pdata->enetaddr[4];
|
|
|
|
macaddrhigh |= pdata->enetaddr[5] << 8;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
writel(0, ®s->laddr[i][LADDR_LOW]);
|
|
|
|
writel(0, ®s->laddr[i][LADDR_HIGH]);
|
|
|
|
/* Do not use MATCHx register */
|
|
|
|
writel(0, ®s->match[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(macaddrlow, ®s->laddr[0][LADDR_LOW]);
|
|
|
|
writel(macaddrhigh, ®s->laddr[0][LADDR_HIGH]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_phy_init(struct udevice *dev)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2015-11-30 12:38:32 +00:00
|
|
|
int ret;
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
2016-05-30 08:43:11 +00:00
|
|
|
struct zynq_gem_regs *regs_mdio = priv->mdiobase;
|
2012-09-13 20:23:34 +00:00
|
|
|
const u32 supported = SUPPORTED_10baseT_Half |
|
|
|
|
SUPPORTED_10baseT_Full |
|
|
|
|
SUPPORTED_100baseT_Half |
|
|
|
|
SUPPORTED_100baseT_Full |
|
|
|
|
SUPPORTED_1000baseT_Half |
|
|
|
|
SUPPORTED_1000baseT_Full;
|
|
|
|
|
2015-11-30 12:58:36 +00:00
|
|
|
/* Enable only MDIO bus */
|
2016-05-30 08:43:11 +00:00
|
|
|
writel(ZYNQ_GEM_NWCTRL_MDEN_MASK, ®s_mdio->nwctrl);
|
2015-11-30 12:58:36 +00:00
|
|
|
|
2015-11-30 12:54:43 +00:00
|
|
|
priv->phydev = phy_connect(priv->bus, priv->phyaddr, dev,
|
|
|
|
priv->interface);
|
2015-11-30 13:03:37 +00:00
|
|
|
if (!priv->phydev)
|
|
|
|
return -ENODEV;
|
2015-11-30 12:54:43 +00:00
|
|
|
|
2018-04-12 10:22:17 +00:00
|
|
|
if (priv->max_speed) {
|
|
|
|
ret = phy_set_supported(priv->phydev, priv->max_speed);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-03-27 12:09:59 +00:00
|
|
|
priv->phydev->supported &= supported | ADVERTISED_Pause |
|
|
|
|
ADVERTISED_Asym_Pause;
|
|
|
|
|
2015-11-30 12:54:43 +00:00
|
|
|
priv->phydev->advertising = priv->phydev->supported;
|
2018-07-16 12:55:45 +00:00
|
|
|
priv->phydev->node = priv->phy_of_node;
|
2016-05-02 20:45:57 +00:00
|
|
|
|
2016-05-18 12:37:23 +00:00
|
|
|
return phy_config(priv->phydev);
|
2015-11-30 12:54:43 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_init(struct udevice *dev)
|
2015-11-30 12:54:43 +00:00
|
|
|
{
|
2016-02-05 07:52:11 +00:00
|
|
|
u32 i, nwconfig;
|
2016-05-18 10:37:22 +00:00
|
|
|
int ret;
|
2015-11-30 12:54:43 +00:00
|
|
|
unsigned long clk_rate = 0;
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
|
|
|
struct zynq_gem_regs *regs = priv->iobase;
|
2016-05-30 08:43:11 +00:00
|
|
|
struct zynq_gem_regs *regs_mdio = priv->mdiobase;
|
2015-11-30 12:54:43 +00:00
|
|
|
struct emac_bd *dummy_tx_bd = &priv->tx_bd[TX_FREE_DESC];
|
|
|
|
struct emac_bd *dummy_rx_bd = &priv->tx_bd[TX_FREE_DESC + 2];
|
|
|
|
|
2018-11-26 10:57:39 +00:00
|
|
|
if (readl(®s->dcfg6) & ZYNQ_GEM_DCFG_DBG6_DMA_64B)
|
|
|
|
priv->dma_64bit = true;
|
|
|
|
else
|
|
|
|
priv->dma_64bit = false;
|
|
|
|
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
if (!priv->dma_64bit) {
|
|
|
|
printf("ERR: %s: Using 64-bit DMA but HW doesn't support it\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (priv->dma_64bit)
|
|
|
|
debug("WARN: %s: Not using 64-bit dma even HW supports it\n",
|
|
|
|
__func__);
|
|
|
|
#endif
|
|
|
|
|
2013-01-24 12:04:12 +00:00
|
|
|
if (!priv->init) {
|
|
|
|
/* Disable all interrupts */
|
|
|
|
writel(0xFFFFFFFF, ®s->idr);
|
|
|
|
|
|
|
|
/* Disable the receiver & transmitter */
|
|
|
|
writel(0, ®s->nwctrl);
|
|
|
|
writel(0, ®s->txsr);
|
|
|
|
writel(0, ®s->rxsr);
|
|
|
|
writel(0, ®s->phymntnc);
|
|
|
|
|
|
|
|
/* Clear the Hash registers for the mac address
|
|
|
|
* pointed by AddressPtr
|
|
|
|
*/
|
|
|
|
writel(0x0, ®s->hashl);
|
|
|
|
/* Write bits [63:32] in TOP */
|
|
|
|
writel(0x0, ®s->hashh);
|
|
|
|
|
|
|
|
/* Clear all counters */
|
2015-10-05 10:49:48 +00:00
|
|
|
for (i = 0; i < STAT_SIZE; i++)
|
2013-01-24 12:04:12 +00:00
|
|
|
readl(®s->stat[i]);
|
|
|
|
|
|
|
|
/* Setup RxBD space */
|
2013-11-08 17:25:48 +00:00
|
|
|
memset(priv->rx_bd, 0, RX_BUF * sizeof(struct emac_bd));
|
2013-01-24 12:04:12 +00:00
|
|
|
|
|
|
|
for (i = 0; i < RX_BUF; i++) {
|
|
|
|
priv->rx_bd[i].status = 0xF0000000;
|
|
|
|
priv->rx_bd[i].addr =
|
2018-11-26 10:57:38 +00:00
|
|
|
(lower_32_bits((ulong)(priv->rxbuffers)
|
|
|
|
+ (i * PKTSIZE_ALIGN)));
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
priv->rx_bd[i].addr_hi =
|
|
|
|
(upper_32_bits((ulong)(priv->rxbuffers)
|
|
|
|
+ (i * PKTSIZE_ALIGN)));
|
|
|
|
#endif
|
|
|
|
}
|
2013-01-24 12:04:12 +00:00
|
|
|
/* WRAP bit to last BD */
|
|
|
|
priv->rx_bd[--i].addr |= ZYNQ_GEM_RXBUF_WRAP_MASK;
|
|
|
|
/* Write RxBDs to IP */
|
2018-11-26 10:57:38 +00:00
|
|
|
writel(lower_32_bits((ulong)priv->rx_bd), ®s->rxqbase);
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
writel(upper_32_bits((ulong)priv->rx_bd), ®s->upper_rxqbase);
|
|
|
|
#endif
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2013-01-24 12:04:12 +00:00
|
|
|
/* Setup for DMA Configuration register */
|
|
|
|
writel(ZYNQ_GEM_DMACR_INIT, ®s->dmacr);
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2013-01-24 12:04:12 +00:00
|
|
|
/* Setup for Network Control register, MDIO, Rx and Tx enable */
|
2016-05-30 08:43:11 +00:00
|
|
|
setbits_le32(®s_mdio->nwctrl, ZYNQ_GEM_NWCTRL_MDEN_MASK);
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-09-26 06:50:07 +00:00
|
|
|
/* Disable the second priority queue */
|
|
|
|
dummy_tx_bd->addr = 0;
|
2018-11-26 10:57:38 +00:00
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
dummy_tx_bd->addr_hi = 0;
|
|
|
|
#endif
|
2015-09-26 06:50:07 +00:00
|
|
|
dummy_tx_bd->status = ZYNQ_GEM_TXBUF_WRAP_MASK |
|
|
|
|
ZYNQ_GEM_TXBUF_LAST_MASK|
|
|
|
|
ZYNQ_GEM_TXBUF_USED_MASK;
|
|
|
|
|
|
|
|
dummy_rx_bd->addr = ZYNQ_GEM_RXBUF_WRAP_MASK |
|
|
|
|
ZYNQ_GEM_RXBUF_NEW_MASK;
|
2018-11-26 10:57:38 +00:00
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
dummy_rx_bd->addr_hi = 0;
|
|
|
|
#endif
|
2015-09-26 06:50:07 +00:00
|
|
|
dummy_rx_bd->status = 0;
|
|
|
|
|
|
|
|
writel((ulong)dummy_tx_bd, ®s->transmit_q1_ptr);
|
|
|
|
writel((ulong)dummy_rx_bd, ®s->receive_q1_ptr);
|
|
|
|
|
2013-01-24 12:04:12 +00:00
|
|
|
priv->init++;
|
|
|
|
}
|
|
|
|
|
2016-05-18 10:37:22 +00:00
|
|
|
ret = phy_startup(priv->phydev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-11-30 12:44:49 +00:00
|
|
|
if (!priv->phydev->link) {
|
|
|
|
printf("%s: No link.\n", priv->phydev->dev->name);
|
2013-11-12 13:25:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-02-05 07:52:11 +00:00
|
|
|
nwconfig = ZYNQ_GEM_NWCFG_INIT;
|
|
|
|
|
2017-11-23 07:26:55 +00:00
|
|
|
/*
|
|
|
|
* Set SGMII enable PCS selection only if internal PCS/PMA
|
|
|
|
* core is used and interface is SGMII.
|
|
|
|
*/
|
|
|
|
if (priv->interface == PHY_INTERFACE_MODE_SGMII &&
|
|
|
|
priv->int_pcs) {
|
2016-02-05 07:52:11 +00:00
|
|
|
nwconfig |= ZYNQ_GEM_NWCFG_SGMII_ENBL |
|
|
|
|
ZYNQ_GEM_NWCFG_PCS_SEL;
|
2016-03-25 07:23:44 +00:00
|
|
|
}
|
2016-02-05 07:52:11 +00:00
|
|
|
|
2015-11-30 12:44:49 +00:00
|
|
|
switch (priv->phydev->speed) {
|
2012-10-15 12:01:23 +00:00
|
|
|
case SPEED_1000:
|
2016-02-05 07:52:11 +00:00
|
|
|
writel(nwconfig | ZYNQ_GEM_NWCFG_SPEED1000,
|
2012-10-15 12:01:23 +00:00
|
|
|
®s->nwcfg);
|
2013-11-21 21:39:01 +00:00
|
|
|
clk_rate = ZYNQ_GEM_FREQUENCY_1000;
|
2012-10-15 12:01:23 +00:00
|
|
|
break;
|
|
|
|
case SPEED_100:
|
2016-02-05 07:52:11 +00:00
|
|
|
writel(nwconfig | ZYNQ_GEM_NWCFG_SPEED100,
|
2015-09-08 14:55:42 +00:00
|
|
|
®s->nwcfg);
|
2013-11-21 21:39:01 +00:00
|
|
|
clk_rate = ZYNQ_GEM_FREQUENCY_100;
|
2012-10-15 12:01:23 +00:00
|
|
|
break;
|
|
|
|
case SPEED_10:
|
2013-11-21 21:39:01 +00:00
|
|
|
clk_rate = ZYNQ_GEM_FREQUENCY_10;
|
2012-10-15 12:01:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-04-05 15:24:24 +00:00
|
|
|
|
2021-03-11 22:55:50 +00:00
|
|
|
#ifdef CONFIG_ARM64
|
|
|
|
if (priv->interface == PHY_INTERFACE_MODE_SGMII &&
|
|
|
|
priv->int_pcs) {
|
|
|
|
/*
|
|
|
|
* Disable AN for fixed link configuration, enable otherwise.
|
|
|
|
* Must be written after PCS_SEL is set in nwconfig,
|
|
|
|
* otherwise writes will not take effect.
|
|
|
|
*/
|
|
|
|
if (priv->phydev->phy_id != PHY_FIXED_ID)
|
|
|
|
writel(readl(®s->pcscntrl) | ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
|
|
|
|
®s->pcscntrl);
|
|
|
|
else
|
|
|
|
writel(readl(®s->pcscntrl) & ~ZYNQ_GEM_PCS_CTL_ANEG_ENBL,
|
|
|
|
®s->pcscntrl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
ret = clk_set_rate(&priv->tx_clk, clk_rate);
|
2021-02-09 14:28:15 +00:00
|
|
|
if (IS_ERR_VALUE(ret)) {
|
2017-01-17 15:27:25 +00:00
|
|
|
dev_err(dev, "failed to set tx clock rate\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
ret = clk_enable(&priv->tx_clk);
|
2021-02-09 14:28:15 +00:00
|
|
|
if (ret) {
|
2017-01-17 15:27:25 +00:00
|
|
|
dev_err(dev, "failed to enable tx clock\n");
|
|
|
|
return ret;
|
|
|
|
}
|
2012-10-15 12:01:23 +00:00
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
if (priv->clk_en_info & RXCLK_EN) {
|
|
|
|
ret = clk_enable(&priv->rx_clk);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "failed to enable rx clock\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-10-15 12:01:23 +00:00
|
|
|
setbits_le32(®s->nwctrl, ZYNQ_GEM_NWCTRL_RXEN_MASK |
|
|
|
|
ZYNQ_GEM_NWCTRL_TXEN_MASK);
|
|
|
|
|
2012-09-13 20:23:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_send(struct udevice *dev, void *ptr, int len)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2018-11-26 10:57:38 +00:00
|
|
|
dma_addr_t addr;
|
|
|
|
u32 size;
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
|
|
|
struct zynq_gem_regs *regs = priv->iobase;
|
2015-08-17 07:58:54 +00:00
|
|
|
struct emac_bd *current_bd = &priv->tx_bd[1];
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
/* Setup Tx BD */
|
2013-11-08 17:25:48 +00:00
|
|
|
memset(priv->tx_bd, 0, sizeof(struct emac_bd));
|
|
|
|
|
2018-11-26 10:57:38 +00:00
|
|
|
priv->tx_bd->addr = lower_32_bits((ulong)ptr);
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
priv->tx_bd->addr_hi = upper_32_bits((ulong)ptr);
|
|
|
|
#endif
|
2013-11-08 17:25:48 +00:00
|
|
|
priv->tx_bd->status = (len & ZYNQ_GEM_TXBUF_FRMLEN_MASK) |
|
2015-08-17 07:58:54 +00:00
|
|
|
ZYNQ_GEM_TXBUF_LAST_MASK;
|
|
|
|
/* Dummy descriptor to mark it as the last in descriptor chain */
|
|
|
|
current_bd->addr = 0x0;
|
2018-11-26 10:57:38 +00:00
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
current_bd->addr_hi = 0x0;
|
|
|
|
#endif
|
2015-08-17 07:58:54 +00:00
|
|
|
current_bd->status = ZYNQ_GEM_TXBUF_WRAP_MASK |
|
|
|
|
ZYNQ_GEM_TXBUF_LAST_MASK|
|
|
|
|
ZYNQ_GEM_TXBUF_USED_MASK;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-08-17 07:50:09 +00:00
|
|
|
/* setup BD */
|
2018-11-26 10:57:38 +00:00
|
|
|
writel(lower_32_bits((ulong)priv->tx_bd), ®s->txqbase);
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
writel(upper_32_bits((ulong)priv->tx_bd), ®s->upper_txqbase);
|
|
|
|
#endif
|
2015-08-17 07:50:09 +00:00
|
|
|
|
2015-10-25 07:48:54 +00:00
|
|
|
addr = (ulong) ptr;
|
2013-11-08 17:25:48 +00:00
|
|
|
addr &= ~(ARCH_DMA_MINALIGN - 1);
|
|
|
|
size = roundup(len, ARCH_DMA_MINALIGN);
|
|
|
|
flush_dcache_range(addr, addr + size);
|
|
|
|
barrier();
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
/* Start transmit */
|
|
|
|
setbits_le32(®s->nwctrl, ZYNQ_GEM_NWCTRL_STARTTX_MASK);
|
|
|
|
|
2013-11-08 17:25:48 +00:00
|
|
|
/* Read TX BD status */
|
|
|
|
if (priv->tx_bd->status & ZYNQ_GEM_TXBUF_EXHAUSTED)
|
|
|
|
printf("TX buffers exhausted in mid frame\n");
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2018-01-23 16:14:55 +00:00
|
|
|
return wait_for_bit_le32(®s->txsr, ZYNQ_GEM_TSR_DONE,
|
|
|
|
true, 20000, true);
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not check frame_recd flag in rx_status register 0x20 - just poll BD */
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_recv(struct udevice *dev, int flags, uchar **packetp)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
|
|
|
int frame_len;
|
2018-11-26 10:57:38 +00:00
|
|
|
dma_addr_t addr;
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
2012-09-13 20:23:34 +00:00
|
|
|
struct emac_bd *current_bd = &priv->rx_bd[priv->rxbd_current];
|
|
|
|
|
|
|
|
if (!(current_bd->addr & ZYNQ_GEM_RXBUF_NEW_MASK))
|
2015-12-09 13:26:48 +00:00
|
|
|
return -1;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
|
|
|
if (!(current_bd->status &
|
|
|
|
(ZYNQ_GEM_RXBUF_SOF_MASK | ZYNQ_GEM_RXBUF_EOF_MASK))) {
|
|
|
|
printf("GEM: SOF or EOF not set for last buffer received!\n");
|
2015-12-09 13:26:48 +00:00
|
|
|
return -1;
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
frame_len = current_bd->status & ZYNQ_GEM_RXBUF_LEN_MASK;
|
2015-12-09 13:26:48 +00:00
|
|
|
if (!frame_len) {
|
|
|
|
printf("%s: Zero size packet?\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-11-08 17:25:48 +00:00
|
|
|
|
2018-11-26 10:57:38 +00:00
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
addr = (dma_addr_t)((current_bd->addr & ZYNQ_GEM_RXBUF_ADD_MASK)
|
|
|
|
| ((dma_addr_t)current_bd->addr_hi << 32));
|
|
|
|
#else
|
2015-12-09 13:26:48 +00:00
|
|
|
addr = current_bd->addr & ZYNQ_GEM_RXBUF_ADD_MASK;
|
2018-11-26 10:57:38 +00:00
|
|
|
#endif
|
2015-12-09 13:26:48 +00:00
|
|
|
addr &= ~(ARCH_DMA_MINALIGN - 1);
|
2018-11-26 10:57:38 +00:00
|
|
|
|
2015-12-09 13:26:48 +00:00
|
|
|
*packetp = (uchar *)(uintptr_t)addr;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2018-12-17 08:12:30 +00:00
|
|
|
invalidate_dcache_range(addr, addr + roundup(PKTSIZE_ALIGN, ARCH_DMA_MINALIGN));
|
|
|
|
barrier();
|
|
|
|
|
2015-12-09 13:26:48 +00:00
|
|
|
return frame_len;
|
|
|
|
}
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-12-09 13:26:48 +00:00
|
|
|
static int zynq_gem_free_pkt(struct udevice *dev, uchar *packet, int length)
|
|
|
|
{
|
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
|
|
|
struct emac_bd *current_bd = &priv->rx_bd[priv->rxbd_current];
|
|
|
|
struct emac_bd *first_bd;
|
2020-02-23 15:01:29 +00:00
|
|
|
dma_addr_t addr;
|
2015-12-09 13:26:48 +00:00
|
|
|
|
|
|
|
if (current_bd->status & ZYNQ_GEM_RXBUF_SOF_MASK) {
|
|
|
|
priv->rx_first_buf = priv->rxbd_current;
|
|
|
|
} else {
|
|
|
|
current_bd->addr &= ~ZYNQ_GEM_RXBUF_NEW_MASK;
|
|
|
|
current_bd->status = 0xF0000000; /* FIXME */
|
|
|
|
}
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-12-09 13:26:48 +00:00
|
|
|
if (current_bd->status & ZYNQ_GEM_RXBUF_EOF_MASK) {
|
|
|
|
first_bd = &priv->rx_bd[priv->rx_first_buf];
|
|
|
|
first_bd->addr &= ~ZYNQ_GEM_RXBUF_NEW_MASK;
|
|
|
|
first_bd->status = 0xF0000000;
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2020-02-23 15:01:29 +00:00
|
|
|
/* Flush the cache for the packet as well */
|
|
|
|
#if defined(CONFIG_PHYS_64BIT)
|
|
|
|
addr = (dma_addr_t)((current_bd->addr & ZYNQ_GEM_RXBUF_ADD_MASK)
|
|
|
|
| ((dma_addr_t)current_bd->addr_hi << 32));
|
|
|
|
#else
|
|
|
|
addr = current_bd->addr & ZYNQ_GEM_RXBUF_ADD_MASK;
|
|
|
|
#endif
|
|
|
|
flush_dcache_range(addr, addr + roundup(PKTSIZE_ALIGN,
|
|
|
|
ARCH_DMA_MINALIGN));
|
|
|
|
barrier();
|
|
|
|
|
2015-12-09 13:26:48 +00:00
|
|
|
if ((++priv->rxbd_current) >= RX_BUF)
|
|
|
|
priv->rxbd_current = 0;
|
|
|
|
|
2015-12-09 13:16:32 +00:00
|
|
|
return 0;
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static void zynq_gem_halt(struct udevice *dev)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
|
|
|
struct zynq_gem_regs *regs = priv->iobase;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2012-10-15 12:01:23 +00:00
|
|
|
clrsetbits_le32(®s->nwctrl, ZYNQ_GEM_NWCTRL_RXEN_MASK |
|
|
|
|
ZYNQ_GEM_NWCTRL_TXEN_MASK, 0);
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 17:57:03 +00:00
|
|
|
__weak int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int zynq_gem_read_rom_mac(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2016-01-26 17:57:03 +00:00
|
|
|
|
2017-04-03 14:18:53 +00:00
|
|
|
if (!pdata)
|
|
|
|
return -ENOSYS;
|
2016-01-26 17:57:03 +00:00
|
|
|
|
2017-04-03 14:18:53 +00:00
|
|
|
return zynq_board_read_rom_ethaddr(pdata->enetaddr);
|
2016-01-26 17:57:03 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_miiphy_read(struct mii_dev *bus, int addr,
|
|
|
|
int devad, int reg)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = bus->priv;
|
2012-09-13 20:23:34 +00:00
|
|
|
int ret;
|
2018-06-14 07:08:44 +00:00
|
|
|
u16 val = 0;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
ret = phyread(priv, addr, reg, &val);
|
|
|
|
debug("%s 0x%x, 0x%x, 0x%x, 0x%x\n", __func__, addr, reg, val, ret);
|
|
|
|
return val;
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_miiphy_write(struct mii_dev *bus, int addr, int devad,
|
|
|
|
int reg, u16 value)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = bus->priv;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
debug("%s 0x%x, 0x%x, 0x%x\n", __func__, addr, reg, value);
|
|
|
|
return phywrite(priv, addr, reg, value);
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_probe(struct udevice *dev)
|
2012-09-13 20:23:34 +00:00
|
|
|
{
|
2013-11-08 17:25:48 +00:00
|
|
|
void *bd_space;
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2013-11-08 17:25:48 +00:00
|
|
|
/* Align rxbuffers to ARCH_DMA_MINALIGN */
|
|
|
|
priv->rxbuffers = memalign(ARCH_DMA_MINALIGN, RX_BUF * PKTSIZE_ALIGN);
|
2018-06-13 13:20:35 +00:00
|
|
|
if (!priv->rxbuffers)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-11-08 17:25:48 +00:00
|
|
|
memset(priv->rxbuffers, 0, RX_BUF * PKTSIZE_ALIGN);
|
2020-01-15 09:15:13 +00:00
|
|
|
ulong addr = (ulong)priv->rxbuffers;
|
2018-12-17 08:12:30 +00:00
|
|
|
flush_dcache_range(addr, addr + roundup(RX_BUF * PKTSIZE_ALIGN, ARCH_DMA_MINALIGN));
|
|
|
|
barrier();
|
2013-11-08 17:25:48 +00:00
|
|
|
|
2014-12-06 07:27:53 +00:00
|
|
|
/* Align bd_space to MMU_SECTION_SHIFT */
|
2013-11-08 17:25:48 +00:00
|
|
|
bd_space = memalign(1 << MMU_SECTION_SHIFT, BD_SPACE);
|
2020-02-06 13:36:46 +00:00
|
|
|
if (!bd_space) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err1;
|
|
|
|
}
|
2018-06-13 13:20:35 +00:00
|
|
|
|
2015-04-15 11:31:28 +00:00
|
|
|
mmu_set_region_dcache_behaviour((phys_addr_t)bd_space,
|
|
|
|
BD_SPACE, DCACHE_OFF);
|
2013-11-08 17:25:48 +00:00
|
|
|
|
|
|
|
/* Initialize the bd spaces for tx and rx bd's */
|
|
|
|
priv->tx_bd = (struct emac_bd *)bd_space;
|
2015-10-25 07:48:54 +00:00
|
|
|
priv->rx_bd = (struct emac_bd *)((ulong)bd_space + BD_SEPRN_SPACE);
|
2013-11-08 17:25:48 +00:00
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
ret = clk_get_by_name(dev, "tx_clk", &priv->tx_clk);
|
2016-11-15 10:45:42 +00:00
|
|
|
if (ret < 0) {
|
2021-02-03 10:10:48 +00:00
|
|
|
dev_err(dev, "failed to get tx_clock\n");
|
2021-02-11 18:03:30 +00:00
|
|
|
goto err2;
|
2016-11-15 10:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
if (priv->clk_en_info & RXCLK_EN) {
|
|
|
|
ret = clk_get_by_name(dev, "rx_clk", &priv->rx_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "failed to get rx_clock\n");
|
2021-02-11 18:03:30 +00:00
|
|
|
goto err2;
|
2021-02-03 10:10:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
priv->bus = mdio_alloc();
|
|
|
|
priv->bus->read = zynq_gem_miiphy_read;
|
|
|
|
priv->bus->write = zynq_gem_miiphy_write;
|
|
|
|
priv->bus->priv = priv;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2020-12-17 04:20:07 +00:00
|
|
|
ret = mdio_register_seq(priv->bus, dev_seq(dev));
|
2015-11-30 13:14:56 +00:00
|
|
|
if (ret)
|
2020-02-06 13:36:46 +00:00
|
|
|
goto err2;
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2020-02-06 13:36:46 +00:00
|
|
|
ret = zynq_phy_init(dev);
|
|
|
|
if (ret)
|
2021-02-10 21:41:57 +00:00
|
|
|
goto err3;
|
2020-02-06 13:36:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2021-02-10 21:41:57 +00:00
|
|
|
err3:
|
|
|
|
mdio_unregister(priv->bus);
|
2020-02-06 13:36:46 +00:00
|
|
|
err2:
|
|
|
|
free(priv->tx_bd);
|
2021-02-11 18:03:30 +00:00
|
|
|
err1:
|
|
|
|
free(priv->rxbuffers);
|
2020-02-06 13:36:46 +00:00
|
|
|
return ret;
|
2015-11-30 13:14:56 +00:00
|
|
|
}
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
static int zynq_gem_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
free(priv->phydev);
|
|
|
|
mdio_unregister(priv->bus);
|
|
|
|
mdio_free(priv->bus);
|
2012-09-13 20:23:34 +00:00
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct eth_ops zynq_gem_ops = {
|
|
|
|
.start = zynq_gem_init,
|
|
|
|
.send = zynq_gem_send,
|
|
|
|
.recv = zynq_gem_recv,
|
2015-12-09 13:26:48 +00:00
|
|
|
.free_pkt = zynq_gem_free_pkt,
|
2015-11-30 13:14:56 +00:00
|
|
|
.stop = zynq_gem_halt,
|
|
|
|
.write_hwaddr = zynq_gem_setup_mac,
|
2016-01-26 17:57:03 +00:00
|
|
|
.read_rom_hwaddr = zynq_gem_read_rom_mac,
|
2015-11-30 13:14:56 +00:00
|
|
|
};
|
2015-11-30 12:58:36 +00:00
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int zynq_gem_of_to_plat(struct udevice *dev)
|
2015-11-30 13:14:56 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2015-11-30 13:14:56 +00:00
|
|
|
struct zynq_gem_priv *priv = dev_get_priv(dev);
|
2018-07-16 12:55:45 +00:00
|
|
|
struct ofnode_phandle_args phandle_args;
|
2015-11-30 13:17:50 +00:00
|
|
|
const char *phy_mode;
|
2015-11-30 13:14:56 +00:00
|
|
|
|
2018-07-16 12:55:45 +00:00
|
|
|
pdata->iobase = (phys_addr_t)dev_read_addr(dev);
|
2015-11-30 13:14:56 +00:00
|
|
|
priv->iobase = (struct zynq_gem_regs *)pdata->iobase;
|
2016-05-30 08:43:11 +00:00
|
|
|
priv->mdiobase = priv->iobase;
|
2015-11-30 13:14:56 +00:00
|
|
|
/* Hardcode for now */
|
2015-12-09 08:29:12 +00:00
|
|
|
priv->phyaddr = -1;
|
2015-11-30 13:14:56 +00:00
|
|
|
|
2018-09-20 07:42:27 +00:00
|
|
|
if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
|
|
|
|
&phandle_args)) {
|
2016-05-30 08:43:11 +00:00
|
|
|
fdt_addr_t addr;
|
|
|
|
ofnode parent;
|
|
|
|
|
2018-09-20 07:42:27 +00:00
|
|
|
debug("phy-handle does exist %s\n", dev->name);
|
|
|
|
priv->phyaddr = ofnode_read_u32_default(phandle_args.node,
|
|
|
|
"reg", -1);
|
|
|
|
priv->phy_of_node = phandle_args.node;
|
|
|
|
priv->max_speed = ofnode_read_u32_default(phandle_args.node,
|
|
|
|
"max-speed",
|
|
|
|
SPEED_1000);
|
2016-05-30 08:43:11 +00:00
|
|
|
|
|
|
|
parent = ofnode_get_parent(phandle_args.node);
|
|
|
|
addr = ofnode_get_addr(parent);
|
|
|
|
if (addr != FDT_ADDR_T_NONE) {
|
|
|
|
debug("MDIO bus not found %s\n", dev->name);
|
|
|
|
priv->mdiobase = (struct zynq_gem_regs *)addr;
|
|
|
|
}
|
2018-07-16 12:55:45 +00:00
|
|
|
}
|
2015-11-30 13:14:56 +00:00
|
|
|
|
2018-07-16 12:55:45 +00:00
|
|
|
phy_mode = dev_read_prop(dev, "phy-mode", NULL);
|
2015-11-30 13:17:50 +00:00
|
|
|
if (phy_mode)
|
|
|
|
pdata->phy_interface = phy_get_interface_by_name(phy_mode);
|
|
|
|
if (pdata->phy_interface == -1) {
|
|
|
|
debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
priv->interface = pdata->phy_interface;
|
|
|
|
|
2018-07-16 12:55:45 +00:00
|
|
|
priv->int_pcs = dev_read_bool(dev, "is-internal-pcspma");
|
2017-11-23 07:26:55 +00:00
|
|
|
|
2016-05-30 08:43:11 +00:00
|
|
|
printf("\nZYNQ GEM: %lx, mdio bus %lx, phyaddr %d, interface %s\n",
|
|
|
|
(ulong)priv->iobase, (ulong)priv->mdiobase, priv->phyaddr,
|
|
|
|
phy_string_for_interface(priv->interface));
|
2015-11-30 13:14:56 +00:00
|
|
|
|
2021-02-03 10:10:48 +00:00
|
|
|
priv->clk_en_info = dev_get_driver_data(dev);
|
|
|
|
|
2015-11-30 13:14:56 +00:00
|
|
|
return 0;
|
2012-09-13 20:23:34 +00:00
|
|
|
}
|
2015-11-30 13:14:56 +00:00
|
|
|
|
|
|
|
static const struct udevice_id zynq_gem_ids[] = {
|
2021-02-03 10:10:48 +00:00
|
|
|
{ .compatible = "cdns,versal-gem", .data = RXCLK_EN },
|
2015-11-30 13:14:56 +00:00
|
|
|
{ .compatible = "cdns,zynqmp-gem" },
|
|
|
|
{ .compatible = "cdns,zynq-gem" },
|
|
|
|
{ .compatible = "cdns,gem" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(zynq_gem) = {
|
|
|
|
.name = "zynq_gem",
|
|
|
|
.id = UCLASS_ETH,
|
|
|
|
.of_match = zynq_gem_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = zynq_gem_of_to_plat,
|
2015-11-30 13:14:56 +00:00
|
|
|
.probe = zynq_gem_probe,
|
|
|
|
.remove = zynq_gem_remove,
|
|
|
|
.ops = &zynq_gem_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct zynq_gem_priv),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct eth_pdata),
|
2015-11-30 13:14:56 +00:00
|
|
|
};
|