diff mbox series

[v2] net:macb: driver support acpi mode

Message ID 20221114114126.1881-1-xiaowu.ding@jaguarmicro.com (mailing list archive)
State Not Applicable
Headers show
Series [v2] net:macb: driver support acpi mode | expand

Checks

Context Check Description
conchuod/tree_selection fail Guessing tree name failed

Commit Message

xiaowu.ding Nov. 14, 2022, 11:41 a.m. UTC
From: Xiaowu Ding <xiaowu.ding@jaguarmicro.com>

Cadence gem driver suuport acpi mode. Current the macb driver
just support device tree mode.So we add new acpi mode code with
this driver.

Signed-off-by: Xiaowu Ding <xiaowu.ding@jaguarmicro.com>
---
V1 -> V2: Add the fixed "pclk" and "hclk" clock within the acpi platform 
          device create.And delete the clock related modify code within the patch V1.
---

 drivers/net/ethernet/cadence/macb_main.c | 118 +++++++++++++++++++----
 1 file changed, 100 insertions(+), 18 deletions(-)

Comments

Jakub Kicinski Nov. 16, 2022, 5:15 p.m. UTC | #1
On Mon, 14 Nov 2022 19:41:26 +0800 xiaowu.ding wrote:
> From: Xiaowu Ding <xiaowu.ding@jaguarmicro.com>
> 
> Cadence gem driver suuport acpi mode. Current the macb driver
> just support device tree mode.So we add new acpi mode code with
> this driver.

Does not apply cleanly. Rebase on top of net-next and put 
[PATCH net-next v3] in the subject, please.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index aa1b03f8bfe9..c98a8b64f9c1 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -38,6 +38,8 @@ 
 #include <linux/pm_runtime.h>
 #include <linux/ptp_classify.h>
 #include <linux/reset.h>
+#include <linux/acpi.h>
+#include <linux/acpi_mdio.h>
 #include "macb.h"
 
 /* This structure is only used for MACB on SiFive FU540 devices */
@@ -748,24 +750,26 @@  static const struct phylink_mac_ops macb_phylink_ops = {
 	.mac_link_up = macb_mac_link_up,
 };
 
