Commit b15dc292 authored by Kejian Yan's avatar Kejian Yan Committed by David S. Miller

net: hns: get reset registers from DT

Since the registers of subctrl may be different, it is better to
mv the registers from hns mdio driver routine to device tree node.
Signed-off-by: default avatarKejian Yan <yankejian@huawei.com>
Signed-off-by: default avatarYisen Zhuang <Yisen.Zhuang@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5d2525f7
...@@ -37,9 +37,19 @@ ...@@ -37,9 +37,19 @@
#define MDIO_TIMEOUT 1000000 #define MDIO_TIMEOUT 1000000
struct hns_mdio_sc_reg {
u16 mdio_clk_en;
u16 mdio_clk_dis;
u16 mdio_reset_req;
u16 mdio_reset_dreq;
u16 mdio_clk_st;
u16 mdio_reset_st;
};
struct hns_mdio_device { struct hns_mdio_device {
void *vbase; /* mdio reg base address */ void *vbase; /* mdio reg base address */
struct regmap *subctrl_vbase; struct regmap *subctrl_vbase;
struct hns_mdio_sc_reg sc_reg;
}; };
/* mdio reg */ /* mdio reg */
...@@ -93,7 +103,6 @@ enum mdio_c45_op_seq { ...@@ -93,7 +103,6 @@ enum mdio_c45_op_seq {
#define MDIO_SC_CLK_DIS 0x33C #define MDIO_SC_CLK_DIS 0x33C
#define MDIO_SC_RESET_REQ 0xA38 #define MDIO_SC_RESET_REQ 0xA38
#define MDIO_SC_RESET_DREQ 0xA3C #define MDIO_SC_RESET_DREQ 0xA3C
#define MDIO_SC_CTRL 0x2010
#define MDIO_SC_CLK_ST 0x531C #define MDIO_SC_CLK_ST 0x531C
#define MDIO_SC_RESET_ST 0x5A1C #define MDIO_SC_RESET_ST 0x5A1C
...@@ -353,6 +362,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, int regnum) ...@@ -353,6 +362,7 @@ static int hns_mdio_read(struct mii_bus *bus, int phy_id, int regnum)
static int hns_mdio_reset(struct mii_bus *bus) static int hns_mdio_reset(struct mii_bus *bus)
{ {
struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv; struct hns_mdio_device *mdio_dev = (struct hns_mdio_device *)bus->priv;
const struct hns_mdio_sc_reg *sc_reg;
int ret; int ret;
if (dev_of_node(bus->parent)) { if (dev_of_node(bus->parent)) {
...@@ -361,9 +371,10 @@ static int hns_mdio_reset(struct mii_bus *bus) ...@@ -361,9 +371,10 @@ static int hns_mdio_reset(struct mii_bus *bus)
return -ENODEV; return -ENODEV;
} }
sc_reg = &mdio_dev->sc_reg;
/* 1. reset req, and read reset st check */ /* 1. reset req, and read reset st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1, ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_req,
MDIO_SC_RESET_ST, 0x1, 0x1, sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_SET_ST); MDIO_CHECK_SET_ST);
if (ret) { if (ret) {
dev_err(&bus->dev, "MDIO reset fail\n"); dev_err(&bus->dev, "MDIO reset fail\n");
...@@ -371,8 +382,8 @@ static int hns_mdio_reset(struct mii_bus *bus) ...@@ -371,8 +382,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
} }
/* 2. dis clk, and read clk st check */ /* 2. dis clk, and read clk st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS, ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_dis,
0x1, MDIO_SC_CLK_ST, 0x1, 0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_CLR_ST); MDIO_CHECK_CLR_ST);
if (ret) { if (ret) {
dev_err(&bus->dev, "MDIO dis clk fail\n"); dev_err(&bus->dev, "MDIO dis clk fail\n");
...@@ -380,8 +391,8 @@ static int hns_mdio_reset(struct mii_bus *bus) ...@@ -380,8 +391,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
} }
/* 3. reset dreq, and read reset st check */ /* 3. reset dreq, and read reset st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1, ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_reset_dreq,
MDIO_SC_RESET_ST, 0x1, 0x1, sc_reg->mdio_reset_st, 0x1,
MDIO_CHECK_CLR_ST); MDIO_CHECK_CLR_ST);
if (ret) { if (ret) {
dev_err(&bus->dev, "MDIO dis clk fail\n"); dev_err(&bus->dev, "MDIO dis clk fail\n");
...@@ -389,8 +400,8 @@ static int hns_mdio_reset(struct mii_bus *bus) ...@@ -389,8 +400,8 @@ static int hns_mdio_reset(struct mii_bus *bus)
} }
/* 4. en clk, and read clk st check */ /* 4. en clk, and read clk st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN, ret = mdio_sc_cfg_reg_write(mdio_dev, sc_reg->mdio_clk_en,
0x1, MDIO_SC_CLK_ST, 0x1, 0x1, sc_reg->mdio_clk_st, 0x1,
MDIO_CHECK_SET_ST); MDIO_CHECK_SET_ST);
if (ret) if (ret)
dev_err(&bus->dev, "MDIO en clk fail\n"); dev_err(&bus->dev, "MDIO en clk fail\n");
...@@ -458,13 +469,54 @@ static int hns_mdio_probe(struct platform_device *pdev) ...@@ -458,13 +469,54 @@ static int hns_mdio_probe(struct platform_device *pdev)
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii", snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%s", "Mii",
dev_name(&pdev->dev)); dev_name(&pdev->dev));
if (dev_of_node(&pdev->dev)) { if (dev_of_node(&pdev->dev)) {
mdio_dev->subctrl_vbase = syscon_node_to_regmap( struct of_phandle_args reg_args;
of_parse_phandle(pdev->dev.of_node,
"subctrl-vbase", 0)); ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node,
if (IS_ERR(mdio_dev->subctrl_vbase)) { "subctrl-vbase",
dev_warn(&pdev->dev, "no syscon hisilicon,peri-c-subctrl\n"); 4,
0,
&reg_args);
if (!ret) {
mdio_dev->subctrl_vbase =
syscon_node_to_regmap(reg_args.np);
if (IS_ERR(mdio_dev->subctrl_vbase)) {
dev_warn(&pdev->dev, "syscon_node_to_regmap error\n");
mdio_dev->subctrl_vbase = NULL;
} else {
if (reg_args.args_count == 4) {
mdio_dev->sc_reg.mdio_clk_en =
(u16)reg_args.args[0];
mdio_dev->sc_reg.mdio_clk_dis =
(u16)reg_args.args[0] + 4;
mdio_dev->sc_reg.mdio_reset_req =
(u16)reg_args.args[1];
mdio_dev->sc_reg.mdio_reset_dreq =
(u16)reg_args.args[1] + 4;
mdio_dev->sc_reg.mdio_clk_st =
(u16)reg_args.args[2];
mdio_dev->sc_reg.mdio_reset_st =
(u16)reg_args.args[3];
} else {
/* for compatible */
mdio_dev->sc_reg.mdio_clk_en =
MDIO_SC_CLK_EN;
mdio_dev->sc_reg.mdio_clk_dis =
MDIO_SC_CLK_DIS;
mdio_dev->sc_reg.mdio_reset_req =
MDIO_SC_RESET_REQ;
mdio_dev->sc_reg.mdio_reset_dreq =
MDIO_SC_RESET_DREQ;
mdio_dev->sc_reg.mdio_clk_st =
MDIO_SC_CLK_ST;
mdio_dev->sc_reg.mdio_reset_st =
MDIO_SC_RESET_ST;
}
}
} else {
dev_warn(&pdev->dev, "find syscon ret = %#x\n", ret);
mdio_dev->subctrl_vbase = NULL; mdio_dev->subctrl_vbase = NULL;
} }
ret = of_mdiobus_register(new_bus, pdev->dev.of_node); ret = of_mdiobus_register(new_bus, pdev->dev.of_node);
} else if (is_acpi_node(pdev->dev.fwnode)) { } else if (is_acpi_node(pdev->dev.fwnode)) {
/* Clear all the IRQ properties */ /* Clear all the IRQ properties */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment