[PATCH v3 net-next 04/13] net: hisilicon: add support of acpi for hns-mdio

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

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: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3:
add Reviewed-by: Andy Shevchenko
 v2:
1. use dev_of_node instead of IS_ENABLED macro
2. Add ACPI bits
Link: https://lkml.org/lkml/2016/5/29/185

 v1: first submit
Link: https://lkml.org/lkml/2016/5/13/93
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 107 +++---
 1 file changed, 69 insertions(+), 38 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 381cf0a..f78286c 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -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;
int ret;
 
-   if (!dev_of_node(bus->parent))
-   return -ENOTSUPP;
+   if (dev_of_node(bus->parent)) {
+   if (!mdio_dev->subctrl_vbase) {
+   dev_err(>dev, "mdio sys ctl reg has not maped\n");
+   return -ENODEV;
+   }
 
-   if (!mdio_dev->subctrl_vbase) {
-   dev_err(>dev, "mdio sys ctl reg has not maped\n");
-   return -ENODEV;
-   }
+   /* 1. reset req, and read reset st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
+   MDIO_SC_RESET_ST, 0x1,
+   MDIO_CHECK_SET_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO reset fail\n");
+   return ret;
+   }
 
-   /*1. reset req, and read reset st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
-   MDIO_SC_RESET_ST, 0x1,
-   MDIO_CHECK_SET_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO reset fail\n");
-   return ret;
-   }
+   /* 2. dis clk, and read clk st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
+   0x1, MDIO_SC_CLK_ST, 0x1,
+   MDIO_CHECK_CLR_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO dis clk fail\n");
+   return ret;
+   }
 
-   /*2. dis clk, and read clk st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
-   0x1, MDIO_SC_CLK_ST, 0x1,
-   MDIO_CHECK_CLR_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO dis clk fail\n");
-   return ret;
-   }
+   /* 3. reset dreq, and read reset st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
+   MDIO_SC_RESET_ST, 0x1,
+   MDIO_CHECK_CLR_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO dis clk fail\n");
+   return ret;
+   }
 
-   /*3. reset dreq, and read reset st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
-   MDIO_SC_RESET_ST, 0x1,
-   MDIO_CHECK_CLR_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO dis clk fail\n");
-   return ret;

[PATCH v3 net-next 04/13] net: hisilicon: add support of acpi for hns-mdio

2016-05-30 Thread Yisen Zhuang
From: Kejian Yan 

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: Kejian Yan 
Reviewed-by: Andy Shevchenko 
Signed-off-by: Yisen Zhuang 
---
change log:
 v3:
add Reviewed-by: Andy Shevchenko
 v2:
1. use dev_of_node instead of IS_ENABLED macro
2. Add ACPI bits
Link: https://lkml.org/lkml/2016/5/29/185

 v1: first submit
Link: https://lkml.org/lkml/2016/5/13/93
---
 drivers/net/ethernet/hisilicon/hns_mdio.c | 107 +++---
 1 file changed, 69 insertions(+), 38 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns_mdio.c 
b/drivers/net/ethernet/hisilicon/hns_mdio.c
index 381cf0a..f78286c 100644
--- a/drivers/net/ethernet/hisilicon/hns_mdio.c
+++ b/drivers/net/ethernet/hisilicon/hns_mdio.c
@@ -7,6 +7,7 @@
  * (at your option) any later version.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -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;
int ret;
 
-   if (!dev_of_node(bus->parent))
-   return -ENOTSUPP;
+   if (dev_of_node(bus->parent)) {
+   if (!mdio_dev->subctrl_vbase) {
+   dev_err(>dev, "mdio sys ctl reg has not maped\n");
+   return -ENODEV;
+   }
 
-   if (!mdio_dev->subctrl_vbase) {
-   dev_err(>dev, "mdio sys ctl reg has not maped\n");
-   return -ENODEV;
-   }
+   /* 1. reset req, and read reset st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
+   MDIO_SC_RESET_ST, 0x1,
+   MDIO_CHECK_SET_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO reset fail\n");
+   return ret;
+   }
 
-   /*1. reset req, and read reset st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_REQ, 0x1,
-   MDIO_SC_RESET_ST, 0x1,
-   MDIO_CHECK_SET_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO reset fail\n");
-   return ret;
-   }
+   /* 2. dis clk, and read clk st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
+   0x1, MDIO_SC_CLK_ST, 0x1,
+   MDIO_CHECK_CLR_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO dis clk fail\n");
+   return ret;
+   }
 
-   /*2. dis clk, and read clk st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_CLK_DIS,
-   0x1, MDIO_SC_CLK_ST, 0x1,
-   MDIO_CHECK_CLR_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO dis clk fail\n");
-   return ret;
-   }
+   /* 3. reset dreq, and read reset st check */
+   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
+   MDIO_SC_RESET_ST, 0x1,
+   MDIO_CHECK_CLR_ST);
+   if (ret) {
+   dev_err(>dev, "MDIO dis clk fail\n");
+   return ret;
+   }
 
-   /*3. reset dreq, and read reset st check*/
-   ret = mdio_sc_cfg_reg_write(mdio_dev, MDIO_SC_RESET_DREQ, 0x1,
-   MDIO_SC_RESET_ST, 0x1,
-   MDIO_CHECK_CLR_ST);
-   if (ret) {
-   dev_err(>dev, "MDIO dis clk fail\n");
-   return ret;
+   /* 4. en clk, and read clk st check */
+   ret =