2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-04-08 07:10:54 +00:00
|
|
|
/*
|
2013-09-30 09:44:43 +00:00
|
|
|
* Copyright 2009-2010, 2013 Freescale Semiconductor, Inc.
|
2011-04-08 07:10:54 +00:00
|
|
|
* Jun-jie Zhang <b18070@freescale.com>
|
|
|
|
* Mingkai Hu <Mingkai.hu@freescale.com>
|
|
|
|
*/
|
2016-01-12 06:41:18 +00:00
|
|
|
|
2011-04-08 07:10:54 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <miiphy.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <fsl_mdio.h>
|
|
|
|
#include <asm/io.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2011-04-08 07:10:54 +00:00
|
|
|
|
2013-09-30 09:44:43 +00:00
|
|
|
void tsec_local_mdio_write(struct tsec_mii_mng __iomem *phyregs, int port_addr,
|
2011-04-08 07:10:54 +00:00
|
|
|
int dev_addr, int regnum, int value)
|
|
|
|
{
|
|
|
|
int timeout = 1000000;
|
|
|
|
|
|
|
|
out_be32(&phyregs->miimadd, (port_addr << 8) | (regnum & 0x1f));
|
|
|
|
out_be32(&phyregs->miimcon, value);
|
2014-09-05 05:52:37 +00:00
|
|
|
/* Memory barrier */
|
|
|
|
mb();
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
while ((in_be32(&phyregs->miimind) & MIIMIND_BUSY) && timeout--)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2013-09-30 09:44:43 +00:00
|
|
|
int tsec_local_mdio_read(struct tsec_mii_mng __iomem *phyregs, int port_addr,
|
2011-04-08 07:10:54 +00:00
|
|
|
int dev_addr, int regnum)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
int timeout = 1000000;
|
|
|
|
|
2016-01-12 06:41:18 +00:00
|
|
|
/* Put the address of the phy, and the register number into MIIMADD */
|
2011-04-08 07:10:54 +00:00
|
|
|
out_be32(&phyregs->miimadd, (port_addr << 8) | (regnum & 0x1f));
|
|
|
|
|
|
|
|
/* Clear the command register, and wait */
|
|
|
|
out_be32(&phyregs->miimcom, 0);
|
2014-09-05 05:52:37 +00:00
|
|
|
/* Memory barrier */
|
|
|
|
mb();
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
/* Initiate a read command, and wait */
|
|
|
|
out_be32(&phyregs->miimcom, MIIMCOM_READ_CYCLE);
|
2014-09-05 05:52:37 +00:00
|
|
|
/* Memory barrier */
|
|
|
|
mb();
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
/* Wait for the the indication that the read is done */
|
|
|
|
while ((in_be32(&phyregs->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
|
|
|
|
&& timeout--)
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Grab the value read from the PHY */
|
|
|
|
value = in_be32(&phyregs->miimstat);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fsl_pq_mdio_reset(struct mii_dev *bus)
|
|
|
|
{
|
2013-09-30 09:44:43 +00:00
|
|
|
struct tsec_mii_mng __iomem *regs =
|
|
|
|
(struct tsec_mii_mng __iomem *)bus->priv;
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
/* Reset MII (due to new addresses) */
|
|
|
|
out_be32(®s->miimcfg, MIIMCFG_RESET_MGMT);
|
|
|
|
|
|
|
|
out_be32(®s->miimcfg, MIIMCFG_INIT_VALUE);
|
|
|
|
|
|
|
|
while (in_be32(®s->miimind) & MIIMIND_BUSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tsec_phy_read(struct mii_dev *bus, int addr, int dev_addr, int regnum)
|
|
|
|
{
|
2013-09-30 09:44:43 +00:00
|
|
|
struct tsec_mii_mng __iomem *phyregs =
|
|
|
|
(struct tsec_mii_mng __iomem *)bus->priv;
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
return tsec_local_mdio_read(phyregs, addr, dev_addr, regnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tsec_phy_write(struct mii_dev *bus, int addr, int dev_addr, int regnum,
|
|
|
|
u16 value)
|
|
|
|
{
|
2013-09-30 09:44:43 +00:00
|
|
|
struct tsec_mii_mng __iomem *phyregs =
|
|
|
|
(struct tsec_mii_mng __iomem *)bus->priv;
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
tsec_local_mdio_write(phyregs, addr, dev_addr, regnum, value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fsl_pq_mdio_init(bd_t *bis, struct fsl_pq_mdio_info *info)
|
|
|
|
{
|
|
|
|
struct mii_dev *bus = mdio_alloc();
|
|
|
|
|
|
|
|
if (!bus) {
|
|
|
|
printf("Failed to allocate FSL MDIO bus\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus->read = tsec_phy_read;
|
|
|
|
bus->write = tsec_phy_write;
|
|
|
|
bus->reset = fsl_pq_mdio_reset;
|
2015-12-30 13:05:58 +00:00
|
|
|
strcpy(bus->name, info->name);
|
2011-04-08 07:10:54 +00:00
|
|
|
|
2013-09-30 09:44:43 +00:00
|
|
|
bus->priv = (void *)info->regs;
|
2011-04-08 07:10:54 +00:00
|
|
|
|
|
|
|
return mdio_register(bus);
|
|
|
|
}
|