From patchwork Tue Aug 11 00:58:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 6987291 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C1A3C9F373 for ; Tue, 11 Aug 2015 00:59:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D9AEC205DD for ; Tue, 11 Aug 2015 00:59:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EB42F205D3 for ; Tue, 11 Aug 2015 00:59:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932670AbbHKA6u (ORCPT ); Mon, 10 Aug 2015 20:58:50 -0400 Received: from mail-ig0-f180.google.com ([209.85.213.180]:35296 "EHLO mail-ig0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932753AbbHKA6s (ORCPT ); Mon, 10 Aug 2015 20:58:48 -0400 Received: by igbjg10 with SMTP id jg10so12348731igb.0; Mon, 10 Aug 2015 17:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f0O6f9PLCZctncUGT+kTwd59wVf4SpuLITC+9jFjRqw=; b=kRy8Do6FsmfHJ8or57jMeLCMlNDls5RurPqCFMxSA99mVCbUtZvyEC/aMm1LMigXUb 1sq3meELuFINQBUis58cgYaUz9+z78k0oWW1kqrFFLkOf55RQEI8BJfJ3s7IXnYSq230 TUM6pAXPpW5eIU0bm32qntuBUGNV8tIQb4lWNbDH9ZJ+BfCAKlGMOyIPxXSQmITsDJzs /J4EBjtUztVJKG6R1ifHb0F481dNcjAZ+DFGsDX4YQcvE9LP2Pl5bMuTpvZNcjoZhhM6 34nVPGlxQxjyhgRaEx1npGN1cSlE/vrk1AwTjz8oW2ZLHZnZ39wJF08eO5pPwwMd0Ga5 jnvA== X-Received: by 10.50.112.166 with SMTP id ir6mr10974043igb.75.1439254728111; Mon, 10 Aug 2015 17:58:48 -0700 (PDT) Received: from dl.caveonetworks.com (64.2.3.194.ptr.us.xo.net. [64.2.3.194]) by smtp.gmail.com with ESMTPSA id 90sm415122iog.35.2015.08.10.17.58.45 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 10 Aug 2015 17:58:46 -0700 (PDT) Received: from dl.caveonetworks.com (localhost.localdomain [127.0.0.1]) by dl.caveonetworks.com (8.14.5/8.14.5) with ESMTP id t7B0wiJx002915; Mon, 10 Aug 2015 17:58:44 -0700 Received: (from ddaney@localhost) by dl.caveonetworks.com (8.14.5/8.14.5/Submit) id t7B0widf002914; Mon, 10 Aug 2015 17:58:44 -0700 From: David Daney To: netdev@vger.kernel.org, "David S. Miller" , linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org, Robert Richter , Tomasz Nowicki , Sunil Goutham , linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, Mark Rutland , rafael@kernel.org, Robert Richter , David Daney Subject: [PATCH v2 1/2] net: thunder: Factor out DT specific code in BGX Date: Mon, 10 Aug 2015 17:58:36 -0700 Message-Id: <1439254717-2875-2-git-send-email-ddaney.cavm@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1439254717-2875-1-git-send-email-ddaney.cavm@gmail.com> References: <1439254717-2875-1-git-send-email-ddaney.cavm@gmail.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Robert Richter Separate DT code in preparation for follow-on ACPI integration. Based on code from: Tomasz Nowicki Signed-off-by: Robert Richter Signed-off-by: David Daney --- drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 48 +++++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c index b961a89..615b2af 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c @@ -835,18 +835,28 @@ static void bgx_get_qlm_mode(struct bgx *bgx) } } -static void bgx_init_of(struct bgx *bgx, struct device_node *np) +#if IS_ENABLED(CONFIG_OF_MDIO) + +static int bgx_init_of_phy(struct bgx *bgx) { + struct device_node *np; struct device_node *np_child; u8 lmac = 0; + char bgx_sel[5]; + const char *mac; - for_each_child_of_node(np, np_child) { - struct device_node *phy_np; - const char *mac; + /* Get BGX node from DT */ + snprintf(bgx_sel, 5, "bgx%d", bgx->bgx_id); + np = of_find_node_by_name(NULL, bgx_sel); + if (!np) + return -ENODEV; - phy_np = of_parse_phandle(np_child, "phy-handle", 0); - if (phy_np) - bgx->lmac[lmac].phydev = of_phy_find_device(phy_np); + for_each_child_of_node(np, np_child) { + struct device_node *phy_np = of_parse_phandle(np_child, + "phy-handle", 0); + if (!phy_np) + continue; + bgx->lmac[lmac].phydev = of_phy_find_device(phy_np); mac = of_get_mac_address(np_child); if (mac) @@ -858,6 +868,21 @@ static void bgx_init_of(struct bgx *bgx, struct device_node *np) if (lmac == MAX_LMAC_PER_BGX) break; } + return 0; +} + +#else + +static int bgx_init_of_phy(struct bgx *bgx) +{ + return -ENODEV; +} + +#endif /* CONFIG_OF_MDIO */ + +static int bgx_init_phy(struct bgx *bgx) +{ + return bgx_init_of_phy(bgx); } static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) @@ -865,8 +890,6 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) int err; struct device *dev = &pdev->dev; struct bgx *bgx = NULL; - struct device_node *np; - char bgx_sel[5]; u8 lmac; bgx = devm_kzalloc(dev, sizeof(*bgx), GFP_KERNEL); @@ -902,10 +925,9 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) bgx_vnic[bgx->bgx_id] = bgx; bgx_get_qlm_mode(bgx); - snprintf(bgx_sel, 5, "bgx%d", bgx->bgx_id); - np = of_find_node_by_name(NULL, bgx_sel); - if (np) - bgx_init_of(bgx, np); + err = bgx_init_phy(bgx); + if (err) + goto err_enable; bgx_init_hw(bgx);