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>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2012-10-08 07:44:21 +00:00
|
|
|
* Some part is taken from tsec.c
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <miiphy.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/fsl_memac.h>
|
|
|
|
#include <fm_eth.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
u32 mdio_ctl;
|
|
|
|
struct memac_mdio_controller *regs = bus->priv;
|
|
|
|
u32 c45 = 1; /* Default to 10G interface */
|
|
|
|
|
|
|
|
if (dev_addr == MDIO_DEVAD_NONE) {
|
|
|
|
c45 = 0; /* clause 22 */
|
|
|
|
dev_addr = regnum & 0x1f;
|
|
|
|
clrbits_be32(®s->mdio_stat, MDIO_STAT_ENC);
|
2014-04-22 10:21:37 +00:00
|
|
|
} else
|
2012-10-08 07:44:21 +00:00
|
|
|
setbits_be32(®s->mdio_stat, MDIO_STAT_ENC);
|
|
|
|
|
|
|
|
/* Wait till the bus is free */
|
|
|
|
while ((in_be32(®s->mdio_stat)) & MDIO_STAT_BSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Set the port and dev addr */
|
|
|
|
mdio_ctl = MDIO_CTL_PORT_ADDR(port_addr) | MDIO_CTL_DEV_ADDR(dev_addr);
|
|
|
|
out_be32(®s->mdio_ctl, mdio_ctl);
|
|
|
|
|
|
|
|
/* Set the register address */
|
|
|
|
if (c45)
|
|
|
|
out_be32(®s->mdio_addr, regnum & 0xffff);
|
|
|
|
|
|
|
|
/* Wait till the bus is free */
|
|
|
|
while ((in_be32(®s->mdio_stat)) & MDIO_STAT_BSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Write the value to the register */
|
|
|
|
out_be32(®s->mdio_data, MDIO_DATA(value));
|
|
|
|
|
|
|
|
/* Wait till the MDIO write is complete */
|
|
|
|
while ((in_be32(®s->mdio_data)) & MDIO_DATA_BSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
u32 mdio_ctl;
|
|
|
|
struct memac_mdio_controller *regs = bus->priv;
|
|
|
|
u32 c45 = 1;
|
|
|
|
|
|
|
|
if (dev_addr == MDIO_DEVAD_NONE) {
|
2014-08-13 10:32:19 +00:00
|
|
|
if (!strcmp(bus->name, DEFAULT_FM_TGEC_MDIO_NAME))
|
|
|
|
return 0xffff;
|
2012-10-08 07:44:21 +00:00
|
|
|
c45 = 0; /* clause 22 */
|
|
|
|
dev_addr = regnum & 0x1f;
|
|
|
|
clrbits_be32(®s->mdio_stat, MDIO_STAT_ENC);
|
2014-04-22 10:21:37 +00:00
|
|
|
} else
|
2012-10-08 07:44:21 +00:00
|
|
|
setbits_be32(®s->mdio_stat, MDIO_STAT_ENC);
|
|
|
|
|
|
|
|
/* Wait till the bus is free */
|
|
|
|
while ((in_be32(®s->mdio_stat)) & MDIO_STAT_BSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Set the Port and Device Addrs */
|
|
|
|
mdio_ctl = MDIO_CTL_PORT_ADDR(port_addr) | MDIO_CTL_DEV_ADDR(dev_addr);
|
|
|
|
out_be32(®s->mdio_ctl, mdio_ctl);
|
|
|
|
|
|
|
|
/* Set the register address */
|
|
|
|
if (c45)
|
|
|
|
out_be32(®s->mdio_addr, regnum & 0xffff);
|
|
|
|
|
|
|
|
/* Wait till the bus is free */
|
|
|
|
while ((in_be32(®s->mdio_stat)) & MDIO_STAT_BSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Initiate the read */
|
|
|
|
mdio_ctl |= MDIO_CTL_READ;
|
|
|
|
out_be32(®s->mdio_ctl, mdio_ctl);
|
|
|
|
|
|
|
|
/* Wait till the MDIO write is complete */
|
|
|
|
while ((in_be32(®s->mdio_data)) & MDIO_DATA_BSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Return all Fs if nothing was there */
|
|
|
|
if (in_be32(®s->mdio_stat) & MDIO_STAT_RD_ER)
|
|
|
|
return 0xffff;
|
|
|
|
|
|
|
|
return in_be32(®s->mdio_data) & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
int memac_mdio_reset(struct mii_dev *bus)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fm_memac_mdio_init(bd_t *bis, struct memac_mdio_info *info)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
sprintf(bus->name, info->name);
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
setbits_be32(&((struct memac_mdio_controller *)info->regs)->mdio_stat,
|
2014-08-13 10:38:09 +00:00
|
|
|
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);
|
|
|
|
}
|