From patchwork Sun Dec 31 11:58:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Wojtas X-Patchwork-Id: 10138107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 233C360362 for ; Sun, 31 Dec 2017 12:11:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0059227EE2 for ; Sun, 31 Dec 2017 12:11:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E90B528581; Sun, 31 Dec 2017 12:11:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 406D327EE2 for ; Sun, 31 Dec 2017 12:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=6wocvOiC1prjX1nCji2zGhoZCQ3OyM3Y2Gx1Wa+deTk=; b=EQN1cmmTPiCEeGPiXefWoOe8vq V256jdzGITu/VniQ3mKxvRV+j7vvpDgIrr/KWiMz9vEIxNPpS2xmAK7yROeiAE5vjAdZZ19bR75zu xcWQZ8Z/G5T/v0Xnha2dlYOaVUq782qxAE+4USjhim+7AyEbwz7yV1iIs4jK28W4fGeSAvzhNRCgv 0qL75DmpQCW4X85Sd758BoHvl7uov4j/dDoNiQVDo7qfrRhjMqriff5zGaL/2C9cFDYL0p1FIj/qS jjRiuU/+sMouqZE/daJBPbaXyIpGL01/J6Ga7D0mMtIruGftieTSlvNM+QuHsA8h4M7PuSRziCOAH URb84MsA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eVcSx-0007gA-Bx; Sun, 31 Dec 2017 12:11:47 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eVcGj-0007r6-JD for linux-arm-kernel@lists.infradead.org; Sun, 31 Dec 2017 11:59:12 +0000 Received: by mail-lf0-x241.google.com with SMTP id h137so7661547lfe.8 for ; Sun, 31 Dec 2017 03:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bqd7nzH4/Tt5heQYNjT+tplFLLUS1UbUGRpcfs0es4k=; b=tCm2hlwcU69FIQnaPK67K7ljfleRDk94OtY09iSA2qWoReaVP3w1oOMO9QsyTMMFaY KfTMM9n0D02aDkyk2UwqvH+Ma1CKIeol+jh7K2ZIz206SORopwCR1dfFQlgBpgDMaY0u 3rHrhUPp58CecL1zyN4IXGGfeRj/GqsxoidMG9R54B4oAKBXw5UHPLJVdgmkx8IhDmc6 /YWrSFP/7BkjdyUWV7vUGIm5vYp2IbtoBy6aIHBHIfUeUaAYJPIkIeWtUUBpVXs6cuaL +md4yw8MTmuVY8LttiK0DLZDA2ESmrocNDh3ezl4sXzkKbDi91GHTdZG+59dj5RssUNj iKqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Bqd7nzH4/Tt5heQYNjT+tplFLLUS1UbUGRpcfs0es4k=; b=ZhePbcZkG5GVasfCEaowKNaTriw5ZXxxApnePS48XlO505A2cl9Y7IHKpH3rzR1g3X OTOqFcL2f2fcZcd/gNIXXXlhi7q1R2akRQGK7WpvROlc/Ocj30vcxa9acc2WGM+krkin 2qJ56M2zNMVygYNHDq6vJt2DLpiiWbkWBH4glTLBdwIv/JfEk0pw2eRsxrAHwUSPn6zI vi+JvayoVDwqI0QvSgWmYLJlqXbt67+xMMWqQatVuAU2EiVdeYr3bemqFkW37F9UoU1u 3kRh/jdfYNTG9dGWFLyeW40N4PTGzod6uQ/yA1EhOWnM79fQ9FNIAmq320IDm12xLGsp AjOA== X-Gm-Message-State: AKGB3mK5m1ECFQKdFDIMajIpMlJ+4hhfDiPkalkPnkzbI+1fUm57zlp1 1j1EPeRjKq4YF2cUlqOoZ7yzJA== X-Google-Smtp-Source: ACJfBotBLKhe9M6ScI6nPs4EG2VZOWyq6l/x594KvsVtGDvoED03JWAig4TvXmT8VHBHX64KpMzhWw== X-Received: by 10.25.115.194 with SMTP id h63mr20847698lfk.79.1514721537293; Sun, 31 Dec 2017 03:58:57 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id f10sm8646298lff.56.2017.12.31.03.58.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 31 Dec 2017 03:58:56 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [net-next: PATCH v2 4/5] net: mvpp2: use device_*/fwnode_* APIs instead of of_* Date: Sun, 31 Dec 2017 12:58:39 +0100 Message-Id: <1514721520-18964-5-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514721520-18964-1-git-send-email-mw@semihalf.com> References: <1514721520-18964-1-git-send-email-mw@semihalf.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171231_035909_844402_17C16229 X-CRM114-Status: GOOD ( 17.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thomas.petazzoni@free-electrons.com, andrew@lunn.ch, f.fainelli@gmail.com, graeme.gregory@linaro.org, ard.biesheuvel@linaro.org, jaz@semihalf.com, antoine.tenart@free-electrons.com, rafael.j.wysocki@intel.com, linux@armlinux.org.uk, nadavh@marvell.com, neta@marvell.com, ezequiel.garcia@free-electrons.com, tn@semihalf.com, gregory.clement@free-electrons.com, mw@semihalf.com, davem@davemloft.net MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP OF functions can be used only for the driver using DT. As a preparation for introducing ACPI support in mvpp2 driver, use struct fwnode_handle in order to obtain properties from the hardware description. Because there is no equivalent for for_each_available_child_of_node(), use device_for_each_child_node() and check the port availability inside the mvpp2_port_probe() routine. This patch replaces of_* function with device_*/fwnode_* where possible in the mvpp2. Signed-off-by: Marcin Wojtas --- drivers/net/ethernet/marvell/mvpp2.c | 47 +++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c index 7f42d90..537474f 100644 --- a/drivers/net/ethernet/marvell/mvpp2.c +++ b/drivers/net/ethernet/marvell/mvpp2.c @@ -932,6 +932,9 @@ struct mvpp2_port { struct mvpp2 *priv; + /* Firmware node associated to the port */ + struct fwnode_handle *fwnode; + /* Per-port registers' base address */ void __iomem *base; void __iomem *stats_base; @@ -7711,17 +7714,16 @@ static bool mvpp2_port_has_tx_irqs(struct mvpp2 *priv, } static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, - struct device_node *port_node, + struct fwnode_handle *fwnode, char **mac_from) { struct mvpp2_port *port = netdev_priv(dev); char hw_mac_addr[ETH_ALEN] = {0}; - const char *dt_mac_addr; + char fw_mac_addr[ETH_ALEN]; - dt_mac_addr = of_get_mac_address(port_node); - if (dt_mac_addr && is_valid_ether_addr(dt_mac_addr)) { - *mac_from = "device tree"; - ether_addr_copy(dev->dev_addr, dt_mac_addr); + if (fwnode_get_mac_address(fwnode, fw_mac_addr, ETH_ALEN)) { + *mac_from = "firmware node"; + ether_addr_copy(dev->dev_addr, fw_mac_addr); return; } @@ -7740,13 +7742,14 @@ static void mvpp2_port_copy_mac_addr(struct net_device *dev, struct mvpp2 *priv, /* Ports initialization */ static int mvpp2_port_probe(struct platform_device *pdev, - struct device_node *port_node, + struct fwnode_handle *port_fwnode, struct mvpp2 *priv) { struct device_node *phy_node; struct phy *comphy; struct mvpp2_port *port; struct mvpp2_port_pcpu *port_pcpu; + struct device_node *port_node = to_of_node(port_fwnode); struct net_device *dev; struct resource *res; char *mac_from = ""; @@ -7757,6 +7760,10 @@ static int mvpp2_port_probe(struct platform_device *pdev, int phy_mode; int err, i, cpu; + /* Silently exit, if the port node turns out to be disabled. */ + if (!fwnode_device_is_available(port_fwnode)) + return 0; + has_tx_irqs = mvpp2_port_has_tx_irqs(priv, port_node); if (!has_tx_irqs) @@ -7773,7 +7780,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, return -ENOMEM; phy_node = of_parse_phandle(port_node, "phy", 0); - phy_mode = of_get_phy_mode(port_node); + phy_mode = fwnode_get_phy_mode(port_fwnode); if (phy_mode < 0) { dev_err(&pdev->dev, "incorrect phy mode\n"); err = phy_mode; @@ -7789,7 +7796,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, comphy = NULL; } - if (of_property_read_u32(port_node, "port-id", &id)) { + if (fwnode_property_read_u32(port_fwnode, "port-id", &id)) { err = -EINVAL; dev_err(&pdev->dev, "missing port-id value\n"); goto err_free_netdev; @@ -7820,7 +7827,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, /* the link irq is optional */ port->link_irq = 0; - if (of_property_read_bool(port_node, "marvell,loopback")) + if (fwnode_property_read_bool(port_fwnode, "marvell,loopback")) port->flags |= MVPP2_F_LOOPBACK; port->id = id; @@ -7845,8 +7852,8 @@ static int mvpp2_port_probe(struct platform_device *pdev, MVPP21_MIB_COUNTERS_OFFSET + port->gop_id * MVPP21_MIB_COUNTERS_PORT_SZ; } else { - if (of_property_read_u32(port_node, "gop-port-id", - &port->gop_id)) { + if (fwnode_property_read_u32(port_fwnode, "gop-port-id", + &port->gop_id)) { err = -EINVAL; dev_err(&pdev->dev, "missing gop-port-id value\n"); goto err_deinit_qvecs; @@ -7876,7 +7883,7 @@ static int mvpp2_port_probe(struct platform_device *pdev, mutex_init(&port->gather_stats_lock); INIT_DELAYED_WORK(&port->stats_work, mvpp2_gather_hw_statistics); - mvpp2_port_copy_mac_addr(dev, priv, port_node, &mac_from); + mvpp2_port_copy_mac_addr(dev, priv, port_fwnode, &mac_from); port->tx_ring_size = MVPP2_MAX_TXD_DFLT; port->rx_ring_size = MVPP2_MAX_RXD_DFLT; @@ -8194,8 +8201,7 @@ static int mvpp2_init(struct platform_device *pdev, struct mvpp2 *priv) static int mvpp2_probe(struct platform_device *pdev) { - struct device_node *dn = pdev->dev.of_node; - struct device_node *port_node; + struct fwnode_handle *port_fwnode; struct mvpp2 *priv; struct resource *res; void __iomem *base; @@ -8315,8 +8321,8 @@ static int mvpp2_probe(struct platform_device *pdev) } /* Initialize ports */ - for_each_available_child_of_node(dn, port_node) { - err = mvpp2_port_probe(pdev, port_node, priv); + device_for_each_child_node(&pdev->dev, port_fwnode) { + err = mvpp2_port_probe(pdev, port_fwnode, priv); if (err < 0) goto err_port_probe; } @@ -8347,7 +8353,7 @@ static int mvpp2_probe(struct platform_device *pdev) err_port_probe: i = 0; - for_each_available_child_of_node(dn, port_node) { + device_for_each_child_node(&pdev->dev, port_fwnode) { if (priv->port_list[i]) mvpp2_port_remove(priv->port_list[i]); i++; @@ -8366,14 +8372,13 @@ static int mvpp2_probe(struct platform_device *pdev) static int mvpp2_remove(struct platform_device *pdev) { struct mvpp2 *priv = platform_get_drvdata(pdev); - struct device_node *dn = pdev->dev.of_node; - struct device_node *port_node; + struct fwnode_handle *port_fwnode; int i = 0; flush_workqueue(priv->stats_queue); destroy_workqueue(priv->stats_queue); - for_each_available_child_of_node(dn, port_node) { + device_for_each_child_node(&pdev->dev, port_fwnode) { if (priv->port_list[i]) { mutex_destroy(&priv->port_list[i]->gather_stats_lock); mvpp2_port_remove(priv->port_list[i]);