2011-04-08 02:56:05 +00:00
|
|
|
/*
|
|
|
|
* Micrel PHY drivers
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-04-08 02:56:05 +00:00
|
|
|
*
|
|
|
|
* Copyright 2010-2011 Freescale Semiconductor, Inc.
|
|
|
|
* author Andy Fleming
|
2013-02-06 21:18:37 +00:00
|
|
|
* (C) 2012 NetModule AG, David Andrey, added KSZ9031
|
2011-04-08 02:56:05 +00:00
|
|
|
*/
|
2012-02-07 14:08:48 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <micrel.h>
|
2011-04-08 02:56:05 +00:00
|
|
|
#include <phy.h>
|
|
|
|
|
|
|
|
static struct phy_driver KSZ804_driver = {
|
|
|
|
.name = "Micrel KSZ804",
|
|
|
|
.uid = 0x221510,
|
|
|
|
.mask = 0xfffff0,
|
|
|
|
.features = PHY_BASIC_FEATURES,
|
|
|
|
.config = &genphy_config,
|
|
|
|
.startup = &genphy_startup,
|
|
|
|
.shutdown = &genphy_shutdown,
|
|
|
|
};
|
|
|
|
|
2012-06-28 08:00:28 +00:00
|
|
|
#ifndef CONFIG_PHY_MICREL_KSZ9021
|
|
|
|
/*
|
|
|
|
* I can't believe Micrel used the exact same part number
|
|
|
|
* for the KSZ9021
|
|
|
|
* Shame Micrel, Shame!!!!!
|
|
|
|
*/
|
2011-12-06 02:47:57 +00:00
|
|
|
static struct phy_driver KS8721_driver = {
|
|
|
|
.name = "Micrel KS8721BL",
|
|
|
|
.uid = 0x221610,
|
|
|
|
.mask = 0xfffff0,
|
|
|
|
.features = PHY_BASIC_FEATURES,
|
|
|
|
.config = &genphy_config,
|
|
|
|
.startup = &genphy_startup,
|
|
|
|
.shutdown = &genphy_shutdown,
|
|
|
|
};
|
2012-06-28 08:00:28 +00:00
|
|
|
#endif
|
2011-12-06 02:47:57 +00:00
|
|
|
|
2013-02-06 21:18:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* KSZ9021 - KSZ9031 common
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MII_KSZ90xx_PHY_CTL 0x1f
|
|
|
|
#define MIIM_KSZ90xx_PHYCTL_1000 (1 << 6)
|
|
|
|
#define MIIM_KSZ90xx_PHYCTL_100 (1 << 5)
|
|
|
|
#define MIIM_KSZ90xx_PHYCTL_10 (1 << 4)
|
|
|
|
#define MIIM_KSZ90xx_PHYCTL_DUPLEX (1 << 3)
|
|
|
|
|
|
|
|
static int ksz90xx_startup(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
unsigned phy_ctl;
|
|
|
|
genphy_update_link(phydev);
|
|
|
|
phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ90xx_PHY_CTL);
|
|
|
|
|
|
|
|
if (phy_ctl & MIIM_KSZ90xx_PHYCTL_DUPLEX)
|
|
|
|
phydev->duplex = DUPLEX_FULL;
|
|
|
|
else
|
|
|
|
phydev->duplex = DUPLEX_HALF;
|
|
|
|
|
|
|
|
if (phy_ctl & MIIM_KSZ90xx_PHYCTL_1000)
|
|
|
|
phydev->speed = SPEED_1000;
|
|
|
|
else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_100)
|
|
|
|
phydev->speed = SPEED_100;
|
|
|
|
else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_10)
|
|
|
|
phydev->speed = SPEED_10;
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-28 08:00:28 +00:00
|
|
|
#ifdef CONFIG_PHY_MICREL_KSZ9021
|
2013-02-06 21:18:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* KSZ9021
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* PHY Registers */
|
2012-02-07 14:08:48 +00:00
|
|
|
#define MII_KSZ9021_EXTENDED_CTRL 0x0b
|
|
|
|
#define MII_KSZ9021_EXTENDED_DATAW 0x0c
|
|
|
|
#define MII_KSZ9021_EXTENDED_DATAR 0x0d
|
|
|
|
|
|
|
|
#define CTRL1000_PREFER_MASTER (1 << 10)
|
|
|
|
#define CTRL1000_CONFIG_MASTER (1 << 11)
|
|
|
|
#define CTRL1000_MANUAL_CONFIG (1 << 12)
|
|
|
|
|
|
|
|
int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val)
|
|
|
|
{
|
|
|
|
/* extended registers */
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000);
|
|
|
|
return phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9021_EXTENDED_DATAW, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum)
|
|
|
|
{
|
|
|
|
/* extended registers */
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_CTRL, regnum);
|
|
|
|
return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Micrel ksz9021 */
|
|
|
|
static int ksz9021_config(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
unsigned ctrl1000 = 0;
|
|
|
|
const unsigned master = CTRL1000_PREFER_MASTER |
|
|
|
|
CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
|
|
|
|
unsigned features = phydev->drv->features;
|
|
|
|
|
|
|
|
if (getenv("disable_giga"))
|
|
|
|
features &= ~(SUPPORTED_1000baseT_Half |
|
|
|
|
SUPPORTED_1000baseT_Full);
|
|
|
|
/* force master mode for 1000BaseT due to chip errata */
|
|
|
|
if (features & SUPPORTED_1000baseT_Half)
|
|
|
|
ctrl1000 |= ADVERTISE_1000HALF | master;
|
|
|
|
if (features & SUPPORTED_1000baseT_Full)
|
|
|
|
ctrl1000 |= ADVERTISE_1000FULL | master;
|
|
|
|
phydev->advertising = phydev->supported = features;
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
|
|
|
|
genphy_config_aneg(phydev);
|
|
|
|
genphy_restart_aneg(phydev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct phy_driver ksz9021_driver = {
|
|
|
|
.name = "Micrel ksz9021",
|
|
|
|
.uid = 0x221610,
|
|
|
|
.mask = 0xfffff0,
|
|
|
|
.features = PHY_GBIT_FEATURES,
|
|
|
|
.config = &ksz9021_config,
|
2013-02-06 21:18:37 +00:00
|
|
|
.startup = &ksz90xx_startup,
|
2012-02-07 14:08:48 +00:00
|
|
|
.shutdown = &genphy_shutdown,
|
|
|
|
};
|
2012-06-28 08:00:28 +00:00
|
|
|
#endif
|
2012-02-07 14:08:48 +00:00
|
|
|
|
2013-04-30 14:57:25 +00:00
|
|
|
/**
|
2013-02-06 21:18:37 +00:00
|
|
|
* KSZ9031
|
|
|
|
*/
|
2013-04-30 14:57:25 +00:00
|
|
|
/* PHY Registers */
|
|
|
|
#define MII_KSZ9031_MMD_ACCES_CTRL 0x0d
|
|
|
|
#define MII_KSZ9031_MMD_REG_DATA 0x0e
|
|
|
|
|
|
|
|
/* Accessors to extended registers*/
|
|
|
|
int ksz9031_phy_extended_write(struct phy_device *phydev,
|
|
|
|
int devaddr, int regnum, u16 mode, u16 val)
|
|
|
|
{
|
|
|
|
/*select register addr for mmd*/
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
|
|
|
|
/*select register for mmd*/
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_REG_DATA, regnum);
|
|
|
|
/*setup mode*/
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_ACCES_CTRL, (mode | devaddr));
|
|
|
|
/*write the value*/
|
|
|
|
return phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_REG_DATA, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr,
|
|
|
|
int regnum, u16 mode)
|
|
|
|
{
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_REG_DATA, regnum);
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE,
|
|
|
|
MII_KSZ9031_MMD_ACCES_CTRL, (devaddr | mode));
|
|
|
|
return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA);
|
|
|
|
}
|
|
|
|
|
2013-02-06 21:18:37 +00:00
|
|
|
static struct phy_driver ksz9031_driver = {
|
|
|
|
.name = "Micrel ksz9031",
|
|
|
|
.uid = 0x221620,
|
2013-09-02 13:42:29 +00:00
|
|
|
.mask = 0xfffff0,
|
2013-02-06 21:18:37 +00:00
|
|
|
.features = PHY_GBIT_FEATURES,
|
|
|
|
.config = &genphy_config,
|
|
|
|
.startup = &ksz90xx_startup,
|
|
|
|
.shutdown = &genphy_shutdown,
|
|
|
|
};
|
|
|
|
|
2011-04-08 02:56:05 +00:00
|
|
|
int phy_micrel_init(void)
|
|
|
|
{
|
|
|
|
phy_register(&KSZ804_driver);
|
2012-06-28 08:00:28 +00:00
|
|
|
#ifdef CONFIG_PHY_MICREL_KSZ9021
|
2012-02-07 14:08:48 +00:00
|
|
|
phy_register(&ksz9021_driver);
|
2012-06-28 08:00:28 +00:00
|
|
|
#else
|
|
|
|
phy_register(&KS8721_driver);
|
|
|
|
#endif
|
2013-02-06 21:18:37 +00:00
|
|
|
phy_register(&ksz9031_driver);
|
2011-04-08 02:56:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|