2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2009-07-21 15:32:21 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2009 Ilya Yanok, Emcraft Systems Ltd <yanok@emcraft.com>
|
|
|
|
* (C) Copyright 2008,2009 Eric Jarrige <eric.jarrige@armadeus.org>
|
|
|
|
* (C) Copyright 2008 Armadeus Systems nc
|
|
|
|
* (C) Copyright 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de>
|
|
|
|
* (C) Copyright 2007 Pengutronix, Juergen Beisert <j.beisert@pengutronix.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2016-12-05 23:00:49 +00:00
|
|
|
#include <dm.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2009-07-21 15:32:21 +00:00
|
|
|
#include <malloc.h>
|
2015-09-02 23:24:58 +00:00
|
|
|
#include <memalign.h>
|
2016-12-05 23:00:50 +00:00
|
|
|
#include <miiphy.h>
|
2009-07-21 15:32:21 +00:00
|
|
|
#include <net.h>
|
2014-10-08 20:57:40 +00:00
|
|
|
#include <netdev.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2018-10-04 17:59:20 +00:00
|
|
|
#include <power/regulator.h>
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2012-08-26 10:19:20 +00:00
|
|
|
#include <linux/compiler.h>
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#include <asm/arch/imx-regs.h>
|
2017-06-29 08:16:06 +00:00
|
|
|
#include <asm/mach-imx/sys_proto.h>
|
2018-06-17 13:22:39 +00:00
|
|
|
#include <asm-generic/gpio.h>
|
|
|
|
|
|
|
|
#include "fec_mxc.h"
|
2020-05-03 14:41:15 +00:00
|
|
|
#include <eth_phy.h>
|
2016-12-05 23:00:50 +00:00
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2012-08-29 03:49:49 +00:00
|
|
|
/*
|
|
|
|
* Timeout the transfer after 5 mS. This is usually a bit more, since
|
|
|
|
* the code in the tightloops this timeout is used in adds some overhead.
|
|
|
|
*/
|
|
|
|
#define FEC_XFER_TIMEOUT 5000
|
|
|
|
|
2014-08-25 16:34:16 +00:00
|
|
|
/*
|
|
|
|
* The standard 32-byte DMA alignment does not work on mx6solox, which requires
|
|
|
|
* 64-byte alignment in the DMA RX FEC buffer.
|
|
|
|
* Introduce the FEC_DMA_RX_MINALIGN which can cover mx6solox needs and also
|
|
|
|
* satisfies the alignment on other SoCs (32-bytes)
|
|
|
|
*/
|
|
|
|
#define FEC_DMA_RX_MINALIGN 64
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
#ifndef CONFIG_MII
|
|
|
|
#error "CONFIG_MII has to be defined!"
|
|
|
|
#endif
|
|
|
|
|
2012-03-15 18:33:25 +00:00
|
|
|
#ifndef CONFIG_FEC_XCV_TYPE
|
|
|
|
#define CONFIG_FEC_XCV_TYPE MII100
|
2011-09-11 18:05:33 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-08 23:18:10 +00:00
|
|
|
/*
|
|
|
|
* The i.MX28 operates with packets in big endian. We need to swap them before
|
|
|
|
* sending and after receiving.
|
|
|
|
*/
|
2012-03-15 18:33:25 +00:00
|
|
|
#ifdef CONFIG_MX28
|
|
|
|
#define CONFIG_FEC_MXC_SWAP_PACKET
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define RXDESC_PER_CACHELINE (ARCH_DMA_MINALIGN/sizeof(struct fec_bd))
|
|
|
|
|
|
|
|
/* Check various alignment issues at compile time */
|
|
|
|
#if ((ARCH_DMA_MINALIGN < 16) || (ARCH_DMA_MINALIGN % 16 != 0))
|
|
|
|
#error "ARCH_DMA_MINALIGN must be multiple of 16!"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ((PKTALIGN < ARCH_DMA_MINALIGN) || \
|
|
|
|
(PKTALIGN % ARCH_DMA_MINALIGN != 0))
|
|
|
|
#error "PKTALIGN must be multiple of ARCH_DMA_MINALIGN!"
|
2011-11-08 23:18:10 +00:00
|
|
|
#endif
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
#undef DEBUG
|
|
|
|
|
2012-03-15 18:33:25 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_SWAP_PACKET
|
2011-11-08 23:18:10 +00:00
|
|
|
static void swap_packet(uint32_t *packet, int length)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < DIV_ROUND_UP(length, 4); i++)
|
|
|
|
packet[i] = __swab32(packet[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* MII-interface related functions */
|
|
|
|
static int fec_mdio_read(struct ethernet_regs *eth, uint8_t phyaddr,
|
|
|
|
uint8_t regaddr)
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
|
|
|
uint32_t reg; /* convenient holder for the PHY register */
|
|
|
|
uint32_t phy; /* convenient holder for the PHY */
|
|
|
|
uint32_t start;
|
2012-02-07 14:08:47 +00:00
|
|
|
int val;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* reading from any PHY's register is done by properly
|
|
|
|
* programming the FEC's MII data register.
|
|
|
|
*/
|
2011-09-11 18:05:34 +00:00
|
|
|
writel(FEC_IEVENT_MII, ð->ievent);
|
2016-12-05 23:00:50 +00:00
|
|
|
reg = regaddr << FEC_MII_DATA_RA_SHIFT;
|
|
|
|
phy = phyaddr << FEC_MII_DATA_PA_SHIFT;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
writel(FEC_MII_DATA_ST | FEC_MII_DATA_OP_RD | FEC_MII_DATA_TA |
|
2011-09-11 18:05:34 +00:00
|
|
|
phy | reg, ð->mii_data);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* wait for the related interrupt */
|
2011-07-15 23:31:37 +00:00
|
|
|
start = get_timer(0);
|
2011-09-11 18:05:34 +00:00
|
|
|
while (!(readl(ð->ievent) & FEC_IEVENT_MII)) {
|
2009-07-21 15:32:21 +00:00
|
|
|
if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
|
|
|
|
printf("Read MDIO failed...\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* clear mii interrupt bit */
|
2011-09-11 18:05:34 +00:00
|
|
|
writel(FEC_IEVENT_MII, ð->ievent);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* it's now safe to read the PHY's register */
|
2012-02-07 14:08:47 +00:00
|
|
|
val = (unsigned short)readl(ð->mii_data);
|
2016-12-05 23:00:50 +00:00
|
|
|
debug("%s: phy: %02x reg:%02x val:%#x\n", __func__, phyaddr,
|
|
|
|
regaddr, val);
|
2012-02-07 14:08:47 +00:00
|
|
|
return val;
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:48:02 +00:00
|
|
|
#ifndef imx_get_fecclk
|
|
|
|
u32 __weak imx_get_fecclk(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-18 14:15:11 +00:00
|
|
|
static int fec_get_clk_rate(void *udev, int idx)
|
|
|
|
{
|
|
|
|
struct fec_priv *fec;
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
2019-10-25 09:48:02 +00:00
|
|
|
if (IS_ENABLED(CONFIG_IMX8) ||
|
|
|
|
CONFIG_IS_ENABLED(CLK_CCF)) {
|
|
|
|
dev = udev;
|
|
|
|
if (!dev) {
|
|
|
|
ret = uclass_get_device(UCLASS_ETH, idx, &dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't get FEC udev: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2018-10-18 14:15:11 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 09:48:02 +00:00
|
|
|
fec = dev_get_priv(dev);
|
|
|
|
if (fec)
|
|
|
|
return fec->clk_rate;
|
2018-10-18 14:15:11 +00:00
|
|
|
|
2019-10-25 09:48:02 +00:00
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
return imx_get_fecclk();
|
|
|
|
}
|
2018-10-18 14:15:11 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 16:40:41 +00:00
|
|
|
static void fec_mii_setspeed(struct ethernet_regs *eth)
|
2010-02-01 13:51:30 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
|
|
|
|
* and do not drop the Preamble.
|
2015-12-08 15:38:45 +00:00
|
|
|
*
|
|
|
|
* The i.MX28 and i.MX6 types have another field in the MSCR (aka
|
|
|
|
* MII_SPEED) register that defines the MDIO output hold time. Earlier
|
|
|
|
* versions are RAZ there, so just ignore the difference and write the
|
|
|
|
* register always.
|
|
|
|
* The minimal hold time according to IEE802.3 (clause 22) is 10 ns.
|
|
|
|
* HOLDTIME + 1 is the number of clk cycles the fec is holding the
|
|
|
|
* output.
|
|
|
|
* The HOLDTIME bitfield takes values between 0 and 7 (inclusive).
|
|
|
|
* Given that ceil(clkrate / 5000000) <= 64, the calculation for
|
|
|
|
* holdtime cannot result in a value greater than 3.
|
2010-02-01 13:51:30 +00:00
|
|
|
*/
|
2018-10-18 14:15:11 +00:00
|
|
|
u32 pclk;
|
|
|
|
u32 speed;
|
|
|
|
u32 hold;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fec_get_clk_rate(NULL, 0);
|
|
|
|
if (ret < 0) {
|
|
|
|
printf("Can't find FEC0 clk rate: %d\n", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pclk = ret;
|
|
|
|
speed = DIV_ROUND_UP(pclk, 5000000);
|
|
|
|
hold = DIV_ROUND_UP(pclk, 100000000) - 1;
|
|
|
|
|
2014-02-05 09:54:11 +00:00
|
|
|
#ifdef FEC_QUIRK_ENET_MAC
|
|
|
|
speed--;
|
|
|
|
#endif
|
2015-12-08 15:38:45 +00:00
|
|
|
writel(speed << 1 | hold << 8, ð->mii_speed);
|
2012-10-22 16:40:41 +00:00
|
|
|
debug("%s: mii_speed %08x\n", __func__, readl(ð->mii_speed));
|
2010-02-01 13:51:30 +00:00
|
|
|
}
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
static int fec_mdio_write(struct ethernet_regs *eth, uint8_t phyaddr,
|
|
|
|
uint8_t regaddr, uint16_t data)
|
2012-02-07 14:08:47 +00:00
|
|
|
{
|
2009-07-21 15:32:21 +00:00
|
|
|
uint32_t reg; /* convenient holder for the PHY register */
|
|
|
|
uint32_t phy; /* convenient holder for the PHY */
|
|
|
|
uint32_t start;
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
reg = regaddr << FEC_MII_DATA_RA_SHIFT;
|
|
|
|
phy = phyaddr << FEC_MII_DATA_PA_SHIFT;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
writel(FEC_MII_DATA_ST | FEC_MII_DATA_OP_WR |
|
2011-09-11 18:05:34 +00:00
|
|
|
FEC_MII_DATA_TA | phy | reg | data, ð->mii_data);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* wait for the MII interrupt */
|
2011-07-15 23:31:37 +00:00
|
|
|
start = get_timer(0);
|
2011-09-11 18:05:34 +00:00
|
|
|
while (!(readl(ð->ievent) & FEC_IEVENT_MII)) {
|
2009-07-21 15:32:21 +00:00
|
|
|
if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
|
|
|
|
printf("Write MDIO failed...\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* clear MII interrupt bit */
|
2011-09-11 18:05:34 +00:00
|
|
|
writel(FEC_IEVENT_MII, ð->ievent);
|
2016-12-05 23:00:50 +00:00
|
|
|
debug("%s: phy: %02x reg:%02x val:%#x\n", __func__, phyaddr,
|
|
|
|
regaddr, data);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
static int fec_phy_read(struct mii_dev *bus, int phyaddr, int dev_addr,
|
|
|
|
int regaddr)
|
2012-02-07 14:08:47 +00:00
|
|
|
{
|
2016-12-05 23:00:50 +00:00
|
|
|
return fec_mdio_read(bus->priv, phyaddr, regaddr);
|
2012-02-07 14:08:47 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
static int fec_phy_write(struct mii_dev *bus, int phyaddr, int dev_addr,
|
|
|
|
int regaddr, u16 data)
|
2012-02-07 14:08:47 +00:00
|
|
|
{
|
2016-12-05 23:00:50 +00:00
|
|
|
return fec_mdio_write(bus->priv, phyaddr, regaddr, data);
|
2012-02-07 14:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_PHYLIB
|
2009-07-21 15:32:21 +00:00
|
|
|
static int miiphy_restart_aneg(struct eth_device *dev)
|
|
|
|
{
|
2012-02-22 00:24:35 +00:00
|
|
|
int ret = 0;
|
|
|
|
#if !defined(CONFIG_FEC_MXC_NO_ANEG)
|
2011-09-15 23:13:47 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2012-02-07 14:08:47 +00:00
|
|
|
struct ethernet_regs *eth = fec->bus->priv;
|
2011-09-15 23:13:47 +00:00
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
/*
|
|
|
|
* Wake up from sleep if necessary
|
|
|
|
* Reset PHY, then delay 300ns
|
|
|
|
*/
|
2010-01-26 06:12:55 +00:00
|
|
|
#ifdef CONFIG_MX27
|
2012-02-07 14:08:47 +00:00
|
|
|
fec_mdio_write(eth, fec->phy_id, MII_DCOUNTER, 0x00FF);
|
2010-01-26 06:12:55 +00:00
|
|
|
#endif
|
2012-02-07 14:08:47 +00:00
|
|
|
fec_mdio_write(eth, fec->phy_id, MII_BMCR, BMCR_RESET);
|
2009-07-21 15:32:21 +00:00
|
|
|
udelay(1000);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Set the auto-negotiation advertisement register bits */
|
2012-02-07 14:08:47 +00:00
|
|
|
fec_mdio_write(eth, fec->phy_id, MII_ADVERTISE,
|
2016-12-05 23:00:50 +00:00
|
|
|
LPA_100FULL | LPA_100HALF | LPA_10FULL |
|
|
|
|
LPA_10HALF | PHY_ANLPAR_PSB_802_3);
|
2012-02-07 14:08:47 +00:00
|
|
|
fec_mdio_write(eth, fec->phy_id, MII_BMCR,
|
2016-12-05 23:00:50 +00:00
|
|
|
BMCR_ANENABLE | BMCR_ANRESTART);
|
2011-09-11 18:05:36 +00:00
|
|
|
|
|
|
|
if (fec->mii_postcall)
|
|
|
|
ret = fec->mii_postcall(fec->phy_id);
|
|
|
|
|
2012-02-22 00:24:35 +00:00
|
|
|
#endif
|
2011-09-11 18:05:36 +00:00
|
|
|
return ret;
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
2016-06-22 10:07:14 +00:00
|
|
|
#ifndef CONFIG_FEC_FIXED_SPEED
|
2009-07-21 15:32:21 +00:00
|
|
|
static int miiphy_wait_aneg(struct eth_device *dev)
|
|
|
|
{
|
|
|
|
uint32_t start;
|
2012-02-07 14:08:47 +00:00
|
|
|
int status;
|
2011-09-15 23:13:47 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2012-02-07 14:08:47 +00:00
|
|
|
struct ethernet_regs *eth = fec->bus->priv;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Wait for AN completion */
|
2011-07-15 23:31:37 +00:00
|
|
|
start = get_timer(0);
|
2009-07-21 15:32:21 +00:00
|
|
|
do {
|
|
|
|
if (get_timer(start) > (CONFIG_SYS_HZ * 5)) {
|
|
|
|
printf("%s: Autonegotiation timeout\n", dev->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-07 14:08:47 +00:00
|
|
|
status = fec_mdio_read(eth, fec->phy_id, MII_BMSR);
|
|
|
|
if (status < 0) {
|
|
|
|
printf("%s: Autonegotiation failed. status: %d\n",
|
2016-12-05 23:00:50 +00:00
|
|
|
dev->name, status);
|
2009-07-21 15:32:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-12-23 20:40:12 +00:00
|
|
|
} while (!(status & BMSR_LSTATUS));
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-06-22 10:07:14 +00:00
|
|
|
#endif /* CONFIG_FEC_FIXED_SPEED */
|
2012-02-07 14:08:47 +00:00
|
|
|
#endif
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
static int fec_rx_task_enable(struct fec_priv *fec)
|
|
|
|
{
|
2012-08-29 03:49:51 +00:00
|
|
|
writel(FEC_R_DES_ACTIVE_RDAR, &fec->eth->r_des_active);
|
2009-07-21 15:32:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fec_rx_task_disable(struct fec_priv *fec)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fec_tx_task_enable(struct fec_priv *fec)
|
|
|
|
{
|
2012-08-29 03:49:51 +00:00
|
|
|
writel(FEC_X_DES_ACTIVE_TDAR, &fec->eth->x_des_active);
|
2009-07-21 15:32:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fec_tx_task_disable(struct fec_priv *fec)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize receive task's buffer descriptors
|
|
|
|
* @param[in] fec all we know about the device yet
|
|
|
|
* @param[in] count receive buffer count to be allocated
|
2012-03-15 18:33:25 +00:00
|
|
|
* @param[in] dsize desired size of each receive buffer
|
2009-07-21 15:32:21 +00:00
|
|
|
* @return 0 on success
|
|
|
|
*
|
2013-10-12 18:36:25 +00:00
|
|
|
* Init all RX descriptors to default values.
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2013-10-12 18:36:25 +00:00
|
|
|
static void fec_rbd_init(struct fec_priv *fec, int count, int dsize)
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2012-03-15 18:33:25 +00:00
|
|
|
uint32_t size;
|
2018-01-10 05:20:44 +00:00
|
|
|
ulong data;
|
2012-03-15 18:33:25 +00:00
|
|
|
int i;
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
/*
|
2013-10-12 18:36:25 +00:00
|
|
|
* Reload the RX descriptors with default values and wipe
|
|
|
|
* the RX buffers.
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2012-03-15 18:33:25 +00:00
|
|
|
size = roundup(dsize, ARCH_DMA_MINALIGN);
|
|
|
|
for (i = 0; i < count; i++) {
|
2018-01-10 05:20:44 +00:00
|
|
|
data = fec->rbd_base[i].data_pointer;
|
|
|
|
memset((void *)data, 0, dsize);
|
|
|
|
flush_dcache_range(data, data + size);
|
2013-10-12 18:36:25 +00:00
|
|
|
|
|
|
|
fec->rbd_base[i].status = FEC_RBD_EMPTY;
|
|
|
|
fec->rbd_base[i].data_length = 0;
|
2012-03-15 18:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the last RBD to close the ring. */
|
2013-10-12 18:36:25 +00:00
|
|
|
fec->rbd_base[i - 1].status = FEC_RBD_WRAP | FEC_RBD_EMPTY;
|
2009-07-21 15:32:21 +00:00
|
|
|
fec->rbd_index = 0;
|
|
|
|
|
2018-01-10 05:20:44 +00:00
|
|
|
flush_dcache_range((ulong)fec->rbd_base,
|
|
|
|
(ulong)fec->rbd_base + size);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize transmit task's buffer descriptors
|
|
|
|
* @param[in] fec all we know about the device yet
|
|
|
|
*
|
|
|
|
* Transmit buffers are created externally. We only have to init the BDs here.\n
|
|
|
|
* Note: There is a race condition in the hardware. When only one BD is in
|
|
|
|
* use it must be marked with the WRAP bit to use it for every transmitt.
|
|
|
|
* This bit in combination with the READY bit results into double transmit
|
|
|
|
* of each data buffer. It seems the state machine checks READY earlier then
|
|
|
|
* resetting it after the first transfer.
|
|
|
|
* Using two BDs solves this issue.
|
|
|
|
*/
|
|
|
|
static void fec_tbd_init(struct fec_priv *fec)
|
|
|
|
{
|
2018-01-10 05:20:44 +00:00
|
|
|
ulong addr = (ulong)fec->tbd_base;
|
2012-03-15 18:33:25 +00:00
|
|
|
unsigned size = roundup(2 * sizeof(struct fec_bd),
|
|
|
|
ARCH_DMA_MINALIGN);
|
2013-10-12 18:36:25 +00:00
|
|
|
|
|
|
|
memset(fec->tbd_base, 0, size);
|
|
|
|
fec->tbd_base[0].status = 0;
|
|
|
|
fec->tbd_base[1].status = FEC_TBD_WRAP;
|
2009-07-21 15:32:21 +00:00
|
|
|
fec->tbd_index = 0;
|
2013-10-12 18:36:25 +00:00
|
|
|
flush_dcache_range(addr, addr + size);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the given read buffer descriptor as free
|
|
|
|
* @param[in] last 1 if this is the last buffer descriptor in the chain, else 0
|
2016-12-05 23:00:50 +00:00
|
|
|
* @param[in] prbd buffer descriptor to mark free again
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2016-12-05 23:00:50 +00:00
|
|
|
static void fec_rbd_clean(int last, struct fec_bd *prbd)
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2012-03-15 18:33:25 +00:00
|
|
|
unsigned short flags = FEC_RBD_EMPTY;
|
2009-07-21 15:32:21 +00:00
|
|
|
if (last)
|
2012-03-15 18:33:25 +00:00
|
|
|
flags |= FEC_RBD_WRAP;
|
2016-12-05 23:00:50 +00:00
|
|
|
writew(flags, &prbd->status);
|
|
|
|
writew(0, &prbd->data_length);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:48 +00:00
|
|
|
static int fec_get_hwaddr(int dev_id, unsigned char *mac)
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2011-12-20 05:46:31 +00:00
|
|
|
imx_get_mac_from_fuse(dev_id, mac);
|
2015-04-08 06:41:04 +00:00
|
|
|
return !is_valid_ethaddr(mac);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static int fecmxc_set_hwaddr(struct udevice *dev)
|
|
|
|
#else
|
2010-02-01 13:51:30 +00:00
|
|
|
static int fec_set_hwaddr(struct eth_device *dev)
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fec_priv *fec = dev_get_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2016-12-05 23:00:49 +00:00
|
|
|
uchar *mac = pdata->enetaddr;
|
|
|
|
#else
|
2010-02-01 13:51:30 +00:00
|
|
|
uchar *mac = dev->enetaddr;
|
2009-07-21 15:32:21 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
writel(0, &fec->eth->iaddr1);
|
|
|
|
writel(0, &fec->eth->iaddr2);
|
|
|
|
writel(0, &fec->eth->gaddr1);
|
|
|
|
writel(0, &fec->eth->gaddr2);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Set physical address */
|
2009-07-21 15:32:21 +00:00
|
|
|
writel((mac[0] << 24) + (mac[1] << 16) + (mac[2] << 8) + mac[3],
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->paddr1);
|
2009-07-21 15:32:21 +00:00
|
|
|
writel((mac[4] << 24) + (mac[5] << 16) + 0x8808, &fec->eth->paddr2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Do initial configuration of the FEC registers */
|
2012-05-01 11:09:41 +00:00
|
|
|
static void fec_reg_setup(struct fec_priv *fec)
|
|
|
|
{
|
|
|
|
uint32_t rcntrl;
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Set interrupt mask register */
|
2012-05-01 11:09:41 +00:00
|
|
|
writel(0x00000000, &fec->eth->imask);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Clear FEC-Lite interrupt event register(IEVENT) */
|
2012-05-01 11:09:41 +00:00
|
|
|
writel(0xffffffff, &fec->eth->ievent);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Set FEC-Lite receive control register(R_CNTRL): */
|
2012-05-01 11:09:41 +00:00
|
|
|
|
|
|
|
/* Start with frame length = 1518, common for all modes. */
|
|
|
|
rcntrl = PKTSIZE << FEC_RCNTRL_MAX_FL_SHIFT;
|
net: fec_mxc: Fix setting of RCR for xMII
At least on i.MX25, the RMII mode did not work, which is fixed by this patch.
The MII_MODE bit of the FEC RCR register means xMII, i.e. 'not 7-wire', so set
it accordingly.
According to the xMII and 7-wire (aka GPSI) standards, full duplex should be
available on xMII, but not on 7-wire, so set FCE accordingly. The FEC may
support full duplex for 7-wire too, but the reference manual does not say that,
so avoid an invalid assumption. Actually, the choice between half and full
duplex also depends on the endpoint/switch/repeater configuration, so a config
option could be added for that, but there has been no need for it so far.
Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Joe Hershberger <joe.hershberger@gmail.com>
Cc: Stefano Babic <sbabic@denx.de>
2012-07-19 02:12:46 +00:00
|
|
|
if (fec->xcv_type != SEVENWIRE) /* xMII modes */
|
|
|
|
rcntrl |= FEC_RCNTRL_FCE | FEC_RCNTRL_MII_MODE;
|
|
|
|
if (fec->xcv_type == RGMII)
|
2012-05-01 11:09:41 +00:00
|
|
|
rcntrl |= FEC_RCNTRL_RGMII;
|
|
|
|
else if (fec->xcv_type == RMII)
|
|
|
|
rcntrl |= FEC_RCNTRL_RMII;
|
|
|
|
|
|
|
|
writel(rcntrl, &fec->eth->r_cntrl);
|
|
|
|
}
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
/**
|
|
|
|
* Start the FEC engine
|
|
|
|
* @param[in] dev Our device to handle
|
|
|
|
*/
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static int fec_open(struct udevice *dev)
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
static int fec_open(struct eth_device *edev)
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fec_priv *fec = dev_get_priv(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)edev->priv;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2012-02-07 14:08:46 +00:00
|
|
|
int speed;
|
2018-01-10 05:20:44 +00:00
|
|
|
ulong addr, size;
|
2012-03-15 18:33:25 +00:00
|
|
|
int i;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
debug("fec_open: fec_open(dev)\n");
|
|
|
|
/* full-duplex, heartbeat disabled */
|
|
|
|
writel(1 << 2, &fec->eth->x_cntrl);
|
|
|
|
fec->rbd_index = 0;
|
|
|
|
|
2012-03-15 18:33:25 +00:00
|
|
|
/* Invalidate all descriptors */
|
|
|
|
for (i = 0; i < FEC_RBD_NUM - 1; i++)
|
|
|
|
fec_rbd_clean(0, &fec->rbd_base[i]);
|
|
|
|
fec_rbd_clean(1, &fec->rbd_base[i]);
|
|
|
|
|
|
|
|
/* Flush the descriptors into RAM */
|
|
|
|
size = roundup(FEC_RBD_NUM * sizeof(struct fec_bd),
|
|
|
|
ARCH_DMA_MINALIGN);
|
2018-01-10 05:20:44 +00:00
|
|
|
addr = (ulong)fec->rbd_base;
|
2012-03-15 18:33:25 +00:00
|
|
|
flush_dcache_range(addr, addr + size);
|
|
|
|
|
2012-02-07 14:08:46 +00:00
|
|
|
#ifdef FEC_QUIRK_ENET_MAC
|
2011-12-16 05:17:07 +00:00
|
|
|
/* Enable ENET HW endian SWAP */
|
|
|
|
writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_DBSWAP,
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->ecntrl);
|
2011-12-16 05:17:07 +00:00
|
|
|
/* Enable ENET store and forward mode */
|
|
|
|
writel(readl(&fec->eth->x_wmrk) | FEC_X_WMRK_STRFWD,
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->x_wmrk);
|
2011-12-16 05:17:07 +00:00
|
|
|
#endif
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Enable FEC-Lite controller */
|
2010-01-26 06:12:55 +00:00
|
|
|
writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_ETHER_EN,
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->ecntrl);
|
|
|
|
|
2020-03-11 10:52:58 +00:00
|
|
|
#ifdef FEC_ENET_ENABLE_TXC_DELAY
|
|
|
|
writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_TXC_DLY,
|
|
|
|
&fec->eth->ecntrl);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FEC_ENET_ENABLE_RXC_DELAY
|
|
|
|
writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_RXC_DLY,
|
|
|
|
&fec->eth->ecntrl);
|
|
|
|
#endif
|
|
|
|
|
2013-09-13 03:36:27 +00:00
|
|
|
#if defined(CONFIG_MX25) || defined(CONFIG_MX53) || defined(CONFIG_MX6SL)
|
2010-01-26 06:12:57 +00:00
|
|
|
udelay(100);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* setup the MII gasket for RMII mode */
|
2010-01-26 06:12:57 +00:00
|
|
|
/* disable the gasket */
|
|
|
|
writew(0, &fec->eth->miigsk_enr);
|
|
|
|
|
|
|
|
/* wait for the gasket to be disabled */
|
|
|
|
while (readw(&fec->eth->miigsk_enr) & MIIGSK_ENR_READY)
|
|
|
|
udelay(2);
|
|
|
|
|
|
|
|
/* configure gasket for RMII, 50 MHz, no loopback, and no echo */
|
|
|
|
writew(MIIGSK_CFGR_IF_MODE_RMII, &fec->eth->miigsk_cfgr);
|
|
|
|
|
|
|
|
/* re-enable the gasket */
|
|
|
|
writew(MIIGSK_ENR_EN, &fec->eth->miigsk_enr);
|
|
|
|
|
|
|
|
/* wait until MII gasket is ready */
|
|
|
|
int max_loops = 10;
|
|
|
|
while ((readw(&fec->eth->miigsk_enr) & MIIGSK_ENR_READY) == 0) {
|
|
|
|
if (--max_loops <= 0) {
|
|
|
|
printf("WAIT for MII Gasket ready timed out\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2012-02-07 14:08:47 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
2012-10-22 16:40:45 +00:00
|
|
|
{
|
2012-02-07 14:08:47 +00:00
|
|
|
/* Start up the PHY */
|
2012-07-09 08:52:43 +00:00
|
|
|
int ret = phy_startup(fec->phydev);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
printf("Could not initialize PHY %s\n",
|
|
|
|
fec->phydev->dev->name);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-02-07 14:08:47 +00:00
|
|
|
speed = fec->phydev->speed;
|
|
|
|
}
|
2016-06-22 10:07:14 +00:00
|
|
|
#elif CONFIG_FEC_FIXED_SPEED
|
|
|
|
speed = CONFIG_FEC_FIXED_SPEED;
|
2012-02-07 14:08:47 +00:00
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
miiphy_wait_aneg(edev);
|
2012-02-07 14:08:46 +00:00
|
|
|
speed = miiphy_speed(edev->name, fec->phy_id);
|
2011-09-15 23:13:47 +00:00
|
|
|
miiphy_duplex(edev->name, fec->phy_id);
|
2012-02-07 14:08:47 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2012-02-07 14:08:46 +00:00
|
|
|
#ifdef FEC_QUIRK_ENET_MAC
|
|
|
|
{
|
|
|
|
u32 ecr = readl(&fec->eth->ecntrl) & ~FEC_ECNTRL_SPEED;
|
2013-05-27 22:55:43 +00:00
|
|
|
u32 rcr = readl(&fec->eth->r_cntrl) & ~FEC_RCNTRL_RMII_10T;
|
2012-02-07 14:08:46 +00:00
|
|
|
if (speed == _1000BASET)
|
|
|
|
ecr |= FEC_ECNTRL_SPEED;
|
|
|
|
else if (speed != _100BASET)
|
|
|
|
rcr |= FEC_RCNTRL_RMII_10T;
|
|
|
|
writel(ecr, &fec->eth->ecntrl);
|
|
|
|
writel(rcr, &fec->eth->r_cntrl);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
debug("%s:Speed=%i\n", __func__, speed);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Enable SmartDMA receive task */
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_rx_task_enable(fec);
|
|
|
|
|
|
|
|
udelay(100000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static int fecmxc_init(struct udevice *dev)
|
|
|
|
#else
|
2020-06-26 06:13:34 +00:00
|
|
|
static int fec_init(struct eth_device *dev, struct bd_info *bd)
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fec_priv *fec = dev_get_priv(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2018-01-10 05:20:44 +00:00
|
|
|
u8 *mib_ptr = (uint8_t *)&fec->eth->rmon_t_drop;
|
|
|
|
u8 *i;
|
|
|
|
ulong addr;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2010-10-13 20:31:08 +00:00
|
|
|
/* Initialize MAC address */
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
fecmxc_set_hwaddr(dev);
|
|
|
|
#else
|
2010-10-13 20:31:08 +00:00
|
|
|
fec_set_hwaddr(dev);
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2010-10-13 20:31:08 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Setup transmit descriptors, there are two in total. */
|
2013-10-12 18:36:25 +00:00
|
|
|
fec_tbd_init(fec);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2013-10-12 18:36:25 +00:00
|
|
|
/* Setup receive descriptors. */
|
|
|
|
fec_rbd_init(fec, FEC_RBD_NUM, FEC_MAX_PKT_SIZE);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2012-05-01 11:09:41 +00:00
|
|
|
fec_reg_setup(fec);
|
2011-09-11 18:05:31 +00:00
|
|
|
|
2012-07-19 02:12:58 +00:00
|
|
|
if (fec->xcv_type != SEVENWIRE)
|
2012-10-22 16:40:41 +00:00
|
|
|
fec_mii_setspeed(fec->bus->priv);
|
2011-09-11 18:05:31 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Set Opcode/Pause Duration Register */
|
2009-07-21 15:32:21 +00:00
|
|
|
writel(0x00010020, &fec->eth->op_pause); /* FIXME 0xffff0020; */
|
|
|
|
writel(0x2, &fec->eth->x_wmrk);
|
2016-12-05 23:00:50 +00:00
|
|
|
|
|
|
|
/* Set multicast address filter */
|
2009-07-21 15:32:21 +00:00
|
|
|
writel(0x00000000, &fec->eth->gaddr1);
|
|
|
|
writel(0x00000000, &fec->eth->gaddr2);
|
|
|
|
|
2018-01-10 05:20:43 +00:00
|
|
|
/* Do not access reserved register */
|
2019-04-15 05:18:33 +00:00
|
|
|
if (!is_mx6ul() && !is_mx6ull() && !is_imx8() && !is_imx8m()) {
|
2015-08-12 09:46:51 +00:00
|
|
|
/* clear MIB RAM */
|
|
|
|
for (i = mib_ptr; i <= mib_ptr + 0xfc; i += 4)
|
|
|
|
writel(0, i);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2015-08-12 09:46:51 +00:00
|
|
|
/* FIFO receive start register */
|
|
|
|
writel(0x520, &fec->eth->r_fstart);
|
|
|
|
}
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
/* size and address of each buffer */
|
|
|
|
writel(FEC_MAX_PKT_SIZE, &fec->eth->emrbr);
|
2018-01-10 05:20:44 +00:00
|
|
|
|
|
|
|
addr = (ulong)fec->tbd_base;
|
|
|
|
writel((uint32_t)addr, &fec->eth->etdsr);
|
|
|
|
|
|
|
|
addr = (ulong)fec->rbd_base;
|
|
|
|
writel((uint32_t)addr, &fec->eth->erdsr);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2012-02-07 14:08:47 +00:00
|
|
|
#ifndef CONFIG_PHYLIB
|
2009-07-21 15:32:21 +00:00
|
|
|
if (fec->xcv_type != SEVENWIRE)
|
|
|
|
miiphy_restart_aneg(dev);
|
2012-02-07 14:08:47 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_open(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Halt the FEC engine
|
|
|
|
* @param[in] dev Our device to handle
|
|
|
|
*/
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static void fecmxc_halt(struct udevice *dev)
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
static void fec_halt(struct eth_device *dev)
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fec_priv *fec = dev_get_priv(dev);
|
|
|
|
#else
|
2011-09-15 23:13:47 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
int counter = 0xffff;
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* issue graceful stop command to the FEC transmitter if necessary */
|
2010-01-26 06:12:55 +00:00
|
|
|
writel(FEC_TCNTRL_GTS | readl(&fec->eth->x_cntrl),
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->x_cntrl);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
debug("eth_halt: wait for stop regs\n");
|
2016-12-05 23:00:50 +00:00
|
|
|
/* wait for graceful stop to register */
|
2009-07-21 15:32:21 +00:00
|
|
|
while ((counter--) && (!(readl(&fec->eth->ievent) & FEC_IEVENT_GRA)))
|
2010-01-26 06:12:55 +00:00
|
|
|
udelay(1);
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Disable SmartDMA tasks */
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_tx_task_disable(fec);
|
|
|
|
fec_rx_task_disable(fec);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the Ethernet Controller
|
|
|
|
* Note: this will also reset the BD index counter!
|
|
|
|
*/
|
2010-01-26 06:12:57 +00:00
|
|
|
writel(readl(&fec->eth->ecntrl) & ~FEC_ECNTRL_ETHER_EN,
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->ecntrl);
|
2009-07-21 15:32:21 +00:00
|
|
|
fec->rbd_index = 0;
|
|
|
|
fec->tbd_index = 0;
|
|
|
|
debug("eth_halt: done\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transmit one frame
|
|
|
|
* @param[in] dev Our ethernet device to handle
|
|
|
|
* @param[in] packet Pointer to the data to be transmitted
|
|
|
|
* @param[in] length Data count in bytes
|
|
|
|
* @return 0 on success
|
|
|
|
*/
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static int fecmxc_send(struct udevice *dev, void *packet, int length)
|
|
|
|
#else
|
2012-05-21 14:45:27 +00:00
|
|
|
static int fec_send(struct eth_device *dev, void *packet, int length)
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
|
|
|
unsigned int status;
|
2018-01-10 05:20:44 +00:00
|
|
|
u32 size;
|
|
|
|
ulong addr, end;
|
2012-08-29 03:49:49 +00:00
|
|
|
int timeout = FEC_XFER_TIMEOUT;
|
|
|
|
int ret = 0;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine transmits one frame. This routine only accepts
|
|
|
|
* 6-byte Ethernet addresses.
|
|
|
|
*/
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fec_priv *fec = dev_get_priv(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for valid length of data.
|
|
|
|
*/
|
|
|
|
if ((length > 1500) || (length <= 0)) {
|
2010-02-01 13:51:30 +00:00
|
|
|
printf("Payload (%d) too large\n", length);
|
2009-07-21 15:32:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-15 18:33:25 +00:00
|
|
|
* Setup the transmit buffer. We are always using the first buffer for
|
|
|
|
* transmission, the second will be empty and only used to stop the DMA
|
|
|
|
* engine. We also flush the packet to RAM here to avoid cache trouble.
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2012-03-15 18:33:25 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_SWAP_PACKET
|
2011-11-08 23:18:10 +00:00
|
|
|
swap_packet((uint32_t *)packet, length);
|
|
|
|
#endif
|
2012-03-15 18:33:25 +00:00
|
|
|
|
2018-01-10 05:20:44 +00:00
|
|
|
addr = (ulong)packet;
|
2012-08-26 10:19:21 +00:00
|
|
|
end = roundup(addr + length, ARCH_DMA_MINALIGN);
|
|
|
|
addr &= ~(ARCH_DMA_MINALIGN - 1);
|
|
|
|
flush_dcache_range(addr, end);
|
2012-03-15 18:33:25 +00:00
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
writew(length, &fec->tbd_base[fec->tbd_index].data_length);
|
2018-01-10 05:20:44 +00:00
|
|
|
writel((uint32_t)addr, &fec->tbd_base[fec->tbd_index].data_pointer);
|
2012-03-15 18:33:25 +00:00
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
/*
|
|
|
|
* update BD's status now
|
|
|
|
* This block:
|
|
|
|
* - is always the last in a chain (means no chain)
|
|
|
|
* - should transmitt the CRC
|
|
|
|
* - might be the last BD in the list, so the address counter should
|
|
|
|
* wrap (-> keep the WRAP flag)
|
|
|
|
*/
|
|
|
|
status = readw(&fec->tbd_base[fec->tbd_index].status) & FEC_TBD_WRAP;
|
|
|
|
status |= FEC_TBD_LAST | FEC_TBD_TC | FEC_TBD_READY;
|
|
|
|
writew(status, &fec->tbd_base[fec->tbd_index].status);
|
|
|
|
|
2012-03-15 18:33:25 +00:00
|
|
|
/*
|
|
|
|
* Flush data cache. This code flushes both TX descriptors to RAM.
|
|
|
|
* After this code, the descriptors will be safely in RAM and we
|
|
|
|
* can start DMA.
|
|
|
|
*/
|
|
|
|
size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN);
|
2018-01-10 05:20:44 +00:00
|
|
|
addr = (ulong)fec->tbd_base;
|
2012-03-15 18:33:25 +00:00
|
|
|
flush_dcache_range(addr, addr + size);
|
|
|
|
|
2013-07-11 23:03:04 +00:00
|
|
|
/*
|
|
|
|
* Below we read the DMA descriptor's last four bytes back from the
|
|
|
|
* DRAM. This is important in order to make sure that all WRITE
|
|
|
|
* operations on the bus that were triggered by previous cache FLUSH
|
|
|
|
* have completed.
|
|
|
|
*
|
|
|
|
* Otherwise, on MX28, it is possible to observe a corruption of the
|
|
|
|
* DMA descriptors. Please refer to schematic "Figure 1-2" in MX28RM
|
|
|
|
* for the bus structure of MX28. The scenario is as follows:
|
|
|
|
*
|
|
|
|
* 1) ARM core triggers a series of WRITEs on the AHB_ARB2 bus going
|
|
|
|
* to DRAM due to flush_dcache_range()
|
|
|
|
* 2) ARM core writes the FEC registers via AHB_ARB2
|
|
|
|
* 3) FEC DMA starts reading/writing from/to DRAM via AHB_ARB3
|
|
|
|
*
|
|
|
|
* Note that 2) does sometimes finish before 1) due to reordering of
|
|
|
|
* WRITE accesses on the AHB bus, therefore triggering 3) before the
|
|
|
|
* DMA descriptor is fully written into DRAM. This results in occasional
|
|
|
|
* corruption of the DMA descriptor.
|
|
|
|
*/
|
|
|
|
readl(addr + size - 4);
|
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Enable SmartDMA transmit task */
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_tx_task_enable(fec);
|
|
|
|
|
|
|
|
/*
|
2012-03-15 18:33:25 +00:00
|
|
|
* Wait until frame is sent. On each turn of the wait cycle, we must
|
|
|
|
* invalidate data cache to see what's really in RAM. Also, we need
|
|
|
|
* barrier here.
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2012-08-29 03:49:50 +00:00
|
|
|
while (--timeout) {
|
2012-08-29 03:49:51 +00:00
|
|
|
if (!(readl(&fec->eth->x_des_active) & FEC_X_DES_ACTIVE_TDAR))
|
2012-08-29 03:49:49 +00:00
|
|
|
break;
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
2012-03-15 18:33:25 +00:00
|
|
|
|
2014-08-25 16:34:17 +00:00
|
|
|
if (!timeout) {
|
2012-08-29 03:49:50 +00:00
|
|
|
ret = -EINVAL;
|
2014-08-25 16:34:17 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The TDAR bit is cleared when the descriptors are all out from TX
|
|
|
|
* but on mx6solox we noticed that the READY bit is still not cleared
|
|
|
|
* right after TDAR.
|
|
|
|
* These are two distinct signals, and in IC simulation, we found that
|
|
|
|
* TDAR always gets cleared prior than the READY bit of last BD becomes
|
|
|
|
* cleared.
|
|
|
|
* In mx6solox, we use a later version of FEC IP. It looks like that
|
|
|
|
* this intrinsic behaviour of TDAR bit has changed in this newer FEC
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* Fix this by polling the READY bit of BD after the TDAR polling,
|
|
|
|
* which covers the mx6solox case and does not harm the other SoCs.
|
|
|
|
*/
|
|
|
|
timeout = FEC_XFER_TIMEOUT;
|
|
|
|
while (--timeout) {
|
|
|
|
invalidate_dcache_range(addr, addr + size);
|
|
|
|
if (!(readw(&fec->tbd_base[fec->tbd_index].status) &
|
|
|
|
FEC_TBD_READY))
|
|
|
|
break;
|
|
|
|
}
|
2012-08-29 03:49:50 +00:00
|
|
|
|
2014-08-25 16:34:17 +00:00
|
|
|
if (!timeout)
|
2012-08-29 03:49:50 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
|
2014-08-25 16:34:17 +00:00
|
|
|
out:
|
2012-08-29 03:49:50 +00:00
|
|
|
debug("fec_send: status 0x%x index %d ret %i\n",
|
2016-12-05 23:00:50 +00:00
|
|
|
readw(&fec->tbd_base[fec->tbd_index].status),
|
|
|
|
fec->tbd_index, ret);
|
2009-07-21 15:32:21 +00:00
|
|
|
/* for next transmission use the other buffer */
|
|
|
|
if (fec->tbd_index)
|
|
|
|
fec->tbd_index = 0;
|
|
|
|
else
|
|
|
|
fec->tbd_index = 1;
|
|
|
|
|
2012-08-29 03:49:49 +00:00
|
|
|
return ret;
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pull one frame from the card
|
|
|
|
* @param[in] dev Our ethernet device to handle
|
|
|
|
* @return Length of packet read
|
|
|
|
*/
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static int fecmxc_recv(struct udevice *dev, int flags, uchar **packetp)
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
static int fec_recv(struct eth_device *dev)
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fec_priv *fec = dev_get_priv(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
struct fec_bd *rbd = &fec->rbd_base[fec->rbd_index];
|
|
|
|
unsigned long ievent;
|
|
|
|
int frame_length, len = 0;
|
|
|
|
uint16_t bd_status;
|
2018-01-10 05:20:44 +00:00
|
|
|
ulong addr, size, end;
|
2012-03-15 18:33:25 +00:00
|
|
|
int i;
|
2018-03-28 12:54:11 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
*packetp = memalign(ARCH_DMA_MINALIGN, FEC_MAX_PKT_SIZE);
|
|
|
|
if (*packetp == 0) {
|
|
|
|
printf("%s: error allocating packetp\n", __func__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
#else
|
2013-09-18 02:13:10 +00:00
|
|
|
ALLOC_CACHE_ALIGN_BUFFER(uchar, buff, FEC_MAX_PKT_SIZE);
|
2018-03-28 12:54:11 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Check if any critical events have happened */
|
2009-07-21 15:32:21 +00:00
|
|
|
ievent = readl(&fec->eth->ievent);
|
|
|
|
writel(ievent, &fec->eth->ievent);
|
2011-10-24 23:40:03 +00:00
|
|
|
debug("fec_recv: ievent 0x%lx\n", ievent);
|
2009-07-21 15:32:21 +00:00
|
|
|
if (ievent & FEC_IEVENT_BABR) {
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
fecmxc_halt(dev);
|
|
|
|
fecmxc_init(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_halt(dev);
|
|
|
|
fec_init(dev, fec->bd);
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
printf("some error: 0x%08lx\n", ievent);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ievent & FEC_IEVENT_HBERR) {
|
|
|
|
/* Heartbeat error */
|
|
|
|
writel(0x00000001 | readl(&fec->eth->x_cntrl),
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->x_cntrl);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
if (ievent & FEC_IEVENT_GRA) {
|
|
|
|
/* Graceful stop complete */
|
|
|
|
if (readl(&fec->eth->x_cntrl) & 0x00000001) {
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
fecmxc_halt(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_halt(dev);
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
writel(~0x00000001 & readl(&fec->eth->x_cntrl),
|
2016-12-05 23:00:50 +00:00
|
|
|
&fec->eth->x_cntrl);
|
2016-12-05 23:00:49 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
fecmxc_init(dev);
|
|
|
|
#else
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_init(dev, fec->bd);
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-15 18:33:25 +00:00
|
|
|
* Read the buffer status. Before the status can be read, the data cache
|
|
|
|
* must be invalidated, because the data in RAM might have been changed
|
|
|
|
* by DMA. The descriptors are properly aligned to cachelines so there's
|
|
|
|
* no need to worry they'd overlap.
|
|
|
|
*
|
|
|
|
* WARNING: By invalidating the descriptor here, we also invalidate
|
|
|
|
* the descriptors surrounding this one. Therefore we can NOT change the
|
|
|
|
* contents of this descriptor nor the surrounding ones. The problem is
|
|
|
|
* that in order to mark the descriptor as processed, we need to change
|
|
|
|
* the descriptor. The solution is to mark the whole cache line when all
|
|
|
|
* descriptors in the cache line are processed.
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2018-01-10 05:20:44 +00:00
|
|
|
addr = (ulong)rbd;
|
2012-03-15 18:33:25 +00:00
|
|
|
addr &= ~(ARCH_DMA_MINALIGN - 1);
|
|
|
|
size = roundup(sizeof(struct fec_bd), ARCH_DMA_MINALIGN);
|
|
|
|
invalidate_dcache_range(addr, addr + size);
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
bd_status = readw(&rbd->status);
|
|
|
|
debug("fec_recv: status 0x%x\n", bd_status);
|
|
|
|
|
|
|
|
if (!(bd_status & FEC_RBD_EMPTY)) {
|
|
|
|
if ((bd_status & FEC_RBD_LAST) && !(bd_status & FEC_RBD_ERR) &&
|
2016-12-05 23:00:50 +00:00
|
|
|
((readw(&rbd->data_length) - 4) > 14)) {
|
|
|
|
/* Get buffer address and size */
|
2015-06-19 12:18:27 +00:00
|
|
|
addr = readl(&rbd->data_pointer);
|
2009-07-21 15:32:21 +00:00
|
|
|
frame_length = readw(&rbd->data_length) - 4;
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Invalidate data cache over the buffer */
|
2012-08-26 10:19:21 +00:00
|
|
|
end = roundup(addr + frame_length, ARCH_DMA_MINALIGN);
|
|
|
|
addr &= ~(ARCH_DMA_MINALIGN - 1);
|
|
|
|
invalidate_dcache_range(addr, end);
|
2012-03-15 18:33:25 +00:00
|
|
|
|
2016-12-05 23:00:50 +00:00
|
|
|
/* Fill the buffer and pass it to upper layers */
|
2012-03-15 18:33:25 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_SWAP_PACKET
|
2015-06-19 12:18:27 +00:00
|
|
|
swap_packet((uint32_t *)addr, frame_length);
|
2011-11-08 23:18:10 +00:00
|
|
|
#endif
|
2018-03-28 12:54:11 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
memcpy(*packetp, (char *)addr, frame_length);
|
|
|
|
#else
|
2015-06-19 12:18:27 +00:00
|
|
|
memcpy(buff, (char *)addr, frame_length);
|
2015-04-08 06:41:06 +00:00
|
|
|
net_process_received_packet(buff, frame_length);
|
2018-03-28 12:54:11 +00:00
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
len = frame_length;
|
|
|
|
} else {
|
|
|
|
if (bd_status & FEC_RBD_ERR)
|
2018-01-10 05:20:44 +00:00
|
|
|
debug("error frame: 0x%08lx 0x%08x\n",
|
|
|
|
addr, bd_status);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
2012-03-15 18:33:25 +00:00
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
/*
|
2012-03-15 18:33:25 +00:00
|
|
|
* Free the current buffer, restart the engine and move forward
|
|
|
|
* to the next buffer. Here we check if the whole cacheline of
|
|
|
|
* descriptors was already processed and if so, we mark it free
|
|
|
|
* as whole.
|
2009-07-21 15:32:21 +00:00
|
|
|
*/
|
2012-03-15 18:33:25 +00:00
|
|
|
size = RXDESC_PER_CACHELINE - 1;
|
|
|
|
if ((fec->rbd_index & size) == size) {
|
|
|
|
i = fec->rbd_index - size;
|
2018-01-10 05:20:44 +00:00
|
|
|
addr = (ulong)&fec->rbd_base[i];
|
2012-03-15 18:33:25 +00:00
|
|
|
for (; i <= fec->rbd_index ; i++) {
|
|
|
|
fec_rbd_clean(i == (FEC_RBD_NUM - 1),
|
|
|
|
&fec->rbd_base[i]);
|
|
|
|
}
|
|
|
|
flush_dcache_range(addr,
|
2016-12-05 23:00:50 +00:00
|
|
|
addr + ARCH_DMA_MINALIGN);
|
2012-03-15 18:33:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
fec_rx_task_enable(fec);
|
|
|
|
fec->rbd_index = (fec->rbd_index + 1) % FEC_RBD_NUM;
|
|
|
|
}
|
|
|
|
debug("fec_recv: stop\n");
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2012-10-22 16:40:44 +00:00
|
|
|
static void fec_set_dev_name(char *dest, int dev_id)
|
|
|
|
{
|
|
|
|
sprintf(dest, (dev_id == -1) ? "FEC" : "FEC%i", dev_id);
|
|
|
|
}
|
|
|
|
|
2013-10-12 18:36:25 +00:00
|
|
|
static int fec_alloc_descs(struct fec_priv *fec)
|
|
|
|
{
|
|
|
|
unsigned int size;
|
|
|
|
int i;
|
|
|
|
uint8_t *data;
|
2018-01-10 05:20:44 +00:00
|
|
|
ulong addr;
|
2013-10-12 18:36:25 +00:00
|
|
|
|
|
|
|
/* Allocate TX descriptors. */
|
|
|
|
size = roundup(2 * sizeof(struct fec_bd), ARCH_DMA_MINALIGN);
|
|
|
|
fec->tbd_base = memalign(ARCH_DMA_MINALIGN, size);
|
|
|
|
if (!fec->tbd_base)
|
|
|
|
goto err_tx;
|
|
|
|
|
|
|
|
/* Allocate RX descriptors. */
|
|
|
|
size = roundup(FEC_RBD_NUM * sizeof(struct fec_bd), ARCH_DMA_MINALIGN);
|
|
|
|
fec->rbd_base = memalign(ARCH_DMA_MINALIGN, size);
|
|
|
|
if (!fec->rbd_base)
|
|
|
|
goto err_rx;
|
|
|
|
|
|
|
|
memset(fec->rbd_base, 0, size);
|
|
|
|
|
|
|
|
/* Allocate RX buffers. */
|
|
|
|
|
|
|
|
/* Maximum RX buffer size. */
|
2014-08-25 16:34:16 +00:00
|
|
|
size = roundup(FEC_MAX_PKT_SIZE, FEC_DMA_RX_MINALIGN);
|
2013-10-12 18:36:25 +00:00
|
|
|
for (i = 0; i < FEC_RBD_NUM; i++) {
|
2014-08-25 16:34:16 +00:00
|
|
|
data = memalign(FEC_DMA_RX_MINALIGN, size);
|
2013-10-12 18:36:25 +00:00
|
|
|
if (!data) {
|
|
|
|
printf("%s: error allocating rxbuf %d\n", __func__, i);
|
|
|
|
goto err_ring;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(data, 0, size);
|
|
|
|
|
2018-01-10 05:20:44 +00:00
|
|
|
addr = (ulong)data;
|
|
|
|
fec->rbd_base[i].data_pointer = (uint32_t)addr;
|
2013-10-12 18:36:25 +00:00
|
|
|
fec->rbd_base[i].status = FEC_RBD_EMPTY;
|
|
|
|
fec->rbd_base[i].data_length = 0;
|
|
|
|
/* Flush the buffer to memory. */
|
2018-01-10 05:20:44 +00:00
|
|
|
flush_dcache_range(addr, addr + size);
|
2013-10-12 18:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the last RBD to close the ring. */
|
|
|
|
fec->rbd_base[i - 1].status = FEC_RBD_WRAP | FEC_RBD_EMPTY;
|
|
|
|
|
|
|
|
fec->rbd_index = 0;
|
|
|
|
fec->tbd_index = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_ring:
|
2018-01-10 05:20:44 +00:00
|
|
|
for (; i >= 0; i--) {
|
|
|
|
addr = fec->rbd_base[i].data_pointer;
|
|
|
|
free((void *)addr);
|
|
|
|
}
|
2013-10-12 18:36:25 +00:00
|
|
|
free(fec->rbd_base);
|
|
|
|
err_rx:
|
|
|
|
free(fec->tbd_base);
|
|
|
|
err_tx:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fec_free_descs(struct fec_priv *fec)
|
|
|
|
{
|
|
|
|
int i;
|
2018-01-10 05:20:44 +00:00
|
|
|
ulong addr;
|
2013-10-12 18:36:25 +00:00
|
|
|
|
2018-01-10 05:20:44 +00:00
|
|
|
for (i = 0; i < FEC_RBD_NUM; i++) {
|
|
|
|
addr = fec->rbd_base[i].data_pointer;
|
|
|
|
free((void *)addr);
|
|
|
|
}
|
2013-10-12 18:36:25 +00:00
|
|
|
free(fec->rbd_base);
|
|
|
|
free(fec->tbd_base);
|
|
|
|
}
|
|
|
|
|
2018-03-28 12:54:12 +00:00
|
|
|
struct mii_dev *fec_get_miibus(ulong base_addr, int dev_id)
|
2016-12-05 23:00:49 +00:00
|
|
|
{
|
2018-03-28 12:54:12 +00:00
|
|
|
struct ethernet_regs *eth = (struct ethernet_regs *)base_addr;
|
2016-12-05 23:00:49 +00:00
|
|
|
struct mii_dev *bus;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
bus = mdio_alloc();
|
|
|
|
if (!bus) {
|
|
|
|
printf("mdio_alloc failed\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bus->read = fec_phy_read;
|
|
|
|
bus->write = fec_phy_write;
|
|
|
|
bus->priv = eth;
|
|
|
|
fec_set_dev_name(bus->name, dev_id);
|
|
|
|
|
|
|
|
ret = mdio_register(bus);
|
|
|
|
if (ret) {
|
|
|
|
printf("mdio_register failed\n");
|
|
|
|
free(bus);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fec_mii_setspeed(eth);
|
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef CONFIG_DM_ETH
|
2012-10-22 16:40:46 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
2020-06-26 06:13:33 +00:00
|
|
|
int fec_probe(struct bd_info *bd, int dev_id, uint32_t base_addr,
|
2012-10-22 16:40:46 +00:00
|
|
|
struct mii_dev *bus, struct phy_device *phydev)
|
|
|
|
#else
|
2020-06-26 06:13:34 +00:00
|
|
|
static int fec_probe(struct bd_info *bd, int dev_id, uint32_t base_addr,
|
2012-10-22 16:40:46 +00:00
|
|
|
struct mii_dev *bus, int phy_id)
|
|
|
|
#endif
|
2009-07-21 15:32:21 +00:00
|
|
|
{
|
|
|
|
struct eth_device *edev;
|
2011-09-15 23:13:47 +00:00
|
|
|
struct fec_priv *fec;
|
2009-07-21 15:32:21 +00:00
|
|
|
unsigned char ethaddr[6];
|
2017-04-10 11:44:35 +00:00
|
|
|
char mac[16];
|
2011-09-11 18:05:37 +00:00
|
|
|
uint32_t start;
|
|
|
|
int ret = 0;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
/* create and fill edev struct */
|
|
|
|
edev = (struct eth_device *)malloc(sizeof(struct eth_device));
|
|
|
|
if (!edev) {
|
2011-09-15 23:13:47 +00:00
|
|
|
puts("fec_mxc: not enough malloc memory for eth_device\n");
|
2011-09-11 18:05:37 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err1;
|
2011-09-15 23:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fec = (struct fec_priv *)malloc(sizeof(struct fec_priv));
|
|
|
|
if (!fec) {
|
|
|
|
puts("fec_mxc: not enough malloc memory for fec_priv\n");
|
2011-09-11 18:05:37 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err2;
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
2011-09-15 23:13:47 +00:00
|
|
|
|
2010-10-19 05:03:42 +00:00
|
|
|
memset(edev, 0, sizeof(*edev));
|
2011-09-15 23:13:47 +00:00
|
|
|
memset(fec, 0, sizeof(*fec));
|
|
|
|
|
2013-10-12 18:36:25 +00:00
|
|
|
ret = fec_alloc_descs(fec);
|
|
|
|
if (ret)
|
|
|
|
goto err3;
|
|
|
|
|
2009-07-21 15:32:21 +00:00
|
|
|
edev->priv = fec;
|
|
|
|
edev->init = fec_init;
|
|
|
|
edev->send = fec_send;
|
|
|
|
edev->recv = fec_recv;
|
|
|
|
edev->halt = fec_halt;
|
2010-04-27 05:43:52 +00:00
|
|
|
edev->write_hwaddr = fec_set_hwaddr;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2018-01-10 05:20:44 +00:00
|
|
|
fec->eth = (struct ethernet_regs *)(ulong)base_addr;
|
2009-07-21 15:32:21 +00:00
|
|
|
fec->bd = bd;
|
|
|
|
|
2011-09-11 18:05:33 +00:00
|
|
|
fec->xcv_type = CONFIG_FEC_XCV_TYPE;
|
2009-07-21 15:32:21 +00:00
|
|
|
|
|
|
|
/* Reset chip. */
|
2010-01-26 06:12:55 +00:00
|
|
|
writel(readl(&fec->eth->ecntrl) | FEC_ECNTRL_RESET, &fec->eth->ecntrl);
|
2011-09-11 18:05:37 +00:00
|
|
|
start = get_timer(0);
|
|
|
|
while (readl(&fec->eth->ecntrl) & FEC_ECNTRL_RESET) {
|
|
|
|
if (get_timer(start) > (CONFIG_SYS_HZ * 5)) {
|
2016-10-24 03:45:19 +00:00
|
|
|
printf("FEC MXC: Timeout resetting chip\n");
|
2013-10-12 18:36:25 +00:00
|
|
|
goto err4;
|
2011-09-11 18:05:37 +00:00
|
|
|
}
|
2009-07-21 15:32:21 +00:00
|
|
|
udelay(10);
|
2011-09-11 18:05:37 +00:00
|
|
|
}
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2012-05-01 11:09:41 +00:00
|
|
|
fec_reg_setup(fec);
|
2012-10-22 16:40:44 +00:00
|
|
|
fec_set_dev_name(edev->name, dev_id);
|
|
|
|
fec->dev_id = (dev_id == -1) ? 0 : dev_id;
|
2012-10-22 16:40:46 +00:00
|
|
|
fec->bus = bus;
|
|
|
|
fec_mii_setspeed(bus->priv);
|
|
|
|
#ifdef CONFIG_PHYLIB
|
|
|
|
fec->phydev = phydev;
|
|
|
|
phy_connect_dev(phydev, edev);
|
|
|
|
/* Configure phy */
|
|
|
|
phy_config(phydev);
|
|
|
|
#else
|
2011-09-15 23:13:47 +00:00
|
|
|
fec->phy_id = phy_id;
|
2012-10-22 16:40:46 +00:00
|
|
|
#endif
|
|
|
|
eth_register(edev);
|
2017-04-10 11:44:35 +00:00
|
|
|
/* only support one eth device, the index number pointed by dev_id */
|
|
|
|
edev->index = fec->dev_id;
|
2012-10-22 16:40:46 +00:00
|
|
|
|
2017-04-10 11:44:34 +00:00
|
|
|
if (fec_get_hwaddr(fec->dev_id, ethaddr) == 0) {
|
|
|
|
debug("got MAC%d address from fuse: %pM\n", fec->dev_id, ethaddr);
|
2012-10-22 16:40:46 +00:00
|
|
|
memcpy(edev->enetaddr, ethaddr, 6);
|
2017-04-10 11:44:35 +00:00
|
|
|
if (fec->dev_id)
|
|
|
|
sprintf(mac, "eth%daddr", fec->dev_id);
|
|
|
|
else
|
|
|
|
strcpy(mac, "ethaddr");
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get(mac))
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr(mac, ethaddr);
|
2012-10-22 16:40:46 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2013-10-12 18:36:25 +00:00
|
|
|
err4:
|
|
|
|
fec_free_descs(fec);
|
2012-10-22 16:40:46 +00:00
|
|
|
err3:
|
|
|
|
free(fec);
|
|
|
|
err2:
|
|
|
|
free(edev);
|
|
|
|
err1:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
int fecmxc_initialize_multi(struct bd_info *bd, int dev_id, int phy_id,
|
|
|
|
uint32_t addr)
|
2012-10-22 16:40:46 +00:00
|
|
|
{
|
|
|
|
uint32_t base_mii;
|
|
|
|
struct mii_dev *bus = NULL;
|
|
|
|
#ifdef CONFIG_PHYLIB
|
|
|
|
struct phy_device *phydev = NULL;
|
|
|
|
#endif
|
|
|
|
int ret;
|
|
|
|
|
2020-05-01 14:08:37 +00:00
|
|
|
if (CONFIG_IS_ENABLED(IMX_MODULE_FUSE)) {
|
|
|
|
if (enet_fused((ulong)addr)) {
|
|
|
|
printf("SoC fuse indicates Ethernet@0x%x is unavailable.\n", addr);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 12:54:14 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_MDIO_BASE
|
2012-02-07 14:08:47 +00:00
|
|
|
/*
|
|
|
|
* The i.MX28 has two ethernet interfaces, but they are not equal.
|
|
|
|
* Only the first one can access the MDIO bus.
|
|
|
|
*/
|
2018-03-28 12:54:14 +00:00
|
|
|
base_mii = CONFIG_FEC_MXC_MDIO_BASE;
|
2012-02-07 14:08:47 +00:00
|
|
|
#else
|
2012-10-22 16:40:46 +00:00
|
|
|
base_mii = addr;
|
2012-02-07 14:08:47 +00:00
|
|
|
#endif
|
2012-10-22 16:40:46 +00:00
|
|
|
debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr);
|
|
|
|
bus = fec_get_miibus(base_mii, dev_id);
|
|
|
|
if (!bus)
|
|
|
|
return -ENOMEM;
|
2012-10-22 16:40:45 +00:00
|
|
|
#ifdef CONFIG_PHYLIB
|
2012-10-22 16:40:46 +00:00
|
|
|
phydev = phy_find_by_mask(bus, 1 << phy_id, PHY_INTERFACE_MODE_RGMII);
|
2012-10-22 16:40:45 +00:00
|
|
|
if (!phydev) {
|
2015-12-08 15:38:46 +00:00
|
|
|
mdio_unregister(bus);
|
2012-10-22 16:40:45 +00:00
|
|
|
free(bus);
|
2012-10-22 16:40:46 +00:00
|
|
|
return -ENOMEM;
|
2012-10-22 16:40:45 +00:00
|
|
|
}
|
2012-10-22 16:40:46 +00:00
|
|
|
ret = fec_probe(bd, dev_id, addr, bus, phydev);
|
|
|
|
#else
|
|
|
|
ret = fec_probe(bd, dev_id, addr, bus, phy_id);
|
2012-10-22 16:40:45 +00:00
|
|
|
#endif
|
2012-10-22 16:40:46 +00:00
|
|
|
if (ret) {
|
|
|
|
#ifdef CONFIG_PHYLIB
|
|
|
|
free(phydev);
|
|
|
|
#endif
|
2015-12-08 15:38:46 +00:00
|
|
|
mdio_unregister(bus);
|
2012-10-22 16:40:46 +00:00
|
|
|
free(bus);
|
|
|
|
}
|
2011-09-11 18:05:37 +00:00
|
|
|
return ret;
|
2012-10-22 16:40:42 +00:00
|
|
|
}
|
2009-07-21 15:32:21 +00:00
|
|
|
|
2012-10-22 16:40:42 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_PHYADDR
|
2020-06-26 06:13:33 +00:00
|
|
|
int fecmxc_initialize(struct bd_info *bd)
|
2012-10-22 16:40:42 +00:00
|
|
|
{
|
|
|
|
return fecmxc_initialize_multi(bd, -1, CONFIG_FEC_MXC_PHYADDR,
|
|
|
|
IMX_FEC_BASE);
|
2009-07-21 15:32:21 +00:00
|
|
|
}
|
2012-10-22 16:40:42 +00:00
|
|
|
#endif
|
2011-09-11 18:05:36 +00:00
|
|
|
|
2012-02-07 14:08:47 +00:00
|
|
|
#ifndef CONFIG_PHYLIB
|
2011-09-11 18:05:36 +00:00
|
|
|
int fecmxc_register_mii_postcall(struct eth_device *dev, int (*cb)(int))
|
|
|
|
{
|
|
|
|
struct fec_priv *fec = (struct fec_priv *)dev->priv;
|
|
|
|
fec->mii_postcall = cb;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-07 14:08:47 +00:00
|
|
|
#endif
|
2016-12-05 23:00:49 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2016-12-05 23:00:51 +00:00
|
|
|
static int fecmxc_read_rom_hwaddr(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct fec_priv *priv = dev_get_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2016-12-05 23:00:51 +00:00
|
|
|
|
|
|
|
return fec_get_hwaddr(priv->dev_id, pdata->enetaddr);
|
|
|
|
}
|
|
|
|
|
2018-03-28 12:54:11 +00:00
|
|
|
static int fecmxc_free_pkt(struct udevice *dev, uchar *packet, int length)
|
|
|
|
{
|
|
|
|
if (packet)
|
|
|
|
free(packet);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
static const struct eth_ops fecmxc_ops = {
|
|
|
|
.start = fecmxc_init,
|
|
|
|
.send = fecmxc_send,
|
|
|
|
.recv = fecmxc_recv,
|
2018-03-28 12:54:11 +00:00
|
|
|
.free_pkt = fecmxc_free_pkt,
|
2016-12-05 23:00:49 +00:00
|
|
|
.stop = fecmxc_halt,
|
|
|
|
.write_hwaddr = fecmxc_set_hwaddr,
|
2016-12-05 23:00:51 +00:00
|
|
|
.read_rom_hwaddr = fecmxc_read_rom_hwaddr,
|
2016-12-05 23:00:49 +00:00
|
|
|
};
|
|
|
|
|
2020-06-18 23:21:18 +00:00
|
|
|
static int device_get_phy_addr(struct fec_priv *priv, struct udevice *dev)
|
2018-12-11 11:34:45 +00:00
|
|
|
{
|
|
|
|
struct ofnode_phandle_args phandle_args;
|
2021-04-15 17:06:08 +00:00
|
|
|
int reg, ret;
|
2018-12-11 11:34:45 +00:00
|
|
|
|
2021-04-15 17:06:08 +00:00
|
|
|
ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
|
|
|
|
&phandle_args);
|
|
|
|
if (ret) {
|
|
|
|
debug("Failed to find phy-handle (err = %d\n)", ret);
|
|
|
|
return ret;
|
2018-12-11 11:34:45 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 17:06:08 +00:00
|
|
|
if (!ofnode_is_available(phandle_args.node))
|
|
|
|
return -ENOENT;
|
2020-06-18 23:21:18 +00:00
|
|
|
|
2021-04-15 17:06:08 +00:00
|
|
|
priv->phy_of_node = phandle_args.node;
|
2018-12-11 11:34:45 +00:00
|
|
|
reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
|
|
|
|
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
static int fec_phy_init(struct fec_priv *priv, struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct phy_device *phydev;
|
2018-12-11 11:34:45 +00:00
|
|
|
int addr;
|
2016-12-05 23:00:49 +00:00
|
|
|
|
2020-06-18 23:21:18 +00:00
|
|
|
addr = device_get_phy_addr(priv, dev);
|
2018-04-15 19:45:54 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_PHYADDR
|
2019-02-15 09:30:18 +00:00
|
|
|
addr = CONFIG_FEC_MXC_PHYADDR;
|
2016-12-05 23:00:49 +00:00
|
|
|
#endif
|
|
|
|
|
2019-02-15 09:30:18 +00:00
|
|
|
phydev = phy_connect(priv->bus, addr, dev, priv->interface);
|
2016-12-05 23:00:49 +00:00
|
|
|
if (!phydev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
priv->phydev = phydev;
|
2020-06-18 23:21:18 +00:00
|
|
|
priv->phydev->node = priv->phy_of_node;
|
2016-12-05 23:00:49 +00:00
|
|
|
phy_config(phydev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-07 04:41:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2018-06-17 13:22:39 +00:00
|
|
|
/* FEC GPIO reset */
|
|
|
|
static void fec_gpio_reset(struct fec_priv *priv)
|
|
|
|
{
|
|
|
|
debug("fec_gpio_reset: fec_gpio_reset(dev)\n");
|
|
|
|
if (dm_gpio_is_valid(&priv->phy_reset_gpio)) {
|
|
|
|
dm_gpio_set_value(&priv->phy_reset_gpio, 1);
|
2018-10-04 17:59:18 +00:00
|
|
|
mdelay(priv->reset_delay);
|
2018-06-17 13:22:39 +00:00
|
|
|
dm_gpio_set_value(&priv->phy_reset_gpio, 0);
|
2019-03-01 13:27:59 +00:00
|
|
|
if (priv->reset_post_delay)
|
|
|
|
mdelay(priv->reset_post_delay);
|
2018-06-17 13:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
static int fecmxc_probe(struct udevice *dev)
|
|
|
|
{
|
2021-04-15 17:06:09 +00:00
|
|
|
bool dm_mii_bus = true;
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2016-12-05 23:00:49 +00:00
|
|
|
struct fec_priv *priv = dev_get_priv(dev);
|
|
|
|
struct mii_dev *bus = NULL;
|
|
|
|
uint32_t start;
|
|
|
|
int ret;
|
|
|
|
|
2020-05-01 14:08:37 +00:00
|
|
|
if (CONFIG_IS_ENABLED(IMX_MODULE_FUSE)) {
|
|
|
|
if (enet_fused((ulong)priv->eth)) {
|
|
|
|
printf("SoC fuse indicates Ethernet@0x%lx is unavailable.\n", (ulong)priv->eth);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-18 14:15:11 +00:00
|
|
|
if (IS_ENABLED(CONFIG_IMX8)) {
|
|
|
|
ret = clk_get_by_name(dev, "ipg", &priv->ipg_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't get FEC ipg clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = clk_enable(&priv->ipg_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't enable FEC ipg clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-10-25 09:48:02 +00:00
|
|
|
priv->clk_rate = clk_get_rate(&priv->ipg_clk);
|
|
|
|
} else if (CONFIG_IS_ENABLED(CLK_CCF)) {
|
|
|
|
ret = clk_get_by_name(dev, "ipg", &priv->ipg_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't get FEC ipg clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = clk_enable(&priv->ipg_clk);
|
|
|
|
if(ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "ahb", &priv->ahb_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't get FEC ahb clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = clk_enable(&priv->ahb_clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "enet_out", &priv->clk_enet_out);
|
|
|
|
if (!ret) {
|
|
|
|
ret = clk_enable(&priv->clk_enet_out);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "enet_clk_ref", &priv->clk_ref);
|
|
|
|
if (!ret) {
|
|
|
|
ret = clk_enable(&priv->clk_ref);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "ptp", &priv->clk_ptp);
|
|
|
|
if (!ret) {
|
|
|
|
ret = clk_enable(&priv->clk_ptp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-18 14:15:11 +00:00
|
|
|
priv->clk_rate = clk_get_rate(&priv->ipg_clk);
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
ret = fec_alloc_descs(priv);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-10-04 17:59:20 +00:00
|
|
|
#ifdef CONFIG_DM_REGULATOR
|
|
|
|
if (priv->phy_supply) {
|
2019-01-15 17:26:48 +00:00
|
|
|
ret = regulator_set_enable(priv->phy_supply, true);
|
2018-10-04 17:59:20 +00:00
|
|
|
if (ret) {
|
|
|
|
printf("%s: Error enabling phy supply\n", dev->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-12-07 04:41:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2018-06-17 13:22:39 +00:00
|
|
|
fec_gpio_reset(priv);
|
|
|
|
#endif
|
2016-12-05 23:00:49 +00:00
|
|
|
/* Reset chip. */
|
2016-12-05 23:00:50 +00:00
|
|
|
writel(readl(&priv->eth->ecntrl) | FEC_ECNTRL_RESET,
|
|
|
|
&priv->eth->ecntrl);
|
2016-12-05 23:00:49 +00:00
|
|
|
start = get_timer(0);
|
|
|
|
while (readl(&priv->eth->ecntrl) & FEC_ECNTRL_RESET) {
|
|
|
|
if (get_timer(start) > (CONFIG_SYS_HZ * 5)) {
|
|
|
|
printf("FEC MXC: Timeout reseting chip\n");
|
|
|
|
goto err_timeout;
|
|
|
|
}
|
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
fec_reg_setup(priv);
|
|
|
|
|
2020-12-17 04:20:07 +00:00
|
|
|
priv->dev_id = dev_seq(dev);
|
2020-05-03 14:41:15 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DM_ETH_PHY
|
|
|
|
bus = eth_phy_get_mdio_bus(dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!bus) {
|
2021-04-15 17:06:09 +00:00
|
|
|
dm_mii_bus = false;
|
2018-03-28 12:54:14 +00:00
|
|
|
#ifdef CONFIG_FEC_MXC_MDIO_BASE
|
2020-12-17 04:20:07 +00:00
|
|
|
bus = fec_get_miibus((ulong)CONFIG_FEC_MXC_MDIO_BASE,
|
|
|
|
dev_seq(dev));
|
2018-03-28 12:54:14 +00:00
|
|
|
#else
|
2020-12-17 04:20:07 +00:00
|
|
|
bus = fec_get_miibus((ulong)priv->eth, dev_seq(dev));
|
2018-03-28 12:54:14 +00:00
|
|
|
#endif
|
2020-05-03 14:41:15 +00:00
|
|
|
}
|
2017-06-27 13:23:16 +00:00
|
|
|
if (!bus) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_mii;
|
|
|
|
}
|
|
|
|
|
2020-05-03 14:41:15 +00:00
|
|
|
#ifdef CONFIG_DM_ETH_PHY
|
|
|
|
eth_phy_set_mdio_bus(dev, bus);
|
|
|
|
#endif
|
|
|
|
|
2017-06-27 13:23:16 +00:00
|
|
|
priv->bus = bus;
|
|
|
|
priv->interface = pdata->phy_interface;
|
2018-10-04 17:59:21 +00:00
|
|
|
switch (priv->interface) {
|
|
|
|
case PHY_INTERFACE_MODE_MII:
|
|
|
|
priv->xcv_type = MII100;
|
|
|
|
break;
|
|
|
|
case PHY_INTERFACE_MODE_RMII:
|
|
|
|
priv->xcv_type = RMII;
|
|
|
|
break;
|
|
|
|
case PHY_INTERFACE_MODE_RGMII:
|
|
|
|
case PHY_INTERFACE_MODE_RGMII_ID:
|
|
|
|
case PHY_INTERFACE_MODE_RGMII_RXID:
|
|
|
|
case PHY_INTERFACE_MODE_RGMII_TXID:
|
|
|
|
priv->xcv_type = RGMII;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
priv->xcv_type = CONFIG_FEC_XCV_TYPE;
|
|
|
|
printf("Unsupported interface type %d defaulting to %d\n",
|
|
|
|
priv->interface, priv->xcv_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-06-27 13:23:16 +00:00
|
|
|
ret = fec_phy_init(priv, dev);
|
|
|
|
if (ret)
|
|
|
|
goto err_phy;
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_phy:
|
2021-04-15 17:06:09 +00:00
|
|
|
if (!dm_mii_bus) {
|
|
|
|
mdio_unregister(bus);
|
|
|
|
free(bus);
|
|
|
|
}
|
2016-12-05 23:00:49 +00:00
|
|
|
err_mii:
|
2018-03-28 12:54:16 +00:00
|
|
|
err_timeout:
|
2016-12-05 23:00:49 +00:00
|
|
|
fec_free_descs(priv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fecmxc_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct fec_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
free(priv->phydev);
|
|
|
|
fec_free_descs(priv);
|
|
|
|
mdio_unregister(priv->bus);
|
|
|
|
mdio_free(priv->bus);
|
|
|
|
|
2018-10-04 17:59:20 +00:00
|
|
|
#ifdef CONFIG_DM_REGULATOR
|
|
|
|
if (priv->phy_supply)
|
|
|
|
regulator_set_enable(priv->phy_supply, false);
|
|
|
|
#endif
|
|
|
|
|
2016-12-05 23:00:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int fecmxc_of_to_plat(struct udevice *dev)
|
2016-12-05 23:00:49 +00:00
|
|
|
{
|
2018-06-17 13:22:39 +00:00
|
|
|
int ret = 0;
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2016-12-05 23:00:49 +00:00
|
|
|
struct fec_priv *priv = dev_get_priv(dev);
|
|
|
|
const char *phy_mode;
|
|
|
|
|
2020-07-17 05:36:48 +00:00
|
|
|
pdata->iobase = dev_read_addr(dev);
|
2016-12-05 23:00:49 +00:00
|
|
|
priv->eth = (struct ethernet_regs *)pdata->iobase;
|
|
|
|
|
|
|
|
pdata->phy_interface = -1;
|
2017-01-17 23:52:55 +00:00
|
|
|
phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
|
|
|
|
NULL);
|
2016-12-05 23:00:49 +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;
|
|
|
|
}
|
|
|
|
|
2018-10-04 17:59:20 +00:00
|
|
|
#ifdef CONFIG_DM_REGULATOR
|
|
|
|
device_get_supply_regulator(dev, "phy-supply", &priv->phy_supply);
|
|
|
|
#endif
|
|
|
|
|
2019-12-07 04:41:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2018-06-17 13:22:39 +00:00
|
|
|
ret = gpio_request_by_name(dev, "phy-reset-gpios", 0,
|
2018-10-04 17:59:19 +00:00
|
|
|
&priv->phy_reset_gpio, GPIOD_IS_OUT);
|
|
|
|
if (ret < 0)
|
|
|
|
return 0; /* property is optional, don't return error! */
|
2016-12-05 23:00:49 +00:00
|
|
|
|
2018-10-04 17:59:19 +00:00
|
|
|
priv->reset_delay = dev_read_u32_default(dev, "phy-reset-duration", 1);
|
2018-06-17 13:22:39 +00:00
|
|
|
if (priv->reset_delay > 1000) {
|
2018-10-04 17:59:19 +00:00
|
|
|
printf("FEC MXC: phy reset duration should be <= 1000ms\n");
|
|
|
|
/* property value wrong, use default value */
|
|
|
|
priv->reset_delay = 1;
|
2018-06-17 13:22:39 +00:00
|
|
|
}
|
2019-03-01 13:27:59 +00:00
|
|
|
|
|
|
|
priv->reset_post_delay = dev_read_u32_default(dev,
|
|
|
|
"phy-reset-post-delay",
|
|
|
|
0);
|
|
|
|
if (priv->reset_post_delay > 1000) {
|
|
|
|
printf("FEC MXC: phy reset post delay should be <= 1000ms\n");
|
|
|
|
/* property value wrong, use default value */
|
|
|
|
priv->reset_post_delay = 0;
|
|
|
|
}
|
2018-06-17 13:22:39 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-04 17:59:19 +00:00
|
|
|
return 0;
|
2016-12-05 23:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id fecmxc_ids[] = {
|
2019-06-19 15:31:03 +00:00
|
|
|
{ .compatible = "fsl,imx28-fec" },
|
2016-12-05 23:00:49 +00:00
|
|
|
{ .compatible = "fsl,imx6q-fec" },
|
2018-03-28 12:54:15 +00:00
|
|
|
{ .compatible = "fsl,imx6sl-fec" },
|
|
|
|
{ .compatible = "fsl,imx6sx-fec" },
|
|
|
|
{ .compatible = "fsl,imx6ul-fec" },
|
2018-04-15 19:54:22 +00:00
|
|
|
{ .compatible = "fsl,imx53-fec" },
|
2018-10-18 14:15:11 +00:00
|
|
|
{ .compatible = "fsl,imx7d-fec" },
|
2019-02-13 21:46:38 +00:00
|
|
|
{ .compatible = "fsl,mvf600-fec" },
|
2016-12-05 23:00:49 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(fecmxc_gem) = {
|
|
|
|
.name = "fecmxc",
|
|
|
|
.id = UCLASS_ETH,
|
|
|
|
.of_match = fecmxc_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = fecmxc_of_to_plat,
|
2016-12-05 23:00:49 +00:00
|
|
|
.probe = fecmxc_probe,
|
|
|
|
.remove = fecmxc_remove,
|
|
|
|
.ops = &fecmxc_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct fec_priv),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct eth_pdata),
|
2016-12-05 23:00:49 +00:00
|
|
|
};
|
|
|
|
#endif
|