From patchwork Mon Nov 28 18:24:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 9449905 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 2516C6071C for ; Mon, 28 Nov 2016 18:28:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B22827F9C for ; Mon, 28 Nov 2016 18:28:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE5E27FB6; Mon, 28 Nov 2016 18:28:19 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BD6A227F9C for ; Mon, 28 Nov 2016 18:28:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cBQf4-0001c6-1X; Mon, 28 Nov 2016 18:28:18 +0000 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cBQea-00013U-95 for linux-mediatek@lists.infradead.org; Mon, 28 Nov 2016 18:27:54 +0000 Received: by mail-lf0-x243.google.com with SMTP id p100so10340523lfg.2 for ; Mon, 28 Nov 2016 10:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=rDTMG6umJxvG4oAUy3twHW2pHT/YFg1VDRr/BI1MNvE=; b=m+ewYG1YJMUeDGawCsyc51GyDR2TeRlYKfoJYaT/FojDhm3eX0JQUxE1y4hhSsG9e3 5udspZLvYMH75aRV0AxCMaFY9w6hwBPoBtb8oseHd4wV58Uce4znyJnljZVZoCl+/ytv IfZPr4ejkIW2bIiMZETaQn3PcM90MoANu6chbV5qIj6gFajm+Nu9uJ/o05xJwoSE7GU/ +PmNRKOtO4A6Xw4+BUmSH/l72z1DX3hhnQXWzhioZowfdE21EqDtkdBp0XHVh/h6cO19 xMZc1w79wa8C7yPAFssKJoPdibW+hM3/0DqyDg0vrMPDHPdGUNc6w2sOV0tj9AxcYE79 r+tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=rDTMG6umJxvG4oAUy3twHW2pHT/YFg1VDRr/BI1MNvE=; b=DyU0x+zXlk+gRk/jTcuN6/wTeQiUICK4MXlDWsB7JDCX4w0+5A9qGS31yDSQ39L2Gq 3W7llMcw/oRov05ZwbymutwYJ/czy+cKujCGSdbAX+nO2K8qm8ZQDugg4HU1YEA4Eg4D 7Q5sRX5enVwPwpQE0ExxQBYQrch874bin6MbGXhUeSo/gB0Kr7N2xvvAPBE5EXldaYoB 3KQLYYIdhQNZnKRXPGX7QMxk/k3oUdTU6WjdBXTptbF3CA2WwDYPFrBWAyN6kVmRHbAC IULJvgTzZWo5qynnhRvZYcNV5kA/A3LiN8saaz0WfkGggddCELM+AGiDQxCqOafQT4St IJRg== X-Gm-Message-State: AKaTC03X1rMq57TxZxHWpKek+1P0UlZIDwW05P9Jv1504YtcXwgLcf1mXW8sk331Z7yU9w== X-Received: by 10.46.69.6 with SMTP id s6mr10541662lja.42.1480357646864; Mon, 28 Nov 2016 10:27:26 -0800 (PST) Received: from xi.terra (c-04aadb54.07-184-6d6c6d4.cust.bredbandsbolaget.se. [84.219.170.4]) by smtp.gmail.com with ESMTPSA id s63sm13105665lja.19.2016.11.28.10.27.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Nov 2016 10:27:25 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.87) (envelope-from ) id 1cBQeA-0007K5-0g; Mon, 28 Nov 2016 19:27:22 +0100 From: Johan Hovold To: "David S. Miller" Subject: [PATCH net 02/16] of_mdio: add helper to deregister fixed-link PHYs Date: Mon, 28 Nov 2016 19:24:55 +0100 Message-Id: <1480357509-28074-3-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1480357509-28074-1-git-send-email-johan@kernel.org> References: <1480357509-28074-1-git-send-email-johan@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161128_102748_872095_3494C407 X-CRM114-Status: GOOD ( 12.86 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Lunn , devicetree@vger.kernel.org, Pantelis Antoniou , Frank Rowand , Felix Fietkau , Florian Fainelli , Claudiu Manoil , Li Yang , Mugunthan V N , Grygorii Strashko , linuxppc-dev@lists.ozlabs.org, Johan Hovold , Rob Herring , linux-mediatek@lists.infradead.org, Lars Persson , Matthias Brugger , linux-omap@vger.kernel.org, John Crispin , Thomas Petazzoni , Fugang Duan , Sergei Shtylyov , Vivien Didelot , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Vitaly Bordug , nios2-dev@lists.rocketboards.org, Vince Bridgers MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add helper to deregister fixed-link PHYs registered using of_phy_register_fixed_link(). Convert the two drivers that care to deregister their fixed-link PHYs to use the new helper, but note that most drivers currently fail to do so. Signed-off-by: Johan Hovold --- drivers/net/ethernet/ti/cpsw.c | 16 ++-------------- drivers/of/of_mdio.c | 15 +++++++++++++++ include/linux/of_mdio.h | 4 ++++ net/dsa/dsa.c | 12 ++---------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 58947aae31c7..9f0646512624 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -2459,20 +2459,8 @@ static void cpsw_remove_dt(struct platform_device *pdev) if (strcmp(slave_node->name, "slave")) continue; - if (of_phy_is_fixed_link(slave_node)) { - struct phy_device *phydev; - - phydev = of_phy_find_device(slave_node); - if (phydev) { - fixed_phy_unregister(phydev); - /* Put references taken by - * of_phy_find_device() and - * of_phy_register_fixed_link(). - */ - phy_device_free(phydev); - phy_device_free(phydev); - } - } + if (of_phy_is_fixed_link(slave_node)) + of_phy_deregister_fixed_link(slave_node); of_node_put(slave_data->phy_node); diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 5a3145a02547..262281bd68fa 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -490,3 +490,18 @@ int of_phy_register_fixed_link(struct device_node *np) return -ENODEV; } EXPORT_SYMBOL(of_phy_register_fixed_link); + +void of_phy_deregister_fixed_link(struct device_node *np) +{ + struct phy_device *phydev; + + phydev = of_phy_find_device(np); + if (!phydev) + return; + + fixed_phy_unregister(phydev); + + put_device(&phydev->mdio.dev); /* of_phy_find_device() */ + phy_device_free(phydev); /* fixed_phy_register() */ +} +EXPORT_SYMBOL(of_phy_deregister_fixed_link); diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h index 2ab233661ae5..a58cca8bcb29 100644 --- a/include/linux/of_mdio.h +++ b/include/linux/of_mdio.h @@ -29,6 +29,7 @@ struct phy_device *of_phy_attach(struct net_device *dev, extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np); extern int of_mdio_parse_addr(struct device *dev, const struct device_node *np); extern int of_phy_register_fixed_link(struct device_node *np); +extern void of_phy_deregister_fixed_link(struct device_node *np); extern bool of_phy_is_fixed_link(struct device_node *np); #else /* CONFIG_OF */ @@ -83,6 +84,9 @@ static inline int of_phy_register_fixed_link(struct device_node *np) { return -ENOSYS; } +static inline void of_phy_deregister_fixed_link(struct device_node *np) +{ +} static inline bool of_phy_is_fixed_link(struct device_node *np) { return false; diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index cb0091b99592..7899919cd9f0 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -506,16 +506,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, void dsa_cpu_dsa_destroy(struct device_node *port_dn) { - struct phy_device *phydev; - - if (of_phy_is_fixed_link(port_dn)) { - phydev = of_phy_find_device(port_dn); - if (phydev) { - fixed_phy_unregister(phydev); - put_device(&phydev->mdio.dev); - phy_device_free(phydev); - } - } + if (of_phy_is_fixed_link(port_dn)) + of_phy_deregister_fixed_link(port_dn); } static void dsa_switch_destroy(struct dsa_switch *ds)