Commit 5f3d3807 authored by Timur Tabi's avatar Timur Tabi Committed by David S. Miller

net: qcom/emac: initial ACPI support

Add support for reading addresses, interrupts, and _DSD properties
from ACPI tables, just like with device tree.  The HID for the
EMAC device itself is QCOM8070.  The internal PHY is represented
by a child node with a HID of QCOM8071.

The EMAC also has some complex clock initialization requirements
that are not represented by this patch.  This will be addressed
in a future patch.
Signed-off-by: default avatarTimur Tabi <timur@codeaurora.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0de709ac
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/iopoll.h> #include <linux/iopoll.h>
#include <linux/acpi.h>
#include "emac.h" #include "emac.h"
#include "emac-mac.h" #include "emac-mac.h"
#include "emac-phy.h" #include "emac-phy.h"
...@@ -167,7 +168,6 @@ static int emac_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val) ...@@ -167,7 +168,6 @@ static int emac_mdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)
{ {
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct device_node *phy_np;
struct mii_bus *mii_bus; struct mii_bus *mii_bus;
int ret; int ret;
...@@ -183,6 +183,27 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) ...@@ -183,6 +183,27 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)
mii_bus->parent = &pdev->dev; mii_bus->parent = &pdev->dev;
mii_bus->priv = adpt; mii_bus->priv = adpt;
if (has_acpi_companion(&pdev->dev)) {
u32 phy_addr;
ret = mdiobus_register(mii_bus);
if (ret) {
dev_err(&pdev->dev, "could not register mdio bus\n");
return ret;
}
ret = device_property_read_u32(&pdev->dev, "phy-channel",
&phy_addr);
if (ret)
/* If we can't read a valid phy address, then assume
* that there is only one phy on this mdio bus.
*/
adpt->phydev = phy_find_first(mii_bus);
else
adpt->phydev = mdiobus_get_phy(mii_bus, phy_addr);
} else {
struct device_node *phy_np;
ret = of_mdiobus_register(mii_bus, np); ret = of_mdiobus_register(mii_bus, np);
if (ret) { if (ret) {
dev_err(&pdev->dev, "could not register mdio bus\n"); dev_err(&pdev->dev, "could not register mdio bus\n");
...@@ -191,6 +212,8 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt) ...@@ -191,6 +212,8 @@ int emac_phy_config(struct platform_device *pdev, struct emac_adapter *adpt)
phy_np = of_parse_phandle(np, "phy-handle", 0); phy_np = of_parse_phandle(np, "phy-handle", 0);
adpt->phydev = of_phy_find_device(phy_np); adpt->phydev = of_phy_find_device(phy_np);
}
if (!adpt->phydev) { if (!adpt->phydev) {
dev_err(&pdev->dev, "could not find external phy\n"); dev_err(&pdev->dev, "could not find external phy\n");
mdiobus_unregister(mii_bus); mdiobus_unregister(mii_bus);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include <linux/iopoll.h> #include <linux/iopoll.h>
#include <linux/acpi.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include "emac.h" #include "emac.h"
#include "emac-mac.h" #include "emac-mac.h"
...@@ -662,6 +663,24 @@ void emac_sgmii_reset(struct emac_adapter *adpt) ...@@ -662,6 +663,24 @@ void emac_sgmii_reset(struct emac_adapter *adpt)
clk_set_rate(adpt->clk[EMAC_CLK_HIGH_SPEED], 125000000); clk_set_rate(adpt->clk[EMAC_CLK_HIGH_SPEED], 125000000);
} }
static int emac_sgmii_acpi_match(struct device *dev, void *data)
{
static const struct acpi_device_id match_table[] = {
{
.id = "QCOM8071",
.driver_data = (kernel_ulong_t)emac_sgmii_init_v2,
},
{}
};
const struct acpi_device_id *id = acpi_match_device(match_table, dev);
emac_sgmii_initialize *initialize = data;
if (id)
*initialize = (emac_sgmii_initialize)id->driver_data;
return !!id;
}
static const struct of_device_id emac_sgmii_dt_match[] = { static const struct of_device_id emac_sgmii_dt_match[] = {
{ {
.compatible = "qcom,fsm9900-emac-sgmii", .compatible = "qcom,fsm9900-emac-sgmii",
...@@ -679,9 +698,23 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) ...@@ -679,9 +698,23 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt)
struct platform_device *sgmii_pdev = NULL; struct platform_device *sgmii_pdev = NULL;
struct emac_phy *phy = &adpt->phy; struct emac_phy *phy = &adpt->phy;
struct resource *res; struct resource *res;
int ret;
if (has_acpi_companion(&pdev->dev)) {
struct device *dev;
dev = device_find_child(&pdev->dev, &phy->initialize,
emac_sgmii_acpi_match);
if (!dev) {
dev_err(&pdev->dev, "cannot find internal phy node\n");
return -ENODEV;
}
sgmii_pdev = to_platform_device(dev);
} else {
const struct of_device_id *match; const struct of_device_id *match;
struct device_node *np; struct device_node *np;
int ret;
np = of_parse_phandle(pdev->dev.of_node, "internal-phy", 0); np = of_parse_phandle(pdev->dev.of_node, "internal-phy", 0);
if (!np) { if (!np) {
...@@ -703,6 +736,7 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt) ...@@ -703,6 +736,7 @@ int emac_sgmii_config(struct platform_device *pdev, struct emac_adapter *adpt)
} }
phy->initialize = (emac_sgmii_initialize)match->data; phy->initialize = (emac_sgmii_initialize)match->data;
}
/* Base address is the first address */ /* Base address is the first address */
res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 0); res = platform_get_resource(sgmii_pdev, IORESOURCE_MEM, 0);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/acpi.h>
#include "emac.h" #include "emac.h"
#include "emac-mac.h" #include "emac-mac.h"
#include "emac-phy.h" #include "emac-phy.h"
...@@ -575,6 +576,16 @@ static const struct of_device_id emac_dt_match[] = { ...@@ -575,6 +576,16 @@ static const struct of_device_id emac_dt_match[] = {
{} {}
}; };
#if IS_ENABLED(CONFIG_ACPI)
static const struct acpi_device_id emac_acpi_match[] = {
{
.id = "QCOM8070",
},
{}
};
MODULE_DEVICE_TABLE(acpi, emac_acpi_match);
#endif
static int emac_probe(struct platform_device *pdev) static int emac_probe(struct platform_device *pdev)
{ {
struct net_device *netdev; struct net_device *netdev;
...@@ -734,6 +745,7 @@ static struct platform_driver emac_platform_driver = { ...@@ -734,6 +745,7 @@ static struct platform_driver emac_platform_driver = {
.driver = { .driver = {
.name = "qcom-emac", .name = "qcom-emac",
.of_match_table = emac_dt_match, .of_match_table = emac_dt_match,
.acpi_match_table = ACPI_PTR(emac_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