2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-10-08 07:44:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Freescale Semiconductor, Inc.
|
2014-07-25 22:39:08 +00:00
|
|
|
* Andy Fleming <afleming@gmail.com>
|
2012-10-08 07:44:21 +00:00
|
|
|
* Roy Zang <tie-fei.zang@freescale.com>
|
|
|
|
* Some part is taken from tsec.c
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <miiphy.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <asm/io.h>
|
2015-03-21 02:28:19 +00:00
|
|
|
#include <fsl_memac.h>
|
2012-10-08 07:44:21 +00:00
|
|
|
#include <fm_eth.h>
|
|
|
|
|
2015-03-21 02:28:19 +00:00
|
|
|
#ifdef CONFIG_SYS_MEMAC_LITTLE_ENDIAN
|
|
|
|
#define memac_out_32(a, v) out_le32(a, v)
|
|
|
|
#define memac_clrbits_32(a, v) clrbits_le32(a, v)
|
|
|
|
#define memac_setbits_32(a, v) setbits_le32(a, v)
|
|
|
|
#else
|
|
|
|
#define memac_out_32(a, v) out_be32(a, v)
|
|
|
|
#define memac_clrbits_32(a, v) clrbits_be32(a, v)
|
|
|
|
#define memac_setbits_32(a, v) setbits_be32(a, v)
|
|
|
|
#endif
|
|
|
|
|
2020-04-23 13:25:18 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct fm_mdio_priv {
|
|
|
|
struct memac_mdio_controller *regs;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
#define MAX_NUM_RETRIES 1000
|
|
|
|
|
2015-03-21 02:28:19 +00:00
|
|
|
static u32 memac_in_32(u32 *reg)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SYS_MEMAC_LITTLE_ENDIAN
|
|
|
|
return in_le32(reg);
|
|
|
|
#else
|
|
|
|
return in_be32(reg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
/*
|
|
|
|
* Wait until the MDIO bus is free
|
|
|
|
*/
|
|
|
|
static int memac_wait_until_free(struct memac_mdio_controller *regs)
|
|
|
|
{
|
|
|
|
unsigned int timeout = MAX_NUM_RETRIES;
|
|
|
|
|
|
|
|
while ((memac_in_32(®s->mdio_stat) & MDIO_STAT_BSY) && timeout--)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
printf("timeout waiting for MDIO bus to be free\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait till the MDIO read or write operation is complete
|
|
|
|
*/
|
|
|
|
static int memac_wait_until_done(struct memac_mdio_controller *regs)
|
|
|
|
{
|
|
|
|
unsigned int timeout = MAX_NUM_RETRIES;
|
|
|
|
|
2022-01-11 18:22:54 +00:00
|
|
|
while ((memac_in_32(®s->mdio_stat) & MDIO_STAT_BSY) && timeout--)
|
2020-12-09 11:31:58 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
if (!timeout) {
|
|
|
|
printf("timeout waiting for MDIO operation to complete\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-08 07:44:21 +00:00
|
|
|
/*
|
|
|
|
* Write value to the PHY for this device to the register at regnum, waiting
|
|
|
|
* until the write is done before it returns. All PHY configuration has to be
|
|
|
|
* done through the TSEC1 MIIM regs
|
|
|
|
*/
|
|
|
|
int memac_mdio_write(struct mii_dev *bus, int port_addr, int dev_addr,
|
|
|
|
int regnum, u16 value)
|
|
|
|
{
|
2020-04-23 13:25:18 +00:00
|
|
|
struct memac_mdio_controller *regs;
|
2012-10-08 07:44:21 +00:00
|
|
|
u32 mdio_ctl;
|
|
|
|
u32 c45 = 1; /* Default to 10G interface */
|
2020-12-09 11:31:58 +00:00
|
|
|
int err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-04-23 13:25:18 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
|
|
|
regs = bus->priv;
|
|
|
|
#else
|
|
|
|
struct fm_mdio_priv *priv;
|
|
|
|
|
|
|
|
if (!bus->priv)
|
|
|
|
return -EINVAL;
|
|
|
|
priv = dev_get_priv(bus->priv);
|
|
|
|
regs = priv->regs;
|
|
|
|
debug("memac_mdio_write(regs %p, port %d, dev %d, reg %d, val %#x)\n",
|
|
|
|
regs, port_addr, dev_addr, regnum, value);
|
|
|
|
#endif
|
|
|
|
|
2012-10-08 07:44:21 +00:00
|
|
|
if (dev_addr == MDIO_DEVAD_NONE) {
|
|
|
|
c45 = 0; /* clause 22 */
|
|
|
|
dev_addr = regnum & 0x1f;
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_clrbits_32(®s->mdio_stat, MDIO_STAT_ENC);
|
2014-04-22 10:21:37 +00:00
|
|
|
} else
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_setbits_32(®s->mdio_stat, MDIO_STAT_ENC);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
err = memac_wait_until_free(regs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Set the port and dev addr */
|
|
|
|
mdio_ctl = MDIO_CTL_PORT_ADDR(port_addr) | MDIO_CTL_DEV_ADDR(dev_addr);
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_out_32(®s->mdio_ctl, mdio_ctl);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Set the register address */
|
|
|
|
if (c45)
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_out_32(®s->mdio_addr, regnum & 0xffff);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
err = memac_wait_until_free(regs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Write the value to the register */
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_out_32(®s->mdio_data, MDIO_DATA(value));
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
err = memac_wait_until_done(regs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads from register regnum in the PHY for device dev, returning the value.
|
|
|
|
* Clears miimcom first. All PHY configuration has to be done through the
|
|
|
|
* TSEC1 MIIM regs
|
|
|
|
*/
|
|
|
|
int memac_mdio_read(struct mii_dev *bus, int port_addr, int dev_addr,
|
|
|
|
int regnum)
|
|
|
|
{
|
2020-04-23 13:25:18 +00:00
|
|
|
struct memac_mdio_controller *regs;
|
2012-10-08 07:44:21 +00:00
|
|
|
u32 mdio_ctl;
|
|
|
|
u32 c45 = 1;
|
2020-12-09 11:31:58 +00:00
|
|
|
int err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-04-23 13:25:18 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
|
|
|
regs = bus->priv;
|
|
|
|
#else
|
|
|
|
struct fm_mdio_priv *priv;
|
|
|
|
|
|
|
|
if (!bus->priv)
|
|
|
|
return -EINVAL;
|
|
|
|
priv = dev_get_priv(bus->priv);
|
|
|
|
regs = priv->regs;
|
|
|
|
#endif
|
|
|
|
|
2012-10-08 07:44:21 +00:00
|
|
|
if (dev_addr == MDIO_DEVAD_NONE) {
|
2020-04-23 13:25:18 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2014-08-13 10:32:19 +00:00
|
|
|
if (!strcmp(bus->name, DEFAULT_FM_TGEC_MDIO_NAME))
|
|
|
|
return 0xffff;
|
2020-04-23 13:25:18 +00:00
|
|
|
#endif
|
2012-10-08 07:44:21 +00:00
|
|
|
c45 = 0; /* clause 22 */
|
|
|
|
dev_addr = regnum & 0x1f;
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_clrbits_32(®s->mdio_stat, MDIO_STAT_ENC);
|
2014-04-22 10:21:37 +00:00
|
|
|
} else
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_setbits_32(®s->mdio_stat, MDIO_STAT_ENC);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
err = memac_wait_until_free(regs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Set the Port and Device Addrs */
|
|
|
|
mdio_ctl = MDIO_CTL_PORT_ADDR(port_addr) | MDIO_CTL_DEV_ADDR(dev_addr);
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_out_32(®s->mdio_ctl, mdio_ctl);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Set the register address */
|
|
|
|
if (c45)
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_out_32(®s->mdio_addr, regnum & 0xffff);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
err = memac_wait_until_free(regs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Initiate the read */
|
|
|
|
mdio_ctl |= MDIO_CTL_READ;
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_out_32(®s->mdio_ctl, mdio_ctl);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
2020-12-09 11:31:58 +00:00
|
|
|
err = memac_wait_until_done(regs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
/* Return all Fs if nothing was there */
|
2015-03-21 02:28:19 +00:00
|
|
|
if (memac_in_32(®s->mdio_stat) & MDIO_STAT_RD_ER)
|
2012-10-08 07:44:21 +00:00
|
|
|
return 0xffff;
|
|
|
|
|
2015-03-21 02:28:19 +00:00
|
|
|
return memac_in_32(®s->mdio_data) & 0xffff;
|
2012-10-08 07:44:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int memac_mdio_reset(struct mii_dev *bus)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:25:18 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2020-06-26 06:13:33 +00:00
|
|
|
int fm_memac_mdio_init(struct bd_info *bis, struct memac_mdio_info *info)
|
2012-10-08 07:44:21 +00:00
|
|
|
{
|
|
|
|
struct mii_dev *bus = mdio_alloc();
|
|
|
|
|
|
|
|
if (!bus) {
|
|
|
|
printf("Failed to allocate FM TGEC MDIO bus\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus->read = memac_mdio_read;
|
|
|
|
bus->write = memac_mdio_write;
|
|
|
|
bus->reset = memac_mdio_reset;
|
2015-12-30 13:05:58 +00:00
|
|
|
strcpy(bus->name, info->name);
|
2012-10-08 07:44:21 +00:00
|
|
|
|
|
|
|
bus->priv = info->regs;
|
|
|
|
|
driver/net/fm/memac_phy: Initialize mdio_clock for SoCs wih FMANv3
MDIO clock needs to be initialized in u-boot code for SoCs
having FMAN-v3(v3H or v3L) controller due to below reasons
-On SoCs that have FMAN-v3H like B4860, default value of
MDIO_CLK_DIV bits in mdio_stat(mdio_cfg) register generates
mdio clock too high (much higher than 2.5MHz), violating the
IEEE specs.
-On SOCs that have FMAN-v3L like T1040, default value of
MDIO_CLK_DIV bits is zero, so MDIO clock is disabled.
So, for proper functioninig of MDIO, MDIO_CLK_DIV bits needs to
be properly initialized.
Also this type of initialization is generally done in
PBI(pre-bootloader) phase using rcw.But for chips like T1040
which support deep-sleep, such type of initialization cannot be
done in PBI phase due to the limitation that during deep-sleep
resume, FMAN (MDIO) registers are not accessible in PBI phase.
So, mdio clock initailization must be done as part of u-boot.
This initialization code is implemented in memac_phy.c which
gets compiled only for SoCs having FMANv3, so no extra compilation
flag is required.
Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com>
Reviewed-by: York Sun <yorksun@freescale.com>
2014-04-08 05:25:49 +00:00
|
|
|
/*
|
|
|
|
* On some platforms like B4860, default value of MDIO_CLK_DIV bits
|
|
|
|
* in mdio_stat(mdio_cfg) register generates MDIO clock too high
|
|
|
|
* (much higher than 2.5MHz), violating the IEEE specs.
|
|
|
|
* On other platforms like T1040, default value of MDIO_CLK_DIV bits
|
|
|
|
* is zero, so MDIO clock is disabled.
|
|
|
|
* So, for proper functioning of MDIO, MDIO_CLK_DIV bits needs to
|
|
|
|
* be properly initialized.
|
2014-08-13 10:38:09 +00:00
|
|
|
* NEG bit default should be '1' as per FMAN-v3 RM, but on platform
|
|
|
|
* like T2080QDS, this bit default is '0', which leads to MDIO failure
|
|
|
|
* on XAUI PHY, so set this bit definitely.
|
driver/net/fm/memac_phy: Initialize mdio_clock for SoCs wih FMANv3
MDIO clock needs to be initialized in u-boot code for SoCs
having FMAN-v3(v3H or v3L) controller due to below reasons
-On SoCs that have FMAN-v3H like B4860, default value of
MDIO_CLK_DIV bits in mdio_stat(mdio_cfg) register generates
mdio clock too high (much higher than 2.5MHz), violating the
IEEE specs.
-On SOCs that have FMAN-v3L like T1040, default value of
MDIO_CLK_DIV bits is zero, so MDIO clock is disabled.
So, for proper functioninig of MDIO, MDIO_CLK_DIV bits needs to
be properly initialized.
Also this type of initialization is generally done in
PBI(pre-bootloader) phase using rcw.But for chips like T1040
which support deep-sleep, such type of initialization cannot be
done in PBI phase due to the limitation that during deep-sleep
resume, FMAN (MDIO) registers are not accessible in PBI phase.
So, mdio clock initailization must be done as part of u-boot.
This initialization code is implemented in memac_phy.c which
gets compiled only for SoCs having FMANv3, so no extra compilation
flag is required.
Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com>
Reviewed-by: York Sun <yorksun@freescale.com>
2014-04-08 05:25:49 +00:00
|
|
|
*/
|
2015-03-21 02:28:19 +00:00
|
|
|
memac_setbits_32(
|
|
|
|
&((struct memac_mdio_controller *)info->regs)->mdio_stat,
|
|
|
|
MDIO_STAT_CLKDIV(258) | MDIO_STAT_NEG);
|
driver/net/fm/memac_phy: Initialize mdio_clock for SoCs wih FMANv3
MDIO clock needs to be initialized in u-boot code for SoCs
having FMAN-v3(v3H or v3L) controller due to below reasons
-On SoCs that have FMAN-v3H like B4860, default value of
MDIO_CLK_DIV bits in mdio_stat(mdio_cfg) register generates
mdio clock too high (much higher than 2.5MHz), violating the
IEEE specs.
-On SOCs that have FMAN-v3L like T1040, default value of
MDIO_CLK_DIV bits is zero, so MDIO clock is disabled.
So, for proper functioninig of MDIO, MDIO_CLK_DIV bits needs to
be properly initialized.
Also this type of initialization is generally done in
PBI(pre-bootloader) phase using rcw.But for chips like T1040
which support deep-sleep, such type of initialization cannot be
done in PBI phase due to the limitation that during deep-sleep
resume, FMAN (MDIO) registers are not accessible in PBI phase.
So, mdio clock initailization must be done as part of u-boot.
This initialization code is implemented in memac_phy.c which
gets compiled only for SoCs having FMANv3, so no extra compilation
flag is required.
Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com>
Reviewed-by: York Sun <yorksun@freescale.com>
2014-04-08 05:25:49 +00:00
|
|
|
|
2012-10-08 07:44:21 +00:00
|
|
|
return mdio_register(bus);
|
|
|
|
}
|
2020-04-23 13:25:18 +00:00
|
|
|
|
|
|
|
#else /* CONFIG_DM_ETH */
|
|
|
|
#if defined(CONFIG_PHYLIB) && defined(CONFIG_DM_MDIO)
|
|
|
|
static int fm_mdio_read(struct udevice *dev, int addr, int devad, int reg)
|
|
|
|
{
|
|
|
|
struct mdio_perdev_priv *pdata = (dev) ? dev_get_uclass_priv(dev) :
|
|
|
|
NULL;
|
|
|
|
|
|
|
|
if (pdata && pdata->mii_bus)
|
|
|
|
return memac_mdio_read(pdata->mii_bus, addr, devad, reg);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fm_mdio_write(struct udevice *dev, int addr, int devad, int reg,
|
|
|
|
u16 val)
|
|
|
|
{
|
|
|
|
struct mdio_perdev_priv *pdata = (dev) ? dev_get_uclass_priv(dev) :
|
|
|
|
NULL;
|
|
|
|
|
|
|
|
if (pdata && pdata->mii_bus)
|
|
|
|
return memac_mdio_write(pdata->mii_bus, addr, devad, reg, val);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fm_mdio_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mdio_perdev_priv *pdata = (dev) ? dev_get_uclass_priv(dev) :
|
|
|
|
NULL;
|
|
|
|
|
|
|
|
if (pdata && pdata->mii_bus)
|
|
|
|
return memac_mdio_reset(pdata->mii_bus);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct mdio_ops fm_mdio_ops = {
|
|
|
|
.read = fm_mdio_read,
|
|
|
|
.write = fm_mdio_write,
|
|
|
|
.reset = fm_mdio_reset,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id fm_mdio_ids[] = {
|
|
|
|
{ .compatible = "fsl,fman-memac-mdio" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int fm_mdio_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct fm_mdio_priv *priv = (dev) ? dev_get_priv(dev) : NULL;
|
|
|
|
struct mdio_perdev_priv *pdata = (dev) ? dev_get_uclass_priv(dev) :
|
|
|
|
NULL;
|
|
|
|
|
|
|
|
if (!dev) {
|
|
|
|
printf("%s dev = NULL\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!priv) {
|
|
|
|
printf("dev_get_priv(dev %p) = NULL\n", dev);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
priv->regs = (void *)(uintptr_t)dev_read_addr(dev);
|
|
|
|
debug("%s priv %p @ regs %p, pdata %p\n", __func__,
|
|
|
|
priv, priv->regs, pdata);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On some platforms like B4860, default value of MDIO_CLK_DIV bits
|
|
|
|
* in mdio_stat(mdio_cfg) register generates MDIO clock too high
|
|
|
|
* (much higher than 2.5MHz), violating the IEEE specs.
|
|
|
|
* On other platforms like T1040, default value of MDIO_CLK_DIV bits
|
|
|
|
* is zero, so MDIO clock is disabled.
|
|
|
|
* So, for proper functioning of MDIO, MDIO_CLK_DIV bits needs to
|
|
|
|
* be properly initialized.
|
|
|
|
* The default NEG bit should be '1' as per FMANv3 RM, but on platforms
|
|
|
|
* like T2080QDS, this bit default is '0', which leads to MDIO failure
|
|
|
|
* on XAUI PHY, so set this bit definitely.
|
|
|
|
*/
|
|
|
|
if (priv && priv->regs && priv->regs->mdio_stat)
|
|
|
|
memac_setbits_32(&priv->regs->mdio_stat,
|
|
|
|
MDIO_STAT_CLKDIV(258) | MDIO_STAT_NEG);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fm_mdio_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(fman_mdio) = {
|
|
|
|
.name = "fman_mdio",
|
|
|
|
.id = UCLASS_MDIO,
|
|
|
|
.of_match = fm_mdio_ids,
|
|
|
|
.probe = fm_mdio_probe,
|
|
|
|
.remove = fm_mdio_remove,
|
|
|
|
.ops = &fm_mdio_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct fm_mdio_priv),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct mdio_perdev_priv),
|
2020-04-23 13:25:18 +00:00
|
|
|
};
|
|
|
|
#endif /* CONFIG_PHYLIB && CONFIG_DM_MDIO */
|
|
|
|
#endif /* CONFIG_DM_ETH */
|