-static bool macb_phy_handle_exists(struct device_node *dn)
+static bool macb_phy_handle_exists(struct fwnode_handle *fwnode)
 {
-	dn = of_parse_phandle(dn, "phy-handle", 0);
-	of_node_put(dn);
-	return dn != NULL;
+	struct fwnode_handle *phy_node;
+
+	phy_node = fwnode_find_reference(fwnode, "phy-handle", 0);
+	fwnode_handle_put(phy_node);
+	return !IS_ERR(phy_node);
 }
 
 static int macb_phylink_connect(struct macb *bp)
 {
-	struct device_node *dn = bp->pdev->dev.of_node;
+	struct fwnode_handle *fwnode = bp->pdev->dev.fwnode;
 	struct net_device *dev = bp->dev;
 	struct phy_device *phydev;
 	int ret;
 
-	if (dn)
-		ret = phylink_of_phy_connect(bp->phylink, dn, 0);
-
-	if (!dn || (ret && !macb_phy_handle_exists(dn))) {
+	if (fwnode)
+		ret = phylink_fwnode_phy_connect(bp->phylink, fwnode, 0);
+	 /* historical device tree code so keep no change */
+	if (!fwnode || (ret && !macb_phy_handle_exists(fwnode))) {
 		phydev = phy_find_first(bp->mii_bus);
 		if (!phydev) {
 			netdev_err(dev, "no PHY found\n");
@@ -852,7 +856,7 @@  static int macb_mii_probe(struct net_device *dev)
 	return 0;
 }
 
-static int macb_mdiobus_register(struct macb *bp)
+static int macb_of_mdiobus_register(struct macb *bp)
 {
 	struct device_node *child, *np = bp->pdev->dev.of_node;
 
@@ -888,6 +892,36 @@  static int macb_mdiobus_register(struct macb *bp)
 	return mdiobus_register(bp->mii_bus);
 }
 
+static int macb_acpi_mdiobus_register(struct macb *bp)
+{
+	struct platform_device *pdev = bp->pdev;
+	struct fwnode_handle *fwnode = pdev->dev.fwnode;
+	struct fwnode_handle *child;
+	u32 addr;
+	int ret;
+
+	if (!IS_ERR_OR_NULL(fwnode_find_reference(fwnode, "fixed-link", 0)))
+		return mdiobus_register(bp->mii_bus);
+	fwnode_for_each_child_node(fwnode, child) {
+		ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr);
+		if (ret)
+			continue;
+
+		ret = acpi_mdiobus_register(bp->mii_bus, fwnode);
+	}
+
+	return mdiobus_register(bp->mii_bus);
+}
+
+static int macb_mdiobus_register(struct macb *bp)
+{
+	/* macb of device tree mode register mdio bus */
+	if (likely(is_of_node(bp->pdev->dev.fwnode)))
+		return macb_of_mdiobus_register(bp);
+	/* macb acpi mode register mdio bus */
+	return macb_acpi_mdiobus_register(bp);
+}
+
 static int macb_mii_init(struct macb *bp)
 {
 	int err = -ENXIO;
@@ -4812,6 +4846,42 @@  static const struct of_device_id macb_dt_ids[] = {
 MODULE_DEVICE_TABLE(of, macb_dt_ids);
 #endif /* CONFIG_OF */
 
+#ifdef CONFIG_ACPI
+
+static const struct macb_config jmnd_gem_rgmii_config = {
+	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE | MACB_CAPS_SG_DISABLED |
+	    MACB_CAPS_JUMBO,
+	.dma_burst_length = 16,
+	.clk_init = macb_clk_init,
+	.init = macb_init,
+	.jumbo_max_len = 10240,
+	.usrio = &macb_default_usrio
+};
+
+static const struct macb_config jmnd_gem_rmii_config = {
+	.caps = MACB_CAPS_SG_DISABLED | MACB_CAPS_JUMBO,
+	.dma_burst_length = 16,
+	.clk_init = macb_clk_init,
+	.init = macb_init,
+	.jumbo_max_len = 10240,
+	.usrio = &macb_default_usrio,
+};
+
+static const struct acpi_device_id macb_acpi_ids[] = {
+	{
+	 .id = "JAMC00B0",
+	 .driver_data = (kernel_ulong_t)&jmnd_gem_rgmii_config},
+	{
+	 .id = "JAMC00BA",
+	 .driver_data = (kernel_ulong_t)&jmnd_gem_rmii_config},
+	{
+	 },
+};
+
+MODULE_DEVICE_TABLE(acpi, macb_acpi_ids);
+
+#endif
+
 static const struct macb_config default_gem_config = {
 	.caps = MACB_CAPS_GIGABIT_MODE_AVAILABLE |
 		MACB_CAPS_JUMBO |
@@ -4855,6 +4925,17 @@  static int macb_probe(struct platform_device *pdev)
 			clk_init = macb_config->clk_init;
 			init = macb_config->init;
 		}
+	} else {   /*add gem support acpi */
+		const struct acpi_device_id *match;
+
+		match =
+		    acpi_match_device(pdev->dev.driver->acpi_match_table,
+				      &pdev->dev);
+		if (match && match->driver_data) {
+			macb_config = (struct macb_config *)match->driver_data;
+			clk_init = macb_config->clk_init;
+			init = macb_config->init;
+		}
 	}
 
 	err = clk_init(pdev, &pclk, &hclk, &tx_clk, &rx_clk, &tsu_clk);
@@ -4904,7 +4985,7 @@  static int macb_probe(struct platform_device *pdev)
 		bp->jumbo_max_len = macb_config->jumbo_max_len;
 
 	bp->wol = 0;
-	if (of_get_property(np, "magic-packet", NULL))
+	if (device_property_present(&pdev->dev, "magic-packet"))
 		bp->wol |= MACB_WOL_HAS_MAGIC_PACKET;
 	device_set_wakeup_capable(&pdev->dev, bp->wol & MACB_WOL_HAS_MAGIC_PACKET);
 
@@ -4952,15 +5033,13 @@  static int macb_probe(struct platform_device *pdev)
 	if (bp->caps & MACB_CAPS_NEEDS_RSTONUBR)
 		bp->rx_intr_mask |= MACB_BIT(RXUBR);
 
-	err = of_get_ethdev_address(np, bp->dev);
-	if (err == -EPROBE_DEFER)
-		goto err_out_free_netdev;
-	else if (err)
+	if (device_get_ethdev_address(&pdev->dev, dev))
 		macb_get_hwaddr(bp);
 
-	err = of_get_phy_mode(np, &interface);
-	if (err)
-		/* not found in DT, MII by default */
+	/*add gem support acpi */
+	interface = device_get_phy_mode(&pdev->dev);
+	if (interface < 0)
+		/* not found in DT and ACPI , MII by default */
 		bp->phy_interface = PHY_INTERFACE_MODE_MII;
 	else
 		bp->phy_interface = interface;
@@ -5255,6 +5334,9 @@  static struct platform_driver macb_driver = {
 	.driver		= {
 		.name		= "macb",
 		.of_match_table	= of_match_ptr(macb_dt_ids),
+#ifdef CONFIG_ACPI
+		.acpi_match_table = ACPI_PTR(macb_acpi_ids),
+#endif
 		.pm	= &macb_pm_ops,
 	},
 };