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

net: hns: dsaf adds support of acpi

Dsaf needs to get configuration parameter by ACPI, so this patch add
support of ACPI.
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 a24274aa
...@@ -689,9 +689,7 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb) ...@@ -689,9 +689,7 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb)
return 0; return 0;
} }
if (!is_of_node(mac_cb->fw_port)) if (is_of_node(mac_cb->fw_port)) {
return -EINVAL;
/* parse property from port subnode in dsaf */ /* parse property from port subnode in dsaf */
np = of_parse_phandle(to_of_node(mac_cb->fw_port), "phy-handle", 0); np = of_parse_phandle(to_of_node(mac_cb->fw_port), "phy-handle", 0);
mac_cb->phy_dev = of_phy_find_device(np); mac_cb->phy_dev = of_phy_find_device(np);
...@@ -728,8 +726,9 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb) ...@@ -728,8 +726,9 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->mac_id); mac_cb->mac_id);
} }
ret = of_parse_phandle_with_fixed_args(to_of_node(mac_cb->fw_port), ret = of_parse_phandle_with_fixed_args(
"cpld-syscon", 1, 0, &cpld_args); to_of_node(mac_cb->fw_port), "cpld-syscon", 1, 0,
&cpld_args);
if (ret) { if (ret) {
dev_dbg(mac_cb->dev, "mac%d no cpld-syscon found.\n", dev_dbg(mac_cb->dev, "mac%d no cpld-syscon found.\n",
mac_cb->mac_id); mac_cb->mac_id);
...@@ -744,6 +743,7 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb) ...@@ -744,6 +743,7 @@ static int hns_mac_get_info(struct hns_mac_cb *mac_cb)
mac_cb->cpld_ctrl_reg = cpld_args.args[0]; mac_cb->cpld_ctrl_reg = cpld_args.args[0];
} }
} }
}
return 0; return 0;
} }
......
...@@ -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/device.h> #include <linux/device.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -33,6 +34,13 @@ const char *g_dsaf_mode_match[DSAF_MODE_MAX] = { ...@@ -33,6 +34,13 @@ const char *g_dsaf_mode_match[DSAF_MODE_MAX] = {
[DSAF_MODE_DISABLE_SP] = "single-port", [DSAF_MODE_DISABLE_SP] = "single-port",
}; };
static const struct acpi_device_id hns_dsaf_acpi_match[] = {
{ "HISI00B1", 0 },
{ "HISI00B2", 0 },
{ },
};
MODULE_DEVICE_TABLE(acpi, hns_dsaf_acpi_match);
int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev) int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
{ {
int ret, i; int ret, i;
...@@ -46,10 +54,22 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev) ...@@ -46,10 +54,22 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
struct device_node *np = dsaf_dev->dev->of_node; struct device_node *np = dsaf_dev->dev->of_node;
struct platform_device *pdev = to_platform_device(dsaf_dev->dev); struct platform_device *pdev = to_platform_device(dsaf_dev->dev);
if (dev_of_node(dsaf_dev->dev)) {
if (of_device_is_compatible(np, "hisilicon,hns-dsaf-v1")) if (of_device_is_compatible(np, "hisilicon,hns-dsaf-v1"))
dsaf_dev->dsaf_ver = AE_VERSION_1; dsaf_dev->dsaf_ver = AE_VERSION_1;
else else
dsaf_dev->dsaf_ver = AE_VERSION_2; dsaf_dev->dsaf_ver = AE_VERSION_2;
} else if (is_acpi_node(dsaf_dev->dev->fwnode)) {
if (acpi_dev_found(hns_dsaf_acpi_match[0].id))
dsaf_dev->dsaf_ver = AE_VERSION_1;
else if (acpi_dev_found(hns_dsaf_acpi_match[1].id))
dsaf_dev->dsaf_ver = AE_VERSION_2;
else
return -ENXIO;
} else {
dev_err(dsaf_dev->dev, "cannot get cfg data from of or acpi\n");
return -ENXIO;
}
ret = device_property_read_string(dsaf_dev->dev, "mode", &mode_str); ret = device_property_read_string(dsaf_dev->dev, "mode", &mode_str);
if (ret) { if (ret) {
...@@ -81,26 +101,33 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev) ...@@ -81,26 +101,33 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
else else
dsaf_dev->dsaf_tc_mode = HRD_DSAF_4TC_MODE; dsaf_dev->dsaf_tc_mode = HRD_DSAF_4TC_MODE;
if (dev_of_node(dsaf_dev->dev)) {
syscon = syscon_node_to_regmap( syscon = syscon_node_to_regmap(
of_parse_phandle(np, "subctrl-syscon", 0)); of_parse_phandle(np, "subctrl-syscon", 0));
if (IS_ERR_OR_NULL(syscon)) { if (IS_ERR_OR_NULL(syscon)) {
res = platform_get_resource(pdev, IORESOURCE_MEM, res_idx++); res = platform_get_resource(pdev, IORESOURCE_MEM,
res_idx++);
if (!res) { if (!res) {
dev_err(dsaf_dev->dev, "subctrl info is needed!\n"); dev_err(dsaf_dev->dev, "subctrl info is needed!\n");
return -ENOMEM; return -ENOMEM;
} }
dsaf_dev->sc_base = devm_ioremap_resource(&pdev->dev, res);
dsaf_dev->sc_base = devm_ioremap_resource(&pdev->dev,
res);
if (!dsaf_dev->sc_base) { if (!dsaf_dev->sc_base) {
dev_err(dsaf_dev->dev, "subctrl can not map!\n"); dev_err(dsaf_dev->dev, "subctrl can not map!\n");
return -ENOMEM; return -ENOMEM;
} }
res = platform_get_resource(pdev, IORESOURCE_MEM, res_idx++); res = platform_get_resource(pdev, IORESOURCE_MEM,
res_idx++);
if (!res) { if (!res) {
dev_err(dsaf_dev->dev, "serdes-ctrl info is needed!\n"); dev_err(dsaf_dev->dev, "serdes-ctrl info is needed!\n");
return -ENOMEM; return -ENOMEM;
} }
dsaf_dev->sds_base = devm_ioremap_resource(&pdev->dev, res);
dsaf_dev->sds_base = devm_ioremap_resource(&pdev->dev,
res);
if (!dsaf_dev->sds_base) { if (!dsaf_dev->sds_base) {
dev_err(dsaf_dev->dev, "serdes-ctrl can not map!\n"); dev_err(dsaf_dev->dev, "serdes-ctrl can not map!\n");
return -ENOMEM; return -ENOMEM;
...@@ -108,6 +135,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev) ...@@ -108,6 +135,7 @@ int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
} else { } else {
dsaf_dev->sub_ctrl = syscon; dsaf_dev->sub_ctrl = syscon;
} }
}
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ppe-base"); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ppe-base");
if (!res) { if (!res) {
...@@ -2686,6 +2714,7 @@ static struct platform_driver g_dsaf_driver = { ...@@ -2686,6 +2714,7 @@ static struct platform_driver g_dsaf_driver = {
.driver = { .driver = {
.name = DSAF_DRV_NAME, .name = DSAF_DRV_NAME,
.of_match_table = g_dsaf_match, .of_match_table = g_dsaf_match,
.acpi_match_table = hns_dsaf_acpi_match,
}, },
}; };
......
...@@ -362,6 +362,7 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) ...@@ -362,6 +362,7 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
if (!misc_op) if (!misc_op)
return NULL; return NULL;
if (dev_of_node(dsaf_dev->dev)) {
misc_op->cpld_set_led = hns_cpld_set_led; misc_op->cpld_set_led = hns_cpld_set_led;
misc_op->cpld_reset_led = cpld_led_reset; misc_op->cpld_reset_led = cpld_led_reset;
misc_op->cpld_set_led_id = cpld_set_led_id; misc_op->cpld_set_led_id = cpld_set_led_id;
...@@ -377,6 +378,7 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev) ...@@ -377,6 +378,7 @@ struct dsaf_misc_op *hns_misc_op_get(struct dsaf_device *dsaf_dev)
misc_op->get_sfp_prsnt = hns_mac_get_sfp_prsnt; misc_op->get_sfp_prsnt = hns_mac_get_sfp_prsnt;
misc_op->cfg_serdes_loopback = hns_mac_config_sds_loopback; misc_op->cfg_serdes_loopback = hns_mac_config_sds_loopback;
}
return (void *)misc_op; return (void *)misc_op;
} }
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