Received: by 10.223.164.202 with SMTP id h10csp3543486wrb; Mon, 20 Nov 2017 00:37:50 -0800 (PST) X-Google-Smtp-Source: AGs4zMYxF88Tt6xgWzXEgZ0RZXWvxi6rdzEIoedtBYATe3RzBBpIl5eaZhDgeAN4WqmbyAyodKR9 X-Received: by 10.99.114.30 with SMTP id n30mr12717783pgc.129.1511167070072; Mon, 20 Nov 2017 00:37:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511167070; cv=none; d=google.com; s=arc-20160816; b=hIs9Kbt59ZP7XLHz3K06wc6xmvvHkzQQdwfZDCuqs0H/SgJtN4zua7BXrB15Piaiqd qjxzvICrhWOACSbvnRNUjnS39NcZphOQ87SSymXTeCqEuZ4SNvaggzKelDvjDq2QZipU OkrrySXAwrUwEp+Otzrk92cQlhj7yZd4i/dIAG/jYl+Wj9v8jfSrOc/UhtOTz8oKVzN/ BMg+gQ/szY6jyC9ZqQR4rJrOqwMh05I+7CJXZSvvUx/Ywlic0R121DHnDlgbadH5xPZD lsXea+dRQMnS7BpB8wieOxQt59vv10Xo9Q1/fl9G+8neYr6atB1vmnvJWO0xpN6F1IzE 28dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=QAJdhw9lgawSX+ySjyb28yRS9xuIw2vgRjmcOOoki3Q=; b=o15BkoInlnBPBs20p9qwn/FgnoJONtTpWNmr3xTEvsoj4q6YMWeMqSz9HMMZRjaSF7 ANJHl7lflNME9w6x1cKZ/ywaDOqynIodqt+3FKFwMXuxADYxSz/DvCajm324IP/fLprf z1FOxdFmUkj84n2PuoxcpQdNUhWR6uxdoMaxxKOU6p4y9t7IYz/uClN2Ap24tY3QP2tL 5vUXWMOiWYqLkzo63lOEXt269m5C3JvhsrQcG9geQZuobN2jAWv6vsWQrE8O/Yy36b8s T0mAYT2nTlqMGZeuRexWnCk04WDIeQn8kmnKxuW1lEfKXn+UQZ8V/BWV+ay+jygiMyPn QKQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14si7950749plk.776.2017.11.20.00.37.40; Mon, 20 Nov 2017 00:37:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751289AbdKTIgn (ORCPT + 68 others); Mon, 20 Nov 2017 03:36:43 -0500 Received: from relay04.alfahosting-server.de ([109.237.142.240]:2742 "EHLO relay04.alfahosting-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750974AbdKTIff (ORCPT ); Mon, 20 Nov 2017 03:35:35 -0500 Received: by relay01.alfahosting-server.de (Postfix, from userid 1001) id A4EA932C2312; Mon, 20 Nov 2017 09:35:33 +0100 (CET) X-Spam-DCC: : X-Spam-Level: X-Spam-Status: No, score=-999.0 required=7.0 tests=BAYES_60,D_SENT_WITH_SASL autolearn=disabled version=3.2.5 Received: from alfa3028.alfahosting-server.de (alfa3028.alfahosting-server.de [109.237.138.38]) by relay01.alfahosting-server.de (Postfix) with ESMTPS id E17E932C31F5; Mon, 20 Nov 2017 09:35:31 +0100 (CET) Received: from localhost.localdomain (unknown [91.230.2.244]) (Authenticated sender: yes) by alfa3028.alfahosting-server.de (Postfix) with ESMTPA id A7DEC430D437; Mon, 20 Nov 2017 09:35:31 +0100 (CET) From: Richard Leitner To: f.fainelli@gmail.com, fugang.duan@nxp.com, andrew@lunn.ch Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, richard.leitner@skidata.com Subject: [PATCH v2 1/3] net: ethernet: freescale: simplify fec_reset_phy Date: Mon, 20 Nov 2017 09:34:15 +0100 Message-Id: <20171120083417.32558-2-dev@g0hl1n.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171120083417.32558-1-dev@g0hl1n.net> References: <20171120083417.32558-1-dev@g0hl1n.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Leitner The fec_reset_phy function allowed only one execution during probeing. To make it more usable move the dt parsing and gpio allocation to the probe function. The parameters of the phy reset are added to the fec_enet_private struct. As a result the fec_reset_phy function may be called anytime after probe. One checkpatch.pl warning (too long line) is ignored. This is due to the fact a string (dt property name) otherwise needs to be split over multiple lines, which is counterproductive for the readability. Signed-off-by: Richard Leitner --- drivers/net/ethernet/freescale/fec.h | 4 ++ drivers/net/ethernet/freescale/fec_main.c | 88 ++++++++++++++++--------------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 5385074b3b7d..401c4eabf08a 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -539,6 +539,10 @@ struct fec_enet_private { int pause_flag; int wol_flag; u32 quirks; + int phy_reset; + int phy_reset_duration; + int phy_reset_post_delay; + bool phy_reset_active_high; struct napi_struct napi; int csum_flags; diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 610573855213..06a7caca0cee 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3212,62 +3212,36 @@ static int fec_enet_init(struct net_device *ndev) } #ifdef CONFIG_OF -static int fec_reset_phy(struct platform_device *pdev) +static int fec_reset_phy(struct net_device *ndev) { - int err, phy_reset; - bool active_high = false; - int msec = 1, phy_post_delay = 0; - struct device_node *np = pdev->dev.of_node; - - if (!np) - return 0; - - err = of_property_read_u32(np, "phy-reset-duration", &msec); - /* A sane reset duration should not be longer than 1s */ - if (!err && msec > 1000) - msec = 1; + struct fec_enet_private *fep = netdev_priv(ndev); - phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0); - if (phy_reset == -EPROBE_DEFER) - return phy_reset; - else if (!gpio_is_valid(phy_reset)) + if (!fep->phy_reset) return 0; - err = of_property_read_u32(np, "phy-reset-post-delay", &phy_post_delay); - /* valid reset duration should be less than 1s */ - if (!err && phy_post_delay > 1000) - return -EINVAL; - - active_high = of_property_read_bool(np, "phy-reset-active-high"); + gpio_set_value_cansleep(fep->phy_reset, fep->phy_reset_active_high); - err = devm_gpio_request_one(&pdev->dev, phy_reset, - active_high ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW, - "phy-reset"); - if (err) { - dev_err(&pdev->dev, "failed to get phy-reset-gpios: %d\n", err); - return err; - } - - if (msec > 20) - msleep(msec); + if (fep->phy_reset_duration > 20) + msleep(fep->phy_reset_duration); else - usleep_range(msec * 1000, msec * 1000 + 1000); + usleep_range(fep->phy_reset_duration * 1000, + fep->phy_reset_duration * 1000 + 1000); - gpio_set_value_cansleep(phy_reset, !active_high); + gpio_set_value_cansleep(fep->phy_reset, !fep->phy_reset_active_high); - if (!phy_post_delay) + if (!fep->phy_reset_post_delay) return 0; - if (phy_post_delay > 20) - msleep(phy_post_delay); + if (fep->phy_reset_post_delay > 20) + msleep(fep->phy_reset_post_delay); else - usleep_range(phy_post_delay * 1000, - phy_post_delay * 1000 + 1000); + usleep_range(fep->phy_reset_post_delay * 1000, + fep->phy_reset_post_delay * 1000 + 1000); return 0; } #else /* CONFIG_OF */ -static int fec_reset_phy(struct platform_device *pdev) +static int fec_reset_phy(struct net_device *ndev) { /* * In case of platform probe, the reset has been done @@ -3400,6 +3374,36 @@ fec_probe(struct platform_device *pdev) } fep->phy_node = phy_node; + fep->phy_reset = of_get_named_gpio(np, "phy-reset-gpios", 0); + if (gpio_is_valid(fep->phy_reset)) { + ret = of_property_read_u32(np, "phy-reset-duration", + &fep->phy_reset_duration); + /* A sane reset duration should not be longer than 1s */ + if (!ret && fep->phy_reset_post_delay > 1000) + fep->phy_reset_post_delay = 1; + + ret = of_property_read_u32(np, "phy-reset-post-delay", + &fep->phy_reset_post_delay); + /* valid post reset delay should be less than 1s */ + if (!ret && fep->phy_reset_post_delay > 1000) + fep->phy_reset_post_delay = 1; + + fep->phy_reset_active_high = of_property_read_bool(np, "phy-reset-active-high"); + + ret = devm_gpio_request_one(&pdev->dev, fep->phy_reset, + fep->phy_reset_active_high ? + GPIOF_OUT_INIT_HIGH : + GPIOF_OUT_INIT_LOW, + "phy-reset"); + if (ret) { + dev_err(&pdev->dev, "failed to get reset-gpios: %d\n", + ret); + goto failed_phy; + } + } else { + fep->phy_reset = 0; + } + ret = of_get_phy_mode(pdev->dev.of_node); if (ret < 0) { pdata = dev_get_platdata(&pdev->dev); @@ -3472,7 +3476,7 @@ fec_probe(struct platform_device *pdev) pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); - ret = fec_reset_phy(pdev); + ret = fec_reset_phy(ndev); if (ret) goto failed_reset; -- 2.11.0 From 1584392568612824629@xxx Sat Nov 18 08:41:39 +0000 2017 X-GM-THRID: 1584392568612824629 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread