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

net: hisilicon: add support of acpi for hns-mdio

hns-mdio needs to register itself to mii-bus. The info of the device can
be read by both DT and ACPI.
HNS tries to call Linux PHY driver to help access PHY-devices, the HNS
hardware topology is as below. The MDIO controller may control several
PHY-devices, and each PHY-device connects to a MAC device. The MDIO will
be registered to mdiobus, then PHY-devices will register when each mac
find PHY device.
                       cpu
                        |
                        |
     -------------------------------------------
    |                   |                       |
    |                   |                       |
    |                  dsaf                     |
   MDIO                 |                      MDIO
    |      ---------------------------          |
    |     |         |         |       |         |
    |     |         |         |       |         |
    |    MAC       MAC       MAC     MAC        |
    |     |         |         |       |         |
     ---- |-------- |-------- |       | --------
         ||        ||        ||       ||
         PHY       PHY       PHY     PHY

And the driver can handle reset sequence by _RST method in DSDT in ACPI
case.
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 16a9f361
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* (at your option) any later version. * (at your option) any later version.
*/ */
#include <linux/acpi.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -354,48 +355,60 @@ static int hns_mdio_reset(struct mii_bus *bus) ...@@ -354,48 +355,60 @@ 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;
int ret; int ret;
if (!dev_of_node(bus->parent)) if (dev_of_node(bus->parent)) {
return -ENOTSUPP; if (!mdio_dev->subctrl_vbase) {
dev_err(&bus->dev, "mdio sys ctl reg has not maped\n");
return -ENODEV;
}
if (!mdio_dev->subctrl_vbase) { /* 1. reset req, and read reset st check */
dev_err(&bus->dev, "mdio sys ctl reg has not maped\n"); ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
return -ENODEV; MDIO_SC_RESET_ST, 0x1,
} MDIO_CHECK_SET_ST);
if (ret) {
dev_err(&bus->dev, "MDIO reset fail\n");
return ret;
}
/*1. reset req, and read reset st check*/ /* 2. dis clk, and read clk st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1, ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
MDIO_SC_RESET_ST, 0x1, 0x1, MDIO_SC_CLK_ST, 0x1,
MDIO_CHECK_SET_ST); MDIO_CHECK_CLR_ST);
if (ret) { if (ret) {
dev_err(&bus->dev, "MDIO reset fail\n"); dev_err(&bus->dev, "MDIO dis clk fail\n");
return ret; return ret;
} }
/*2. dis clk, and read clk st check*/ /* 3. reset dreq, and read reset st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS, ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
0x1, MDIO_SC_CLK_ST, 0x1, MDIO_SC_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");
return ret; return ret;
} }
/*3. reset dreq, and read reset st check*/ /* 4. en clk, and read clk st check */
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1, ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
MDIO_SC_RESET_ST, 0x1, 0x1, MDIO_SC_CLK_ST, 0x1,
MDIO_CHECK_CLR_ST); MDIO_CHECK_SET_ST);
if (ret) { if (ret)
dev_err(&bus->dev, "MDIO dis clk fail\n"); dev_err(&bus->dev, "MDIO en clk fail\n");
return ret; } else if (is_acpi_node(bus->parent->fwnode)) {
acpi_status s;
s = acpi_evaluate_object(ACPI_HANDLE(bus->parent),
"_RST", NULL, NULL);
if (ACPI_FAILURE(s)) {
dev_err(&bus->dev, "Reset failed, return:%#x\n", s);
ret = -EBUSY;
} else {
ret = 0;
}
} else {
dev_err(&bus->dev, "Can not get cfg data from DT or ACPI\n");
ret = -ENXIO;
} }
/*4. en clk, and read clk st check*/
ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_EN,
0x1, MDIO_SC_CLK_ST, 0x1,
MDIO_CHECK_SET_ST);
if (ret)
dev_err(&bus->dev, "MDIO en clk fail\n");
return ret; return ret;
} }
...@@ -453,6 +466,18 @@ static int hns_mdio_probe(struct platform_device *pdev) ...@@ -453,6 +466,18 @@ static int hns_mdio_probe(struct platform_device *pdev)
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)) {
/* Clear all the IRQ properties */
memset(new_bus->irq, PHY_POLL, 4 * PHY_MAX_ADDR);
/* Mask out all PHYs from auto probing. */
new_bus->phy_mask = ~0;
/* Register the MDIO bus */
ret = mdiobus_register(new_bus);
} else {
dev_err(&pdev->dev, "Can not get cfg data from DT or ACPI\n");
ret = -ENXIO;
} }
if (ret) { if (ret) {
...@@ -487,12 +512,19 @@ static const struct of_device_id hns_mdio_match[] = { ...@@ -487,12 +512,19 @@ static const struct of_device_id hns_mdio_match[] = {
{} {}
}; };
static const struct acpi_device_id hns_mdio_acpi_match[] = {
{ "HISI0141", 0 },
{ },
};
MODULE_DEVICE_TABLE(acpi, hns_mdio_acpi_match);
static struct platform_driver hns_mdio_driver = { static struct platform_driver hns_mdio_driver = {
.probe = hns_mdio_probe, .probe = hns_mdio_probe,
.remove = hns_mdio_remove, .remove = hns_mdio_remove,
.driver = { .driver = {
.name = MDIO_DRV_NAME, .name = MDIO_DRV_NAME,
.of_match_table = hns_mdio_match, .of_match_table = hns_mdio_match,
.acpi_match_table = ACPI_PTR(hns_mdio_acpi_match),
}, },
}; };
......
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