2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-04-08 02:56:05 +00:00
|
|
|
/*
|
|
|
|
* Atheros PHY drivers
|
|
|
|
*
|
2013-04-10 08:23:39 +00:00
|
|
|
* Copyright 2011, 2013 Freescale Semiconductor, Inc.
|
2011-04-08 02:56:05 +00:00
|
|
|
* author Andy Fleming
|
2020-05-06 22:11:57 +00:00
|
|
|
* Copyright (c) 2019 Michael Walle <michael@walle.cc>
|
2011-04-08 02:56:05 +00:00
|
|
|
*/
|
2018-07-25 17:59:22 +00:00
|
|
|
#include <common.h>
|
2011-04-08 02:56:05 +00:00
|
|
|
#include <phy.h>
|
2020-05-06 22:11:57 +00:00
|
|
|
#include <dm/device_compat.h>
|
|
|
|
#include <linux/bitfield.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-05-06 22:11:57 +00:00
|
|
|
#include <dt-bindings/net/qca-ar803x.h>
|
2011-04-08 02:56:05 +00:00
|
|
|
|
2016-10-13 14:03:36 +00:00
|
|
|
#define AR803x_PHY_DEBUG_ADDR_REG 0x1d
|
|
|
|
#define AR803x_PHY_DEBUG_DATA_REG 0x1e
|
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
/* Debug registers */
|
|
|
|
#define AR803x_DEBUG_REG_0 0x0
|
|
|
|
#define AR803x_RGMII_RX_CLK_DLY BIT(15)
|
|
|
|
|
2016-10-13 14:03:36 +00:00
|
|
|
#define AR803x_DEBUG_REG_5 0x5
|
2020-05-06 22:11:49 +00:00
|
|
|
#define AR803x_RGMII_TX_CLK_DLY BIT(8)
|
2016-10-13 14:03:36 +00:00
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
#define AR803x_DEBUG_REG_1F 0x1f
|
|
|
|
#define AR803x_PLL_ON BIT(2)
|
|
|
|
#define AR803x_RGMII_1V8 BIT(3)
|
2020-05-06 22:11:49 +00:00
|
|
|
|
2020-05-06 22:11:50 +00:00
|
|
|
/* CLK_25M register is at MMD 7, address 0x8016 */
|
|
|
|
#define AR803x_CLK_25M_SEL_REG 0x8016
|
2020-05-06 22:11:57 +00:00
|
|
|
|
|
|
|
#define AR803x_CLK_25M_MASK GENMASK(4, 2)
|
|
|
|
#define AR803x_CLK_25M_25MHZ_XTAL 0
|
|
|
|
#define AR803x_CLK_25M_25MHZ_DSP 1
|
|
|
|
#define AR803x_CLK_25M_50MHZ_PLL 2
|
|
|
|
#define AR803x_CLK_25M_50MHZ_DSP 3
|
|
|
|
#define AR803x_CLK_25M_62_5MHZ_PLL 4
|
|
|
|
#define AR803x_CLK_25M_62_5MHZ_DSP 5
|
|
|
|
#define AR803x_CLK_25M_125MHZ_PLL 6
|
|
|
|
#define AR803x_CLK_25M_125MHZ_DSP 7
|
2020-05-06 22:11:50 +00:00
|
|
|
#define AR8035_CLK_25M_MASK GENMASK(4, 3)
|
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
#define AR803x_CLK_25M_DR_MASK GENMASK(8, 7)
|
|
|
|
#define AR803x_CLK_25M_DR_FULL 0
|
|
|
|
#define AR803x_CLK_25M_DR_HALF 1
|
|
|
|
#define AR803x_CLK_25M_DR_QUARTER 2
|
|
|
|
|
2020-05-06 22:11:54 +00:00
|
|
|
#define AR8021_PHY_ID 0x004dd040
|
|
|
|
#define AR8031_PHY_ID 0x004dd074
|
|
|
|
#define AR8035_PHY_ID 0x004dd072
|
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
struct ar803x_priv {
|
|
|
|
int flags;
|
|
|
|
#define AR803x_FLAG_KEEP_PLL_ENABLED BIT(0) /* don't turn off internal PLL */
|
|
|
|
#define AR803x_FLAG_RGMII_1V8 BIT(1) /* use 1.8V RGMII I/O voltage */
|
|
|
|
u16 clk_25m_reg;
|
|
|
|
u16 clk_25m_mask;
|
|
|
|
};
|
|
|
|
|
2020-05-06 22:11:55 +00:00
|
|
|
static int ar803x_debug_reg_read(struct phy_device *phydev, u16 reg)
|
2020-05-06 22:11:49 +00:00
|
|
|
{
|
2020-05-06 22:11:55 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = phy_write(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_ADDR_REG,
|
|
|
|
reg);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return phy_read(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_DATA_REG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ar803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
|
|
|
|
u16 clear, u16 set)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = ar803x_debug_reg_read(phydev, reg);
|
|
|
|
if (val < 0)
|
|
|
|
return val;
|
|
|
|
|
|
|
|
val &= 0xffff;
|
|
|
|
val &= ~clear;
|
|
|
|
val |= set;
|
|
|
|
|
|
|
|
return phy_write(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_DATA_REG,
|
|
|
|
val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ar803x_enable_rx_delay(struct phy_device *phydev, bool on)
|
|
|
|
{
|
|
|
|
u16 clear = 0, set = 0;
|
2020-05-06 22:11:49 +00:00
|
|
|
|
|
|
|
if (on)
|
2020-05-06 22:11:55 +00:00
|
|
|
set = AR803x_RGMII_RX_CLK_DLY;
|
2020-05-06 22:11:49 +00:00
|
|
|
else
|
2020-05-06 22:11:55 +00:00
|
|
|
clear = AR803x_RGMII_RX_CLK_DLY;
|
|
|
|
|
|
|
|
return ar803x_debug_reg_mask(phydev, AR803x_DEBUG_REG_0, clear, set);
|
2020-05-06 22:11:49 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 22:11:55 +00:00
|
|
|
static int ar803x_enable_tx_delay(struct phy_device *phydev, bool on)
|
2020-05-06 22:11:49 +00:00
|
|
|
{
|
2020-05-06 22:11:55 +00:00
|
|
|
u16 clear = 0, set = 0;
|
2020-05-06 22:11:49 +00:00
|
|
|
|
|
|
|
if (on)
|
2020-05-06 22:11:55 +00:00
|
|
|
set = AR803x_RGMII_TX_CLK_DLY;
|
2020-05-06 22:11:49 +00:00
|
|
|
else
|
2020-05-06 22:11:55 +00:00
|
|
|
clear = AR803x_RGMII_TX_CLK_DLY;
|
|
|
|
|
|
|
|
return ar803x_debug_reg_mask(phydev, AR803x_DEBUG_REG_5, clear, set);
|
2020-05-06 22:11:49 +00:00
|
|
|
}
|
2016-10-13 14:03:36 +00:00
|
|
|
|
2011-04-08 02:56:05 +00:00
|
|
|
static int ar8021_config(struct phy_device *phydev)
|
|
|
|
{
|
2020-05-06 22:11:52 +00:00
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR,
|
|
|
|
BMCR_ANENABLE | BMCR_ANRESTART);
|
|
|
|
|
|
|
|
ar803x_enable_tx_delay(phydev, true);
|
2011-04-08 02:56:05 +00:00
|
|
|
|
2013-12-23 07:51:33 +00:00
|
|
|
phydev->supported = phydev->drv->features;
|
2011-04-08 02:56:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:11:56 +00:00
|
|
|
static int ar803x_delay_config(struct phy_device *phydev)
|
2016-10-13 14:03:36 +00:00
|
|
|
{
|
2020-05-06 22:11:56 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-10-13 14:03:36 +00:00
|
|
|
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID ||
|
2020-05-06 22:11:49 +00:00
|
|
|
phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
|
2020-05-06 22:11:56 +00:00
|
|
|
ret = ar803x_enable_tx_delay(phydev, true);
|
2020-05-06 22:11:51 +00:00
|
|
|
else
|
2020-05-06 22:11:56 +00:00
|
|
|
ret = ar803x_enable_tx_delay(phydev, false);
|
2016-10-13 14:03:36 +00:00
|
|
|
|
|
|
|
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID ||
|
2020-05-06 22:11:49 +00:00
|
|
|
phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
|
2020-05-06 22:11:56 +00:00
|
|
|
ret = ar803x_enable_rx_delay(phydev, true);
|
2020-05-06 22:11:51 +00:00
|
|
|
else
|
2020-05-06 22:11:56 +00:00
|
|
|
ret = ar803x_enable_rx_delay(phydev, false);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
static int ar803x_regs_config(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
struct ar803x_priv *priv = phydev->priv;
|
|
|
|
u16 set = 0, clear = 0;
|
|
|
|
int val;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* no configuration available */
|
|
|
|
if (!priv)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only supported on the AR8031, AR8035 has strappings for the PLL mode
|
|
|
|
* as well as the RGMII voltage.
|
|
|
|
*/
|
|
|
|
if (phydev->drv->uid == AR8031_PHY_ID) {
|
|
|
|
if (priv->flags & AR803x_FLAG_KEEP_PLL_ENABLED)
|
|
|
|
set |= AR803x_PLL_ON;
|
|
|
|
else
|
|
|
|
clear |= AR803x_PLL_ON;
|
|
|
|
|
|
|
|
if (priv->flags & AR803x_FLAG_RGMII_1V8)
|
|
|
|
set |= AR803x_RGMII_1V8;
|
|
|
|
else
|
|
|
|
clear |= AR803x_RGMII_1V8;
|
|
|
|
|
|
|
|
ret = ar803x_debug_reg_mask(phydev, AR803x_DEBUG_REG_1F, clear,
|
|
|
|
set);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save the write access if the mask is empty */
|
|
|
|
if (priv->clk_25m_mask) {
|
|
|
|
val = phy_read_mmd(phydev, MDIO_MMD_AN, AR803x_CLK_25M_SEL_REG);
|
|
|
|
if (val < 0)
|
|
|
|
return val;
|
|
|
|
val &= ~priv->clk_25m_mask;
|
|
|
|
val |= priv->clk_25m_reg;
|
|
|
|
ret = phy_write_mmd(phydev, MDIO_MMD_AN,
|
|
|
|
AR803x_CLK_25M_SEL_REG, val);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ar803x_of_init(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
#if defined(CONFIG_DM_ETH)
|
|
|
|
struct ar803x_priv *priv;
|
|
|
|
ofnode node, vddio_reg_node;
|
|
|
|
u32 strength, freq, min_uV, max_uV;
|
|
|
|
int sel;
|
|
|
|
|
|
|
|
node = phy_get_ofnode(phydev);
|
|
|
|
if (!ofnode_valid(node))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
priv = malloc(sizeof(*priv));
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
memset(priv, 0, sizeof(*priv));
|
|
|
|
|
|
|
|
phydev->priv = priv;
|
|
|
|
|
|
|
|
debug("%s: found PHY node: %s\n", __func__, ofnode_get_name(node));
|
|
|
|
|
|
|
|
if (ofnode_read_bool(node, "qca,keep-pll-enabled"))
|
|
|
|
priv->flags |= AR803x_FLAG_KEEP_PLL_ENABLED;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't use the regulator framework because the regulator is
|
|
|
|
* a subnode of the PHY. So just read the two properties we are
|
|
|
|
* interested in.
|
|
|
|
*/
|
|
|
|
vddio_reg_node = ofnode_find_subnode(node, "vddio-regulator");
|
|
|
|
if (ofnode_valid(vddio_reg_node)) {
|
|
|
|
min_uV = ofnode_read_u32_default(vddio_reg_node,
|
|
|
|
"regulator-min-microvolt", 0);
|
|
|
|
max_uV = ofnode_read_u32_default(vddio_reg_node,
|
|
|
|
"regulator-max-microvolt", 0);
|
|
|
|
|
|
|
|
if (min_uV != max_uV) {
|
|
|
|
free(priv);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (min_uV) {
|
|
|
|
case 1500000:
|
|
|
|
break;
|
|
|
|
case 1800000:
|
|
|
|
priv->flags |= AR803x_FLAG_RGMII_1V8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(priv);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the CLK_25M frequency from the device tree. Only XTAL and PLL
|
|
|
|
* sources are supported right now. There is also the possibilty to use
|
|
|
|
* the DSP as frequency reference, this is used for synchronous
|
|
|
|
* ethernet.
|
|
|
|
*/
|
|
|
|
if (!ofnode_read_u32(node, "qca,clk-out-frequency", &freq)) {
|
|
|
|
switch (freq) {
|
|
|
|
case 25000000:
|
|
|
|
sel = AR803x_CLK_25M_25MHZ_XTAL;
|
|
|
|
break;
|
|
|
|
case 50000000:
|
|
|
|
sel = AR803x_CLK_25M_50MHZ_PLL;
|
|
|
|
break;
|
|
|
|
case 62500000:
|
|
|
|
sel = AR803x_CLK_25M_62_5MHZ_PLL;
|
|
|
|
break;
|
|
|
|
case 125000000:
|
|
|
|
sel = AR803x_CLK_25M_125MHZ_PLL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(phydev->dev,
|
|
|
|
"invalid qca,clk-out-frequency\n");
|
|
|
|
free(priv);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->clk_25m_mask |= AR803x_CLK_25M_MASK;
|
|
|
|
priv->clk_25m_reg |= FIELD_PREP(AR803x_CLK_25M_MASK, sel);
|
|
|
|
/*
|
|
|
|
* Fixup for the AR8035 which only has two bits. The two
|
|
|
|
* remaining bits map to the same frequencies.
|
|
|
|
*/
|
|
|
|
|
2020-06-18 23:21:17 +00:00
|
|
|
if (phydev->drv->uid == AR8035_PHY_ID) {
|
|
|
|
priv->clk_25m_reg &= AR8035_CLK_25M_MASK;
|
|
|
|
priv->clk_25m_mask &= AR8035_CLK_25M_MASK;
|
2020-05-06 22:11:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phydev->drv->uid == AR8031_PHY_ID &&
|
|
|
|
!ofnode_read_u32(node, "qca,clk-out-strength", &strength)) {
|
|
|
|
switch (strength) {
|
|
|
|
case AR803X_STRENGTH_FULL:
|
|
|
|
sel = AR803x_CLK_25M_DR_FULL;
|
|
|
|
break;
|
|
|
|
case AR803X_STRENGTH_HALF:
|
|
|
|
sel = AR803x_CLK_25M_DR_HALF;
|
|
|
|
break;
|
|
|
|
case AR803X_STRENGTH_QUARTER:
|
|
|
|
sel = AR803x_CLK_25M_DR_QUARTER;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(phydev->dev,
|
|
|
|
"invalid qca,clk-out-strength\n");
|
|
|
|
free(priv);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
priv->clk_25m_mask |= AR803x_CLK_25M_DR_MASK;
|
|
|
|
priv->clk_25m_reg |= FIELD_PREP(AR803x_CLK_25M_DR_MASK, sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("%s: flags=%x clk_25m_reg=%04x clk_25m_mask=%04x\n", __func__,
|
|
|
|
priv->flags, priv->clk_25m_reg, priv->clk_25m_mask);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:11:59 +00:00
|
|
|
static int ar803x_config(struct phy_device *phydev)
|
2013-04-10 08:23:39 +00:00
|
|
|
{
|
2020-05-06 22:11:56 +00:00
|
|
|
int ret;
|
2013-04-10 08:23:39 +00:00
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
ret = ar803x_of_init(phydev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2020-05-06 22:11:56 +00:00
|
|
|
ret = ar803x_delay_config(phydev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-05-26 16:24:28 +00:00
|
|
|
|
2020-05-06 22:11:57 +00:00
|
|
|
ret = ar803x_regs_config(phydev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2014-04-11 08:03:11 +00:00
|
|
|
phydev->supported = phydev->drv->features;
|
2013-04-10 08:23:39 +00:00
|
|
|
|
2016-02-19 07:52:28 +00:00
|
|
|
genphy_config_aneg(phydev);
|
|
|
|
genphy_restart_aneg(phydev);
|
|
|
|
|
2013-04-10 08:23:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-29 13:34:33 +00:00
|
|
|
static struct phy_driver AR8021_driver = {
|
2011-04-08 02:56:05 +00:00
|
|
|
.name = "AR8021",
|
2020-05-06 22:11:54 +00:00
|
|
|
.uid = AR8021_PHY_ID,
|
2020-05-06 22:11:53 +00:00
|
|
|
.mask = 0xfffffff0,
|
2011-04-08 02:56:05 +00:00
|
|
|
.features = PHY_GBIT_FEATURES,
|
|
|
|
.config = ar8021_config,
|
|
|
|
.startup = genphy_startup,
|
|
|
|
.shutdown = genphy_shutdown,
|
|
|
|
};
|
|
|
|
|
2013-06-04 08:58:00 +00:00
|
|
|
static struct phy_driver AR8031_driver = {
|
2013-08-08 08:33:35 +00:00
|
|
|
.name = "AR8031/AR8033",
|
2020-05-06 22:11:54 +00:00
|
|
|
.uid = AR8031_PHY_ID,
|
2014-01-03 17:55:59 +00:00
|
|
|
.mask = 0xffffffef,
|
2013-06-04 08:58:00 +00:00
|
|
|
.features = PHY_GBIT_FEATURES,
|
2020-05-06 22:11:59 +00:00
|
|
|
.config = ar803x_config,
|
2013-06-04 08:58:00 +00:00
|
|
|
.startup = genphy_startup,
|
|
|
|
.shutdown = genphy_shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct phy_driver AR8035_driver = {
|
2013-04-10 08:23:39 +00:00
|
|
|
.name = "AR8035",
|
2020-05-06 22:11:54 +00:00
|
|
|
.uid = AR8035_PHY_ID,
|
2014-01-03 17:55:59 +00:00
|
|
|
.mask = 0xffffffef,
|
2013-04-10 08:23:39 +00:00
|
|
|
.features = PHY_GBIT_FEATURES,
|
2020-05-06 22:11:59 +00:00
|
|
|
.config = ar803x_config,
|
2013-04-10 08:23:39 +00:00
|
|
|
.startup = genphy_startup,
|
|
|
|
.shutdown = genphy_shutdown,
|
|
|
|
};
|
|
|
|
|
2011-04-08 02:56:05 +00:00
|
|
|
int phy_atheros_init(void)
|
|
|
|
{
|
|
|
|
phy_register(&AR8021_driver);
|
2013-06-04 08:58:00 +00:00
|
|
|
phy_register(&AR8031_driver);
|
2013-04-10 08:23:39 +00:00
|
|
|
phy_register(&AR8035_driver);
|
2011-04-08 02:56:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|