Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3613960rwb; Mon, 16 Jan 2023 10:16:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXueRxQv/ZPDVS0F/wTFg8GFHj9VK5dPTWBs3P9kbiyuNplc48oPKP4dPVT0Q2anLYnUQAz0 X-Received: by 2002:a17:906:8e1b:b0:871:8a18:d0a7 with SMTP id rx27-20020a1709068e1b00b008718a18d0a7mr2652142ejc.68.1673893010141; Mon, 16 Jan 2023 10:16:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673893010; cv=none; d=google.com; s=arc-20160816; b=hnMxNhXfRf5VjhFbegG15uCwxpBQpMJ/he64kli4UB0SR7qG7r/UJlOwk1R0SNcnQQ 5jITihsvKLZlxZufxIdtw0t2WtUHs9kn/iKMH+BZZEgFRaM4ZnJB1fa/jSFIrWPncLsY HFLtrk5r6tPPQVCYlvavE19sOrtP4ilMXno+0dWaCC2D6Ji1eUo9lSmblaC6KIezS+Wy ATuuF2vGLZFKfm5uGopIDb04iR8Jo3rTxwvMkRqKxcBrf0cXH1KLQZTmp2b1lxwvkxDo Az8oytvR5v9gq59UnN2V8bHYvvQl1CXqgPdt4vljU6WMRAKxSHzuiKHjE0ZsjY13fdzo nmwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p7zRzIvSvAnePdgerXrTk1rkO3KZL7nxc+XvMTxQPhY=; b=MoIYubYaBEk1y9WWr3hVL6QTR3R6M1vCDFjlq2YT21lzvpdpDzAv3MRPuq+7sXnJWL MpNGWySKuUft6HYrjabUqQnhx6cxDWNDQCkHTLuTiERrUwl7vIY6slGnAX5H8s80U6RJ oWkEsv5f3rlc581QdVhK9hlX6yf4i0nj6JHG5FjRoBlXvtTRB0DPmGE4ScnRqhQgC5H4 TdjUXomLG0e+gjRJXD6O5dKLCsxw4IAX3tm+B3ZLzAJRSVLbH9n0D4CH5I8RYUOEM5jL vBrtjtDwUKhDu/i/EJ4orOESpJIj4zf1AyjEIMZAfkvphdXTjhPHbbY1AbYJ8FbKno6B kW/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b="Xw/fj4+F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ww2-20020a170907084200b007c0db556798si32582418ejb.994.2023.01.16.10.16.37; Mon, 16 Jan 2023 10:16:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b="Xw/fj4+F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235129AbjAPRxN (ORCPT + 52 others); Mon, 16 Jan 2023 12:53:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233175AbjAPRwa (ORCPT ); Mon, 16 Jan 2023 12:52:30 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 930ED30E9E for ; Mon, 16 Jan 2023 09:35:01 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id o7so30347147ljj.8 for ; Mon, 16 Jan 2023 09:35:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=p7zRzIvSvAnePdgerXrTk1rkO3KZL7nxc+XvMTxQPhY=; b=Xw/fj4+FQpuzGP7EaLIXAVXbJxMPn0Ykf3JEyIVvh0e4CzvpJ+Ly0jSQ3R8nTXqfzg VJGosRKpmExhQ9GpsUvmDtQWbOHyRkh5QTYCstCk04Rt4pkYX0ma0fOiQcPnskzbcRJL /gXJNwOBsx1qqirgcQ1+ghYY1A9aNvklPV3uqw8rsqrbN5J6fqLdwuBgwkGtHVjG5xXh UjpZbwI3W8mHWLpQaDCUMqXYCweFwB+cv2KJAV2xSc9lzC27lMd7ha/3jy/6nDiXGfRs wl4xkixjqViuR8690NymFAvdA+n3U759J6sArzAcVTCri00qP0eYxpdBX5C3t9kbNfXx N8WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p7zRzIvSvAnePdgerXrTk1rkO3KZL7nxc+XvMTxQPhY=; b=CBIdFiWn2iJtBf2cMZi/QAugGsaEPywJr1VsYGcXrBEKBICGcGV+hbac1Cve/wrtbQ yIwUTVwq8MdufnY78aYTRAnqZM5ffhwaLBYDIK/KiLMQcvCrTaHOZ54C4102TzP23Wcr mfIHNfwldlqa4kF9v3EFZPbybtW0kw1vVyZITLjrKRBhigjyUx1yZ9ATpDadCv72J+gy QYZIMkRNnWgsUhyYaAZbak9fGPNXwoceweqCxyNvDeorn5dWJLB35gPaLMLtZ+chXQW0 jwmSsJeK8zF+oOgjTUW5vtZzf+Qq+JqRmEIjcFIJxVt5D49vmBiqwMQPEKK3baGfgOMe KNNw== X-Gm-Message-State: AFqh2kpDTJvIXL9MikACN1oGKXEsTIJH532S1TJM3BBU1fN1LgHjc2Tf drGqOF+cZlTy4Xv435GxzAMvRFa00hR0YUmq X-Received: by 2002:a2e:838b:0:b0:285:478a:7f2c with SMTP id x11-20020a2e838b000000b00285478a7f2cmr164267ljg.38.1673890499896; Mon, 16 Jan 2023 09:34:59 -0800 (PST) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id k20-20020a2e8894000000b0028b7f51414fsm707333lji.80.2023.01.16.09.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 09:34:59 -0800 (PST) From: Marcin Wojtas To: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, netdev@vger.kernel.org Cc: rafael@kernel.org, andriy.shevchenko@linux.intel.com, sean.wang@mediatek.com, Landen.Chao@mediatek.com, linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, hkallweit1@gmail.com, mw@semihalf.com, jaz@semihalf.com, tn@semihalf.com, Samer.El-Haj-Mahmoud@arm.com Subject: [net-next: PATCH v4 2/8] net: mdio: switch fixed-link PHYs API to fwnode_ Date: Mon, 16 Jan 2023 18:34:14 +0100 Message-Id: <20230116173420.1278704-3-mw@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20230116173420.1278704-1-mw@semihalf.com> References: <20230116173420.1278704-1-mw@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org fixed-link PHYs API is used by DSA and a number of drivers and was depending on of_. Switch to fwnode_ so to make it hardware description agnostic and allow to be used in ACPI world as well. Signed-off-by: Marcin Wojtas --- include/linux/fwnode_mdio.h | 19 ++++ drivers/net/mdio/fwnode_mdio.c | 96 ++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 79 +--------------- 3 files changed, 118 insertions(+), 76 deletions(-) diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h index faf603c48c86..98755b8c6c8a 100644 --- a/include/linux/fwnode_mdio.h +++ b/include/linux/fwnode_mdio.h @@ -16,6 +16,11 @@ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, int fwnode_mdiobus_register_phy(struct mii_bus *bus, struct fwnode_handle *child, u32 addr); +int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode); + +void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode); + +bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode); #else /* CONFIG_FWNODE_MDIO */ int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy, @@ -30,6 +35,20 @@ static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus, { return -EINVAL; } + +static inline int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode) +{ + return -ENODEV; +} + +static inline void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode) +{ +} + +static inline bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode) +{ + return false; +} #endif #endif /* __LINUX_FWNODE_MDIO_H */ diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c index b782c35c4ac1..56f57381ae69 100644 --- a/drivers/net/mdio/fwnode_mdio.c +++ b/drivers/net/mdio/fwnode_mdio.c @@ -10,6 +10,7 @@ #include #include #include +#include #include MODULE_AUTHOR("Calvin Johnson "); @@ -185,3 +186,98 @@ int fwnode_mdiobus_register_phy(struct mii_bus *bus, return rc; } EXPORT_SYMBOL(fwnode_mdiobus_register_phy); + +/* + * fwnode_phy_is_fixed_link() and fwnode_phy_register_fixed_link() must + * support two bindings: + * - the old binding, where 'fixed-link' was a property with 5 + * cells encoding various information about the fixed PHY + * - the new binding, where 'fixed-link' is a sub-node of the + * Ethernet device. + */ +bool fwnode_phy_is_fixed_link(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *fixed_link_node; + const char *managed; + + /* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + fwnode_handle_put(fixed_link_node); + return true; + } + + if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && + strcmp(managed, "auto") != 0) + return true; + + /* Old binding */ + return fwnode_property_count_u32(fwnode, "fixed-link") == 5; +} +EXPORT_SYMBOL(fwnode_phy_is_fixed_link); + +int fwnode_phy_register_fixed_link(struct fwnode_handle *fwnode) +{ + struct fixed_phy_status status = {}; + struct fwnode_handle *fixed_link_node; + u32 fixed_link_prop[5]; + const char *managed; + int rc; + + if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 && + strcmp(managed, "in-band-status") == 0) { + /* status is zeroed, namely its .link member */ + goto register_phy; + } + + /* New binding */ + fixed_link_node = fwnode_get_named_child_node(fwnode, "fixed-link"); + if (fixed_link_node) { + status.link = 1; + status.duplex = fwnode_property_present(fixed_link_node, + "full-duplex"); + rc = fwnode_property_read_u32(fixed_link_node, "speed", + &status.speed); + if (rc) { + fwnode_handle_put(fixed_link_node); + return rc; + } + status.pause = fwnode_property_present(fixed_link_node, "pause"); + status.asym_pause = fwnode_property_present(fixed_link_node, + "asym-pause"); + fwnode_handle_put(fixed_link_node); + + goto register_phy; + } + + /* Old binding */ + rc = fwnode_property_read_u32_array(fwnode, "fixed-link", fixed_link_prop, + ARRAY_SIZE(fixed_link_prop)); + if (rc) + return rc; + + status.link = 1; + status.duplex = fixed_link_prop[1]; + status.speed = fixed_link_prop[2]; + status.pause = fixed_link_prop[3]; + status.asym_pause = fixed_link_prop[4]; + +register_phy: + return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, fwnode)); +} +EXPORT_SYMBOL(fwnode_phy_register_fixed_link); + +void fwnode_phy_deregister_fixed_link(struct fwnode_handle *fwnode) +{ + struct phy_device *phydev; + + phydev = fwnode_phy_find_device(fwnode); + if (!phydev) + return; + + fixed_phy_unregister(phydev); + + put_device(&phydev->mdio.dev); /* fwnode_phy_find_device() */ + phy_device_free(phydev); /* fixed_phy_register() */ +} +EXPORT_SYMBOL(fwnode_phy_deregister_fixed_link); diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index ba22b7110cdc..e6b3a4e251a1 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -353,91 +353,18 @@ EXPORT_SYMBOL(of_phy_get_and_connect); */ bool of_phy_is_fixed_link(struct device_node *np) { - struct device_node *dn; - int len, err; - const char *managed; - - /* New binding */ - dn = of_get_child_by_name(np, "fixed-link"); - if (dn) { - of_node_put(dn); - return true; - } - - err = of_property_read_string(np, "managed", &managed); - if (err == 0 && strcmp(managed, "auto") != 0) - return true; - - /* Old binding */ - if (of_get_property(np, "fixed-link", &len) && - len == (5 * sizeof(__be32))) - return true; - - return false; + return fwnode_phy_is_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_is_fixed_link); int of_phy_register_fixed_link(struct device_node *np) { - struct fixed_phy_status status = {}; - struct device_node *fixed_link_node; - u32 fixed_link_prop[5]; - const char *managed; - - if (of_property_read_string(np, "managed", &managed) == 0 && - strcmp(managed, "in-band-status") == 0) { - /* status is zeroed, namely its .link member */ - goto register_phy; - } - - /* New binding */ - fixed_link_node = of_get_child_by_name(np, "fixed-link"); - if (fixed_link_node) { - status.link = 1; - status.duplex = of_property_read_bool(fixed_link_node, - "full-duplex"); - if (of_property_read_u32(fixed_link_node, "speed", - &status.speed)) { - of_node_put(fixed_link_node); - return -EINVAL; - } - status.pause = of_property_read_bool(fixed_link_node, "pause"); - status.asym_pause = of_property_read_bool(fixed_link_node, - "asym-pause"); - of_node_put(fixed_link_node); - - goto register_phy; - } - - /* Old binding */ - if (of_property_read_u32_array(np, "fixed-link", fixed_link_prop, - ARRAY_SIZE(fixed_link_prop)) == 0) { - status.link = 1; - status.duplex = fixed_link_prop[1]; - status.speed = fixed_link_prop[2]; - status.pause = fixed_link_prop[3]; - status.asym_pause = fixed_link_prop[4]; - goto register_phy; - } - - return -ENODEV; - -register_phy: - return PTR_ERR_OR_ZERO(fixed_phy_register(PHY_POLL, &status, of_fwnode_handle(np))); + return fwnode_phy_register_fixed_link(of_fwnode_handle(np)); } 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() */ + fwnode_phy_deregister_fixed_link(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_phy_deregister_fixed_link); -- 2.29.0