Skip to content

Commit 85ef603

Browse files
Biao Huangdavem330
authored andcommitted
net: ethernet: mtk-star-emac: add clock pad selection for RMII
This patch add a new dts property named "mediatek,rmii-rxc" parsing in driver, which will configure MAC to select which pin the RMII reference clock is connected to, TXC or RXC. TXC pad is the default reference clock pin. If user wants to use RXC pad instead, add "mediatek,rmii-rxc" to corresponding device node. Signed-off-by: Biao Huang <[email protected]> Signed-off-by: Yinghua Pan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4336069 commit 85ef603

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

drivers/net/ethernet/mediatek/mtk_star_emac.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ static const char *const mtk_star_clk_names[] = { "core", "reg", "trans" };
188188
#define MTK_PERICFG_REG_NIC_CFG_CON_V2 0x0c10
189189
#define MTK_PERICFG_REG_NIC_CFG_CON_CFG_INTF GENMASK(3, 0)
190190
#define MTK_PERICFG_BIT_NIC_CFG_CON_RMII 1
191+
#define MTK_PERICFG_BIT_NIC_CFG_CON_CLK BIT(0)
192+
#define MTK_PERICFG_BIT_NIC_CFG_CON_CLK_V2 BIT(8)
191193

192194
/* Represents the actual structure of descriptors used by the MAC. We can
193195
* reuse the same structure for both TX and RX - the layout is the same, only
@@ -264,6 +266,7 @@ struct mtk_star_priv {
264266
int speed;
265267
int duplex;
266268
int pause;
269+
bool rmii_rxc;
267270

268271
const struct mtk_star_compat *compat_data;
269272

@@ -1527,6 +1530,8 @@ static int mtk_star_probe(struct platform_device *pdev)
15271530
return -ENODEV;
15281531
}
15291532

1533+
priv->rmii_rxc = of_property_read_bool(of_node, "mediatek,rmii-rxc");
1534+
15301535
if (priv->compat_data->set_interface_mode) {
15311536
ret = priv->compat_data->set_interface_mode(ndev);
15321537
if (ret) {
@@ -1571,17 +1576,25 @@ static int mt8516_set_interface_mode(struct net_device *ndev)
15711576
{
15721577
struct mtk_star_priv *priv = netdev_priv(ndev);
15731578
struct device *dev = mtk_star_get_dev(priv);
1574-
unsigned int intf_val;
1579+
unsigned int intf_val, ret, rmii_rxc;
15751580

15761581
switch (priv->phy_intf) {
15771582
case PHY_INTERFACE_MODE_RMII:
15781583
intf_val = MTK_PERICFG_BIT_NIC_CFG_CON_RMII;
1584+
rmii_rxc = priv->rmii_rxc ? 0 : MTK_PERICFG_BIT_NIC_CFG_CON_CLK;
15791585
break;
15801586
default:
15811587
dev_err(dev, "This interface not supported\n");
15821588
return -EINVAL;
15831589
}
15841590

1591+
ret = regmap_update_bits(priv->pericfg,
1592+
MTK_PERICFG_REG_NIC_CFG1_CON,
1593+
MTK_PERICFG_BIT_NIC_CFG_CON_CLK,
1594+
rmii_rxc);
1595+
if (ret)
1596+
return ret;
1597+
15851598
return regmap_update_bits(priv->pericfg,
15861599
MTK_PERICFG_REG_NIC_CFG0_CON,
15871600
MTK_PERICFG_REG_NIC_CFG_CON_CFG_INTF,
@@ -1597,6 +1610,7 @@ static int mt8365_set_interface_mode(struct net_device *ndev)
15971610
switch (priv->phy_intf) {
15981611
case PHY_INTERFACE_MODE_RMII:
15991612
intf_val = MTK_PERICFG_BIT_NIC_CFG_CON_RMII;
1613+
intf_val |= priv->rmii_rxc ? 0 : MTK_PERICFG_BIT_NIC_CFG_CON_CLK_V2;
16001614
break;
16011615
default:
16021616
dev_err(dev, "This interface not supported\n");
@@ -1605,7 +1619,8 @@ static int mt8365_set_interface_mode(struct net_device *ndev)
16051619

16061620
return regmap_update_bits(priv->pericfg,
16071621
MTK_PERICFG_REG_NIC_CFG_CON_V2,
1608-
MTK_PERICFG_REG_NIC_CFG_CON_CFG_INTF,
1622+
MTK_PERICFG_REG_NIC_CFG_CON_CFG_INTF |
1623+
MTK_PERICFG_BIT_NIC_CFG_CON_CLK_V2,
16091624
intf_val);
16101625
}
16111626

0 commit comments

Comments
 (0)