From patchwork Thu Jun 10 16:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FF7FC48BDF for ; Thu, 10 Jun 2021 16:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 34AAA613DD for ; Thu, 10 Jun 2021 16:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231324AbhFJQmR (ORCPT ); Thu, 10 Jun 2021 12:42:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbhFJQmQ (ORCPT ); Thu, 10 Jun 2021 12:42:16 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AACE1C061574; Thu, 10 Jun 2021 09:40:19 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id ce15so216836ejb.4; Thu, 10 Jun 2021 09:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ekhkiQ/ajaml1kkzZn9VuscWuNkh/PE4KZAYXzMIVnE=; b=LBjQHRUBy/eSAUVhN05Z3w4cUT4qOfjlCzuiJV3c/eOyEqnWk9A0r6HBF/Mso1iktB FonlMGy2EP0SGjxQw3Z3rCdElScXasBWjfcd+4f/tekaorUWnuoYh8Z3lNRBPQoGXh7f ds7P21wY8G0fkLaX9XZnS4ozPllkvQLMIB6ak1khU0fGQbaVx8IbrIGFZHkYGLE8YUSo oOg8dFA+dxWg0EoWBuuz8GUkIaaCI6Ypi4YsxmNtj5G95H21BdTz9tL08lzz1J5YpWGA dbPeHwVWCslDNH1dgBxGKjfEJvKBLsDuYWCf006hGm0g8rdwpwwijRBcZjujAYVxhPNk fVXA== 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:mime-version:content-transfer-encoding; bh=ekhkiQ/ajaml1kkzZn9VuscWuNkh/PE4KZAYXzMIVnE=; b=DqCvsad8A4dZVTnQj+BBEkJ0ME5skVD7vyGmf4r+/lqTC6r9FIrp9feVXSRCmCABx5 7K0XVGXmC6+aJRz54cGtSKOwnsbPFesuEUj1penex3Kbjufj239vM8rXEzPEcL0+bV+n milzqM0ZudsCvhsvK0gV/OYYGJlrpejlTVzqyBgOotXTtMxuGFqnsJP+crZcQwvSJnBW Y2cJDGCGhUWwmjhFgMIkaQ4F1pwo9ctUiO85/xta43vK4o3L5+4AMrJX+0/9Eb0nJric 7NMUKASBQ0YlBPsDzyCjhAx/B/fBBAxF1gwPmyVdHhhE2JR1it7o5JRFoEeov6ZAO9O+ mxbg== X-Gm-Message-State: AOAM533jLxhARLGcbkulRcSNM1I7R0vi2pcmVppeXBONbq38hHDOlSid 2vQME8uSTKpE1PrzVUB94e4= X-Google-Smtp-Source: ABdhPJzft5i0ZiOR+rf9TO8ZlJg/BGluC2Y4GAupGRxA5UnS62OO68Rx+K5ILcCy/8s8hEkUbG+q+A== X-Received: by 2002:a17:906:49c8:: with SMTP id w8mr445104ejv.497.1623343218154; Thu, 10 Jun 2021 09:40:18 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:17 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 01/15] Documentation: ACPI: DSD: Document MDIO PHY Date: Thu, 10 Jun 2021 19:39:03 +0300 Message-Id: <20210610163917.4138412-2-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Introduce ACPI mechanism to get PHYs registered on a MDIO bus and provide them to be connected to MAC. Describe properties "phy-handle" and "phy-mode". Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei Acked-by: Rafael J. Wysocki Acked-by: may not be very valuable, but here it is anyway: Acked-by: Grant Likely --- Changes in v8: None Changes in v7: None Changes in v6: - Minor cleanup Changes in v5: - More cleanup Changes in v4: - More cleanup Changes in v3: None Changes in v2: - Updated with more description in document Documentation/firmware-guide/acpi/dsd/phy.rst | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Documentation/firmware-guide/acpi/dsd/phy.rst diff --git a/Documentation/firmware-guide/acpi/dsd/phy.rst b/Documentation/firmware-guide/acpi/dsd/phy.rst new file mode 100644 index 000000000000..7d01ae8b3cc6 --- /dev/null +++ b/Documentation/firmware-guide/acpi/dsd/phy.rst @@ -0,0 +1,133 @@ +.. SPDX-License-Identifier: GPL-2.0 + +========================= +MDIO bus and PHYs in ACPI +========================= + +The PHYs on an MDIO bus [1] are probed and registered using +fwnode_mdiobus_register_phy(). + +Later, for connecting these PHYs to their respective MACs, the PHYs registered +on the MDIO bus have to be referenced. + +This document introduces two _DSD properties that are to be used +for connecting PHYs on the MDIO bus [3] to the MAC layer. + +These properties are defined in accordance with the "Device +Properties UUID For _DSD" [2] document and the +daffd814-6eba-4d8c-8a91-bc9bbf4aa301 UUID must be used in the Device +Data Descriptors containing them. + +phy-handle +---------- +For each MAC node, a device property "phy-handle" is used to reference +the PHY that is registered on an MDIO bus. This is mandatory for +network interfaces that have PHYs connected to MAC via MDIO bus. + +During the MDIO bus driver initialization, PHYs on this bus are probed +using the _ADR object as shown below and are registered on the MDIO bus. + +:: + Scope(\_SB.MDI0) + { + Device(PHY1) { + Name (_ADR, 0x1) + } // end of PHY1 + + Device(PHY2) { + Name (_ADR, 0x2) + } // end of PHY2 + } + +Later, during the MAC driver initialization, the registered PHY devices +have to be retrieved from the MDIO bus. For this, the MAC driver needs +references to the previously registered PHYs which are provided +as device object references (e.g. \_SB.MDI0.PHY1). + +phy-mode +-------- +The "phy-mode" _DSD property is used to describe the connection to +the PHY. The valid values for "phy-mode" are defined in [4]. + +The following ASL example illustrates the usage of these properties. + +DSDT entry for MDIO node +------------------------ + +The MDIO bus has an SoC component (MDIO controller) and a platform +component (PHYs on the MDIO bus). + +a) Silicon Component +This node describes the MDIO controller, MDI0 +--------------------------------------------- +:: + Scope(_SB) + { + Device(MDI0) { + Name(_HID, "NXP0006") + Name(_CCA, 1) + Name(_UID, 0) + Name(_CRS, ResourceTemplate() { + Memory32Fixed(ReadWrite, MDI0_BASE, MDI_LEN) + Interrupt(ResourceConsumer, Level, ActiveHigh, Shared) + { + MDI0_IT + } + }) // end of _CRS for MDI0 + } // end of MDI0 + } + +b) Platform Component +The PHY1 and PHY2 nodes represent the PHYs connected to MDIO bus MDI0 +--------------------------------------------------------------------- +:: + Scope(\_SB.MDI0) + { + Device(PHY1) { + Name (_ADR, 0x1) + } // end of PHY1 + + Device(PHY2) { + Name (_ADR, 0x2) + } // end of PHY2 + } + +DSDT entries representing MAC nodes +----------------------------------- + +Below are the MAC nodes where PHY nodes are referenced. +phy-mode and phy-handle are used as explained earlier. +------------------------------------------------------ +:: + Scope(\_SB.MCE0.PR17) + { + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package (2) {"phy-mode", "rgmii-id"}, + Package (2) {"phy-handle", \_SB.MDI0.PHY1} + } + }) + } + + Scope(\_SB.MCE0.PR18) + { + Name (_DSD, Package () { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package (2) {"phy-mode", "rgmii-id"}, + Package (2) {"phy-handle", \_SB.MDI0.PHY2}} + } + }) + } + +References +========== + +[1] Documentation/networking/phy.rst + +[2] https://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf + +[3] Documentation/firmware-guide/acpi/DSD-properties-rules.rst + +[4] Documentation/devicetree/bindings/net/ethernet-controller.yaml From patchwork Thu Jun 10 16:39:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE321C47094 for ; Thu, 10 Jun 2021 16:41:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE07A60FDA for ; Thu, 10 Jun 2021 16:41:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbhFJQn1 (ORCPT ); Thu, 10 Jun 2021 12:43:27 -0400 Received: from mail-ed1-f41.google.com ([209.85.208.41]:33382 "EHLO mail-ed1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231500AbhFJQnR (ORCPT ); Thu, 10 Jun 2021 12:43:17 -0400 Received: by mail-ed1-f41.google.com with SMTP id f5so28804474eds.0; Thu, 10 Jun 2021 09:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KaDg6gQwiNbYQ/n+/AJXeEJZNxoDx4UiMVm3rtxhM28=; b=UHYZrSeAQMnPEqKw9Yu1yjR6f8crKDxB0QKCJUw/qyyC7dvFfrO/CGQIAqee8f1PlG bhM5fU/2JgbtIgfP+wiN2adwzCDBXnooeSBx6uQCulbemwY58oyPAZuqosXWz90YE8nD TpQMDXGv4OHl5KI34uKDpOvbUGPYhh3iTuv+zXV3zsvSG6ndCDzm0MRfbLxMzfgvlXHo 7FVFV2KfjxdikU5QLfpamLN/wz4LmbLj0aUucsw/zgwl4Nuh4yigaiJkHhqqAzLe9jet 2tlqDpEJiumXFst6m2Vy0pMpHvRDB6n+7JRG7Rb3M9ufVrR+Q6ugz5Ml+0eKrhZdDc7x 6Ejw== 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:mime-version:content-transfer-encoding; bh=KaDg6gQwiNbYQ/n+/AJXeEJZNxoDx4UiMVm3rtxhM28=; b=HORXkDjRp6XHlMGe4xbGFV32RNDeCt8tS9zAkfT0P5pEIaiFZXiTbDUcL1/JTbliku EtZOn/RJuBUGCMYXE36Irhq5OtObeo6KCfpPpDKxGK6xVtMKIWdoTIEz2H3+plWQOUyI 2FCKYEKockV3iFlQGo7Nfe/zmFA6aiNvsAOXKZc/39eSDLKvQ9u0/oFMcPziW8lmQS7C O/lgG/6hNYU048VPywncc9SPL4LpNgxbyAhx7bZ9gShJjdEuOH9yDvPrjVJHYggUNrdH 93OqkG7QZ1VVAp+ylZsmExVGh0xesySQZb4f17g6lTLnku1dHWL2gOQNAfbp0Vf8+tG4 p6dw== X-Gm-Message-State: AOAM530cN8P7+r+gg/RpT2K3/vakk9mLGVwvsYqIoy+UfSDyasGHuSMM Ls1qrZ9c59fqeK4WmKaQuc8= X-Google-Smtp-Source: ABdhPJwV5RxjQIJKGTTFuMRHC1yAz5oZtEGMCwmSVSL7QWpJwoalTw1VHdLa4/3G2Moi2Q06OIkSGg== X-Received: by 2002:a05:6402:204:: with SMTP id t4mr387873edv.34.1623343220068; Thu, 10 Jun 2021 09:40:20 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:19 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 02/15] net: phy: Introduce fwnode_mdio_find_device() Date: Thu, 10 Jun 2021 19:39:04 +0300 Message-Id: <20210610163917.4138412-3-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Define fwnode_mdio_find_device() to get a pointer to the mdio_device from fwnode passed to the function. Refactor of_mdio_find_device() to use fwnode_mdio_find_device(). Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: - correct fwnode_mdio_find_device() description Changes in v6: - fix warning for function parameter of fwnode_mdio_find_device() Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/mdio/of_mdio.c | 11 +---------- drivers/net/phy/phy_device.c | 23 +++++++++++++++++++++++ include/linux/phy.h | 7 +++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 8e97d5b825f5..6ef8b6e40189 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -347,16 +347,7 @@ EXPORT_SYMBOL(of_mdiobus_register); */ struct mdio_device *of_mdio_find_device(struct device_node *np) { - struct device *d; - - if (!np) - return NULL; - - d = bus_find_device_by_of_node(&mdio_bus_type, np); - if (!d) - return NULL; - - return to_mdio_device(d); + return fwnode_mdio_find_device(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_mdio_find_device); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1539ea021ac0..363cc70d00ca 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2863,6 +2863,29 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) return phydrv->config_intr && phydrv->handle_interrupt; } +/** + * fwnode_mdio_find_device - Given a fwnode, find the mdio_device + * @fwnode: pointer to the mdio_device's fwnode + * + * If successful, returns a pointer to the mdio_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + * The caller should call put_device() on the mdio_device after its use. + */ +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) +{ + struct device *d; + + if (!fwnode) + return NULL; + + d = bus_find_device_by_fwnode(&mdio_bus_type, fwnode); + if (!d) + return NULL; + + return to_mdio_device(d); +} +EXPORT_SYMBOL(fwnode_mdio_find_device); + /** * phy_probe - probe and init a PHY device * @dev: device to probe and init diff --git a/include/linux/phy.h b/include/linux/phy.h index ed332ac92e25..7aa97f4e5387 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1377,10 +1377,17 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, bool is_c45, struct phy_c45_device_ids *c45_ids); #if IS_ENABLED(CONFIG_PHYLIB) +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode); struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); int phy_device_register(struct phy_device *phy); void phy_device_free(struct phy_device *phydev); #else +static inline +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) +{ + return 0; +} + static inline struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) { From patchwork Thu Jun 10 16:39:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33F3AC47094 for ; Thu, 10 Jun 2021 16:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DF9D613E1 for ; Thu, 10 Jun 2021 16:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbhFJQmo (ORCPT ); Thu, 10 Jun 2021 12:42:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231420AbhFJQmh (ORCPT ); Thu, 10 Jun 2021 12:42:37 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A140CC061574; Thu, 10 Jun 2021 09:40:23 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id l1so203627ejb.6; Thu, 10 Jun 2021 09:40:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=shfC9D595uDApwpxEXW8RRDC5cbltzSKhmOaalAiSMg=; b=QGBpbB+sbXZx4uG7W9s9OIFYCVD0zB0Jw8s6tz2sjm9ezoAHS/NAYZgWrJj7VqJ410 yqcid0G80rGzmVGzMcl7vkqQ2MeOru5Mr3SZrdB4ojLFAUIEqxOAIpIRmVdpEIHCiTBS KzN9MEX1VHIwG9sFymoIK25PaBgGHSkTe3ZONahCai80COKNj614e9bWpq4P/K7s7Ys0 /AmZ4GPbZE/gVW4SyAAzi6HEdZKypuGW7rN+4+FkDy4BKruynsF5/LGaVcr/1kjDeokt e2qW0VTV3grlbQ5PVg/MeqjwzVItY/BjzHeH6zRR0j0PT73gFkdKXHoewTACAx6MfN0E XOJw== 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:mime-version:content-transfer-encoding; bh=shfC9D595uDApwpxEXW8RRDC5cbltzSKhmOaalAiSMg=; b=arXfpbAEdWAc3l5AF+QkbrDmCVU1qEQlE1lqU5w/M8xQnNa6x5uia1R3GimEogUGsI 55KiC4QPo/4LkI7uXgw3e+Dp83izb4IWFmQkuzmSnzBUoFdDqat2++L0nZ0neHB9uJTv KtWPgXtref8EBV+UhdCvOesALigOMVVBL5xgAFUdfa4uH2gfxjcPUcD+MJsN0DkQbDId lmABPFyPX3Mw+IzYTfk6r/ESPmknWcWlI+eXDgCv7qcy8x3XVxQr1WoX+kwrfeEGVW0y JfF61TYJ8xiYN641hBsy8dt2ghdH8gdi0F1w5HMRPhGAb3QsIlvQtFR5SFK6Fnb+4bUA BQ7g== X-Gm-Message-State: AOAM531ohY5Fuepedng36Mh3HcsP8tpmFXS62Mu23FEsAMY42mPRZla4 PTJuUlCD9B8nfbo6L2ATYcQ= X-Google-Smtp-Source: ABdhPJz/zjr86kubhnfYba4VQBUWzENHrxk5/xcSj1PnwyXEDtV6uD6kq3yCQWlvf9t7HCbDOiPe1A== X-Received: by 2002:a17:906:6d45:: with SMTP id a5mr457515ejt.399.1623343222093; Thu, 10 Jun 2021 09:40:22 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:21 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 03/15] net: phy: Introduce phy related fwnode functions Date: Thu, 10 Jun 2021 19:39:05 +0300 Message-Id: <20210610163917.4138412-4-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Define fwnode_phy_find_device() to iterate an mdiobus and find the phy device of the provided phy fwnode. Additionally define device_phy_find_device() to find phy device of provided device. Define fwnode_get_phy_node() to get phy_node using named reference. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: - Add more info on legacy DT properties "phy" and "phy-device" - Redefine fwnode_phy_find_device() to follow of_phy_find_device() Changes in v2: - use reverse christmas tree ordering for local variables drivers/net/phy/phy_device.c | 62 ++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 20 ++++++++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 363cc70d00ca..f651c4feb49f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -9,6 +9,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -2886,6 +2887,67 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) } EXPORT_SYMBOL(fwnode_mdio_find_device); +/** + * fwnode_phy_find_device - For provided phy_fwnode, find phy_device. + * + * @phy_fwnode: Pointer to the phy's fwnode. + * + * If successful, returns a pointer to the phy_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + */ +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) +{ + struct mdio_device *mdiodev; + + mdiodev = fwnode_mdio_find_device(phy_fwnode); + if (!mdiodev) + return NULL; + + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) + return to_phy_device(&mdiodev->dev); + + put_device(&mdiodev->dev); + + return NULL; +} +EXPORT_SYMBOL(fwnode_phy_find_device); + +/** + * device_phy_find_device - For the given device, get the phy_device + * @dev: Pointer to the given device + * + * Refer return conditions of fwnode_phy_find_device(). + */ +struct phy_device *device_phy_find_device(struct device *dev) +{ + return fwnode_phy_find_device(dev_fwnode(dev)); +} +EXPORT_SYMBOL_GPL(device_phy_find_device); + +/** + * fwnode_get_phy_node - Get the phy_node using the named reference. + * @fwnode: Pointer to fwnode from which phy_node has to be obtained. + * + * Refer return conditions of fwnode_find_reference(). + * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy" + * and "phy-device" are not supported in ACPI. DT supports all the three + * named references to the phy node. + */ +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *phy_node; + + /* Only phy-handle is used for ACPI */ + phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); + if (is_acpi_node(fwnode) || !IS_ERR(phy_node)) + return phy_node; + phy_node = fwnode_find_reference(fwnode, "phy", 0); + if (IS_ERR(phy_node)) + phy_node = fwnode_find_reference(fwnode, "phy-device", 0); + return phy_node; +} +EXPORT_SYMBOL_GPL(fwnode_get_phy_node); + /** * phy_probe - probe and init a PHY device * @dev: device to probe and init diff --git a/include/linux/phy.h b/include/linux/phy.h index 7aa97f4e5387..f9b5fb099fa6 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1378,6 +1378,9 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, struct phy_c45_device_ids *c45_ids); #if IS_ENABLED(CONFIG_PHYLIB) struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode); +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); +struct phy_device *device_phy_find_device(struct device *dev); +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode); struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); int phy_device_register(struct phy_device *phy); void phy_device_free(struct phy_device *phydev); @@ -1388,6 +1391,23 @@ struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) return 0; } +static inline +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) +{ + return NULL; +} + +static inline struct phy_device *device_phy_find_device(struct device *dev) +{ + return NULL; +} + +static inline +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) +{ + return NULL; +} + static inline struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) { From patchwork Thu Jun 10 16:39:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85A62C48BD1 for ; Thu, 10 Jun 2021 16:40:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69C91613DD for ; Thu, 10 Jun 2021 16:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbhFJQmo (ORCPT ); Thu, 10 Jun 2021 12:42:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbhFJQmg (ORCPT ); Thu, 10 Jun 2021 12:42:36 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8F1C0617A6; Thu, 10 Jun 2021 09:40:25 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id w21so33742690edv.3; Thu, 10 Jun 2021 09:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j9eHvw1lqfOl6qU0681eRcLN+MHCzmRQcN2E31ftIDo=; b=sSybiEKHNkV6oB3gxfZkR+Jicue8rGl58fooPFQAaHFXby18vVnsP8GJ2AWv/WCtTo kFftFCtgK7+WmNowlV/xnJOgeAJ7p7zhj8K6EH0+V0DpIRkccTn3W/FRl99dHLYEJPYh pJjWOczWQt8gh+i4pQMQPquU2USV2kmM3ODeA5O2o7ryAyqZhGNTBHMsH+qRiPyjec82 wx1EhfDgHVYliAznWeBsNbh50gyYlxmw1Ox2hMZBcR1MDSByGS5ibrFOUj1xqjp/sGmM 0qOC6q6H0xZT7kEK5pqxbXDHt219rYrMf37mmBL5KpxkeROGG8gQJCyKqJEFdPYdtzzg GodQ== 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:mime-version:content-transfer-encoding; bh=j9eHvw1lqfOl6qU0681eRcLN+MHCzmRQcN2E31ftIDo=; b=sU32CzUqUEIUY3gWf9haLNM17lyLuTxTwv4RSOjmzuRwZhPvqW/d6JJMYa88DWF+Tf d0BcaQ1tR3JhxxxBOT4S5LQRbuHhmyAYq9W7bqSCcisFhHt35AHeuR7qV2UTEQv5OZAF xVFSIhLcnLjbEGIOwbWFfyYKkqWMU9JrLE40sBruUfL6WKgor05N/dR9rP5THKq/dq72 bGQgQmmWdnWcqLE37eOjqYCjkxKgiHtse1EMjXbHot4MTeGsHKIlKsFhu+9c3TZ7viL4 HI3gLPnNWHlPrKYOhYNFoRBDhCySXjM9prTuViNcDadCbbKnBtdrvP+akl8XlV6SNHOt KCbQ== X-Gm-Message-State: AOAM5303JS15JT/dJSlH0KS6deb6V96oRaVE17cm50R1L/dc0JPScHlQ 47YfTA+5FN7zpXDGwGUJCJw= X-Google-Smtp-Source: ABdhPJzqqiYvYm4SQUMr+r5gefyTaByZ70DC1vm/F+7Dp8gRQvSaF6tOC/x1yTfVcspDeAYCdk9w/w== X-Received: by 2002:a05:6402:543:: with SMTP id i3mr342712edx.173.1623343224091; Thu, 10 Jun 2021 09:40:24 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:23 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 04/15] of: mdio: Refactor of_phy_find_device() Date: Thu, 10 Jun 2021 19:39:06 +0300 Message-Id: <20210610163917.4138412-5-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Refactor of_phy_find_device() to use fwnode_phy_find_device(). Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/mdio/of_mdio.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 6ef8b6e40189..0ba1158796d9 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -360,18 +360,7 @@ EXPORT_SYMBOL(of_mdio_find_device); */ struct phy_device *of_phy_find_device(struct device_node *phy_np) { - struct mdio_device *mdiodev; - - mdiodev = of_mdio_find_device(phy_np); - if (!mdiodev) - return NULL; - - if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) - return to_phy_device(&mdiodev->dev); - - put_device(&mdiodev->dev); - - return NULL; + return fwnode_phy_find_device(of_fwnode_handle(phy_np)); } EXPORT_SYMBOL(of_phy_find_device); From patchwork Thu Jun 10 16:39:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92C58C47094 for ; Thu, 10 Jun 2021 16:42:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7ABA7613E1 for ; Thu, 10 Jun 2021 16:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231667AbhFJQn4 (ORCPT ); Thu, 10 Jun 2021 12:43:56 -0400 Received: from mail-ed1-f47.google.com ([209.85.208.47]:38831 "EHLO mail-ed1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbhFJQnh (ORCPT ); Thu, 10 Jun 2021 12:43:37 -0400 Received: by mail-ed1-f47.google.com with SMTP id d13so20287112edt.5; Thu, 10 Jun 2021 09:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ag0yKOvBPz35E774qJinec6gzeqAN1dw4dMLgUS0S0M=; b=k00Eyg+KNHcp27L9EngtjAxDEAM+/ChWX41ETeDr8WHFFmX4JsyY8t/hSC77O9lWQ+ 9VM9AHyXSD237yUvDoPoXsnB0h5wYpd1u8EkE7lx182RzfbB1qudjDTPDegA3cuZFzNg +KmC+hV7Qjop6MYodqml4ciy+FrAmkEvhZz9REpd3rShUXLAViF7FwP7WqfGoNer5MwC Wo5mZxTZlevAF1Zt68eHFqow/q7cwpcUQC5AojPx7HG7ds3KeHgoGSOcD/jNPBYeKxw3 X50qhJr6hVw5O+S7TD0GruqRaB9+yqCNhv9Z9wn/+fQg4spYP/i4GSO/EBmZZgmeNS8B W8Mg== 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:mime-version:content-transfer-encoding; bh=ag0yKOvBPz35E774qJinec6gzeqAN1dw4dMLgUS0S0M=; b=jW7vLKdNl2kpaqYxJ0rKYUmnCkIBHtkmbKVcSksPgrK8F6WgyDI5Ik42zrIchBfOaI zks6o8SOE2z5QsMEWXYsUkvdlptKiR39h6mLyh44gEBYZ+lv5QgwS0KUt3a9PE1p+9xa m1kiHO3rdKQCy3webTtftoXV0IBDgucXFE3t7LDapfewFBF0xtvql9fKnE8AqJPcdn0U LqWtcj30Kq4QTqYqv6E0R/Hif8qkrbgVzxNYGYX2TUIYH8X5DUVShcbSE9uvSkIwWTCD r7ImCE2mVJ4ng0yawv2AmvlZI3gove8PIOYELoCQhuZ1837hezpkKThA1kACVoV0SUiE Togw== X-Gm-Message-State: AOAM5322PZJ0zz3qSzgf2gss+I2R9socC/J0kNC6hw5u7c02Y5FMqZpd tzKLAZWpyt2kzg30WBBHwWY= X-Google-Smtp-Source: ABdhPJwR1do5Z1sT8Bu5N6QMCgvOOFKrRwMNFrJ0YWcL3LVcwX4TCoNIMAIhLP9VO1YUdzDASrx+Vg== X-Received: by 2002:a05:6402:1d0c:: with SMTP id dg12mr340543edb.155.1623343226010; Thu, 10 Jun 2021 09:40:26 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:25 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 05/15] net: phy: Introduce fwnode_get_phy_id() Date: Thu, 10 Jun 2021 19:39:07 +0300 Message-Id: <20210610163917.4138412-6-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Extract phy_id from compatible string. This will be used by fwnode_mdiobus_register_phy() to create phy device using the phy_id. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: - Use traditional comparison pattern - Use GENMASK Changes in v2: None drivers/net/phy/phy_device.c | 21 +++++++++++++++++++++ include/linux/phy.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f651c4feb49f..0ce5c7274930 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -834,6 +834,27 @@ static int get_phy_c22_id(struct mii_bus *bus, int addr, u32 *phy_id) return 0; } +/* Extract the phy ID from the compatible string of the form + * ethernet-phy-idAAAA.BBBB. + */ +int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id) +{ + unsigned int upper, lower; + const char *cp; + int ret; + + ret = fwnode_property_read_string(fwnode, "compatible", &cp); + if (ret) + return ret; + + if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) != 2) + return -EINVAL; + + *phy_id = ((upper & GENMASK(15, 0)) << 16) | (lower & GENMASK(15, 0)); + return 0; +} +EXPORT_SYMBOL(fwnode_get_phy_id); + /** * get_phy_device - reads the specified PHY device and returns its @phy_device * struct diff --git a/include/linux/phy.h b/include/linux/phy.h index f9b5fb099fa6..b60694734b07 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1377,6 +1377,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, bool is_c45, struct phy_c45_device_ids *c45_ids); #if IS_ENABLED(CONFIG_PHYLIB) +int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id); struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode); struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); struct phy_device *device_phy_find_device(struct device *dev); @@ -1385,6 +1386,10 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); int phy_device_register(struct phy_device *phy); void phy_device_free(struct phy_device *phydev); #else +static inline int fwnode_get_phy_id(struct fwnode_handle *fwnode, u32 *phy_id) +{ + return 0; +} static inline struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) { From patchwork Thu Jun 10 16:39:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8018C47094 for ; Thu, 10 Jun 2021 16:40:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A00FF613E1 for ; Thu, 10 Jun 2021 16:40:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbhFJQmr (ORCPT ); Thu, 10 Jun 2021 12:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231447AbhFJQml (ORCPT ); Thu, 10 Jun 2021 12:42:41 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FD1DC061760; Thu, 10 Jun 2021 09:40:29 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id k7so160340ejv.12; Thu, 10 Jun 2021 09:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uTnxI5g7pTP4jGA31eYupvoRHHosLhVQl5fsqQt2kmE=; b=K/BnfP2x9atKngYttqB+Vgh7F78oLYUi2dLhhdvn+WIKorMVnrCZ/4AIn0z4hsBSBg C8JsL0qfFxpEQCi7ImdqY4ivRaFG9dL67PCUySfiYGsuRRBDZnYsDydtA39XMS5qufJc 7KGsGJMP1/1rPbxKdK0LDeJa0YrnuLNz70DONMZYo62Wj5D32LA4HltXfTDILMDsevow cxTnXQT+YtnvesijhgjyeZhxdJxszi4Ptmt5U8Q7fxZ1EfD3s3K7Cp3C1jJ/YkXh+5ve T/koiAk4tce9oS6KdwSZNtYndEHHIa4n63AkRJTjjZaurmqeikGzuJNvjwd0G70QKSkU 3Jnw== 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:mime-version:content-transfer-encoding; bh=uTnxI5g7pTP4jGA31eYupvoRHHosLhVQl5fsqQt2kmE=; b=PcnjaLegeB+nOb7GmPgYqhgG9Pnzmy8cc8UXW1A2j0qM0/EIL7uGdxMz0+bRTmlDL9 vqudTgluJBUWBV05ApOpbf0tS/oY/nVIhjG4lbIB7DFNNVZri46JR+D/nhV3+LaVyN31 XrRKyyFP1BrzvEiBKTSqX0vOgFXqHyfeJmLGEkE/Nr+JjxxB8aF9zq8uKi+RiK1rna6Z V+c6lqOl2iWCWIXqTU6qImH/6XVCB9n1laBd5DC4elHBZoKOyQA/9a4hR7U8/hRIvWM5 AO/87hedZz98FobD38OiYcV9VYgxEf8z1XwWUVY7+bdHtJnB3bhD1iF1H8EC8Es0XvN7 8l7A== X-Gm-Message-State: AOAM533x926Ey/swm2124bRXTKR2ly2mTPLu8kxOUtO74Ob5GvnsgDRE x7dL8E0+UakDQJWZ51/C1H4= X-Google-Smtp-Source: ABdhPJyeSYOloOR8hF4HGXfH8IkYg4P/EpFpKhL/014YAO7Rb5LLYqsJNRpGRx36Jh8sGTjQQmYguw== X-Received: by 2002:a17:906:7742:: with SMTP id o2mr495849ejn.284.1623343228063; Thu, 10 Jun 2021 09:40:28 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:27 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 06/15] of: mdio: Refactor of_get_phy_id() Date: Thu, 10 Jun 2021 19:39:08 +0300 Message-Id: <20210610163917.4138412-7-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson With the introduction of fwnode_get_phy_id(), refactor of_get_phy_id() to use fwnode equivalent. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/mdio/of_mdio.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 0ba1158796d9..29f121cba314 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -29,17 +29,7 @@ MODULE_LICENSE("GPL"); * ethernet-phy-idAAAA.BBBB */ static int of_get_phy_id(struct device_node *device, u32 *phy_id) { - struct property *prop; - const char *cp; - unsigned int upper, lower; - - of_property_for_each_string(device, "compatible", prop, cp) { - if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) { - *phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF); - return 0; - } - } - return -EINVAL; + return fwnode_get_phy_id(of_fwnode_handle(device), phy_id); } static struct mii_timestamper *of_find_mii_timestamper(struct device_node *node) From patchwork Thu Jun 10 16:39:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75BDCC48BE0 for ; Thu, 10 Jun 2021 16:41:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E1C7613DD for ; Thu, 10 Jun 2021 16:41:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231527AbhFJQni (ORCPT ); Thu, 10 Jun 2021 12:43:38 -0400 Received: from mail-ej1-f48.google.com ([209.85.218.48]:46895 "EHLO mail-ej1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbhFJQn1 (ORCPT ); Thu, 10 Jun 2021 12:43:27 -0400 Received: by mail-ej1-f48.google.com with SMTP id he7so152629ejc.13; Thu, 10 Jun 2021 09:41:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZXMwlWoKAxdjuwt/HiX3am6VGgoRjdgFRZsahRLqNM4=; b=rr23b17GamtNW4dIKFfdbl4vB0T6+nWAuLM1qZ7yQw2xnlRe+bajixCjTlcKC+hrXO Cwsal0pKmmyPA6kJKecYnw5pIhWxIJaA4AVmPsjJedoNY3jSGz1YnsGHc9AuPuazXFyM IwOH1+nVuAmXlDXfh5R0BYbzBOga0u7dN1RGBISYwAAK65FjtzYHZRxoV26dHJ+Hsg+u DdPki22Jgq2bjkMLQnsjabA8/miMHqOK8DU865YyB4xSY/ollgX8SVpcvqahy211EiYm RsWB0Ft40d/gujKFhntTSmtpqDLfqIIFSGNreZRGBPiGBlclqoExVSN7gLeMs9Qz96DG qwAg== 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:mime-version:content-transfer-encoding; bh=ZXMwlWoKAxdjuwt/HiX3am6VGgoRjdgFRZsahRLqNM4=; b=Lwap2AOEHrmEkTLmA4p6ig7bDwFwsP+xweHEJuZpIJB491atyKOkvIeouNj9RcVIV2 E6n/eKcrXvU3iPbnycdXtq58upi+9s+Yap0RT7nT1BT4xY9OoloyjGTK/DLsC9e9fGFJ RZ6qUcFQdzox0uEOr3TGi58p5KpXFZC6pKYziGC6GdTiaSRKE6/9YxxNUWN/nlstrWqG kiwNEVMwb4R0b833geTMtdJDbkTI/8M0uIgQoJBJtWJrahANVhXBcuFRGCWqVDpc10Vk MO9AZj1YuQ2SJ27r1tLkXCsTxTV3I9I9mGG9SBaOZtB84//ef81i2i6JpUZ5Gqmt5ro5 X23w== X-Gm-Message-State: AOAM531+2TNiP73Tcn/hhWbD4pF4H0ZWVcUEsOPLZuZ3yc1rxWoUgQJy auEH2rNV9V8YPaqgpVYE7GQ= X-Google-Smtp-Source: ABdhPJyCX/NBP+v0Apbk+4/3ZqHRp6qWrIaNmofj15uz4394jzlihzFqwQyK2h4+J5iQK3HLJ45kZQ== X-Received: by 2002:a17:906:490:: with SMTP id f16mr442229eja.541.1623343229891; Thu, 10 Jun 2021 09:40:29 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:29 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 07/15] net: mii_timestamper: check NULL in unregister_mii_timestamper() Date: Thu, 10 Jun 2021 19:39:09 +0300 Message-Id: <20210610163917.4138412-8-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Callers of unregister_mii_timestamper() currently check for NULL value of mii_ts before calling it. Place the NULL check inside unregister_mii_timestamper() and update the callers accordingly. Signed-off-by: Calvin Johnson Reviewed-by: Andy Shevchenko Suggested-by: Andy Shevchenko Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: - check NULL in unregister_mii_timestamper() Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/mdio/of_mdio.c | 6 ++---- drivers/net/phy/mii_timestamper.c | 3 +++ drivers/net/phy/phy_device.c | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 29f121cba314..d73c0570f19c 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -115,15 +115,13 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, else phy = get_phy_device(mdio, addr, is_c45); if (IS_ERR(phy)) { - if (mii_ts) - unregister_mii_timestamper(mii_ts); + unregister_mii_timestamper(mii_ts); return PTR_ERR(phy); } rc = of_mdiobus_phy_device_register(mdio, phy, child, addr); if (rc) { - if (mii_ts) - unregister_mii_timestamper(mii_ts); + unregister_mii_timestamper(mii_ts); phy_device_free(phy); return rc; } diff --git a/drivers/net/phy/mii_timestamper.c b/drivers/net/phy/mii_timestamper.c index b71b7456462d..51ae0593a04f 100644 --- a/drivers/net/phy/mii_timestamper.c +++ b/drivers/net/phy/mii_timestamper.c @@ -111,6 +111,9 @@ void unregister_mii_timestamper(struct mii_timestamper *mii_ts) struct mii_timestamping_desc *desc; struct list_head *this; + if (!mii_ts) + return; + /* mii_timestamper statically registered by the PHY driver won't use the * register_mii_timestamper() and thus don't have ->device set. Don't * try to unregister these. diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 0ce5c7274930..e4b935b0b71b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -945,8 +945,7 @@ EXPORT_SYMBOL(phy_device_register); */ void phy_device_remove(struct phy_device *phydev) { - if (phydev->mii_ts) - unregister_mii_timestamper(phydev->mii_ts); + unregister_mii_timestamper(phydev->mii_ts); device_del(&phydev->mdio.dev); From patchwork Thu Jun 10 16:39:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A31A7C48BDF for ; Thu, 10 Jun 2021 16:40:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B52F61407 for ; Thu, 10 Jun 2021 16:40:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbhFJQmj (ORCPT ); Thu, 10 Jun 2021 12:42:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231391AbhFJQma (ORCPT ); Thu, 10 Jun 2021 12:42:30 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96A99C0617AD; Thu, 10 Jun 2021 09:40:33 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id l1so204352ejb.6; Thu, 10 Jun 2021 09:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hFh6jYonelvZcVZIn7qh3nwcG8z8TGAQoCmOgPCyB0c=; b=Ho8mRlw8cA1XuEW9uN0AMreW1JMmvi9l3Aj9Kg7vSxqQmmyS3SDcDPuX8myEl24zAK rk/TkkaWV4FliQvwFsmVbb2sfHecdDmE8F6pvbdujUsM3f5ztTMusZdjZZ6Ccrej2D8g EvWZlF96PqJukZ+624VwBvUhQoGIIP49hH26+RzSFdIobezMYpgy8P7e9QbKOrwCk8YK Qyk6RI28g0mcXxRfvkYBhWOlFFg/5iddhUv1VZvIWJrceEeM1coDBjpNQF2fipBA/Zd5 Op7o3UWZkVOxApMH2kM/ySJ5UduXXH8WPt7tq/VDzKZCRKQRFD5AkXdH3FmL95T6Dxmd g94g== 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:mime-version:content-transfer-encoding; bh=hFh6jYonelvZcVZIn7qh3nwcG8z8TGAQoCmOgPCyB0c=; b=C2J0cbNZfg3StmxakGjgHKYSRFNd8SRPl2QNtzcTHttqCZwkbiKZipvaACmvkNB2dP uGtuD2nGkFm4l9lVyzj+2murgpWo5Uq2svbHlXs1OdqmuF4FMfO8zAlxWr0hKI1R2BaF Eh1Hyn/5Rv9KtgxrbmqzT3Rwtpdf2uvuBrpcu4qiOAgo7IfYeSA7csY//wQsNtYsqClS 3XuFAq+peMuxmoZHk26SZS3XOPHJ0hBce/HOk+NMLwRIlr4TWsmPLIZmDithwszLRZmZ x/o2GG63qXyel9F6v4Y9/ooLoNjetoQ4Xmiy5TIm4DCcD/f+rUNsrG05/JUABW/9wUlP Tsuw== X-Gm-Message-State: AOAM5310IeSyclYw+qB7x5B2IqoFGDnHnD+ff+v2TIXkNl5rKMUo0oEJ L/LnCVENcW2FTHVHEGUyRVg= X-Google-Smtp-Source: ABdhPJyi/Zlj/d1o32zuNleSWskcyk4jc1ktL+9+XUsQLcPbmWXPXvm7q//kgPyvLth7GxXyuG4wZA== X-Received: by 2002:a17:906:2892:: with SMTP id o18mr474818ejd.124.1623343232068; Thu, 10 Jun 2021 09:40:32 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:31 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 08/15] net: mdiobus: Introduce fwnode_mdiobus_register_phy() Date: Thu, 10 Jun 2021 19:39:10 +0300 Message-Id: <20210610163917.4138412-9-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Introduce fwnode_mdiobus_register_phy() to register PHYs on the mdiobus. From the compatible string, identify whether the PHY is c45 and based on this create a PHY device instance which is registered on the mdiobus. Along with fwnode_mdiobus_register_phy() also introduce fwnode_find_mii_timestamper() and fwnode_mdiobus_phy_device_register() since they are needed. While at it, also use the newly introduced fwnode operation in of_mdiobus_phy_device_register() and remove of_find_mii_timestamper() since it's not needed anymore. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: - fixed some checkpatch warnings/checks - included linux/fwnode_mdio.h in fwnode_mdio.c (fixed the build warnings) - added fwnode_find_mii_timestamper() and fwnode_mdiobus_phy_device_register() in order to get rid of the cycle dependency. - change to 'depends on (ACPI || OF) || COMPILE_TEST Changes in v7: - Call unregister_mii_timestamper() without NULL check - Create fwnode_mdio.c and move fwnode_mdiobus_register_phy() Changes in v6: - Initialize mii_ts to NULL Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None MAINTAINERS | 1 + drivers/net/mdio/Kconfig | 7 ++ drivers/net/mdio/Makefile | 3 +- drivers/net/mdio/fwnode_mdio.c | 144 +++++++++++++++++++++++++++++++++ drivers/net/mdio/of_mdio.c | 61 +------------- include/linux/fwnode_mdio.h | 35 ++++++++ 6 files changed, 193 insertions(+), 58 deletions(-) create mode 100644 drivers/net/mdio/fwnode_mdio.c create mode 100644 include/linux/fwnode_mdio.h diff --git a/MAINTAINERS b/MAINTAINERS index e69c1991ec3b..e8f8b6c33a51 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6811,6 +6811,7 @@ F: Documentation/devicetree/bindings/net/mdio* F: Documentation/devicetree/bindings/net/qca,ar803x.yaml F: Documentation/networking/phy.rst F: drivers/net/mdio/ +F: drivers/net/mdio/fwnode_mdio.c F: drivers/net/mdio/of_mdio.c F: drivers/net/pcs/ F: drivers/net/phy/ diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig index d06e06f5e31a..422e9e042a3c 100644 --- a/drivers/net/mdio/Kconfig +++ b/drivers/net/mdio/Kconfig @@ -19,6 +19,13 @@ config MDIO_BUS reflects whether the mdio_bus/mdio_device code is built as a loadable module or built-in. +config FWNODE_MDIO + def_tristate PHYLIB + depends on (ACPI || OF) || COMPILE_TEST + select FIXED_PHY + help + FWNODE MDIO bus (Ethernet PHY) accessors + config OF_MDIO def_tristate PHYLIB depends on OF diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile index c3ec0ef989df..2e6813c709eb 100644 --- a/drivers/net/mdio/Makefile +++ b/drivers/net/mdio/Makefile @@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux MDIO bus drivers -obj-$(CONFIG_OF_MDIO) += of_mdio.o +obj-$(CONFIG_FWNODE_MDIO) += fwnode_mdio.o +obj-$(CONFIG_OF_MDIO) += of_mdio.o obj-$(CONFIG_MDIO_ASPEED) += mdio-aspeed.o obj-$(CONFIG_MDIO_BCM_IPROC) += mdio-bcm-iproc.o diff --git a/drivers/net/mdio/fwnode_mdio.c b/drivers/net/mdio/fwnode_mdio.c new file mode 100644 index 000000000000..e6985fcf7921 --- /dev/null +++ b/drivers/net/mdio/fwnode_mdio.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * fwnode helpers for the MDIO (Ethernet PHY) API + * + * This file provides helper functions for extracting PHY device information + * out of the fwnode and using it to populate an mii_bus. + */ + +#include +#include +#include +#include + +MODULE_AUTHOR("Calvin Johnson "); +MODULE_LICENSE("GPL"); + +static struct mii_timestamper * +fwnode_find_mii_timestamper(struct fwnode_handle *fwnode) +{ + struct of_phandle_args arg; + int err; + + if (is_acpi_node(fwnode)) + return NULL; + + err = of_parse_phandle_with_fixed_args(to_of_node(fwnode), "timestamper", 1, 0, &arg); + + if (err == -ENOENT) + return NULL; + else if (err) + return ERR_PTR(err); + + if (arg.args_count != 1) + return ERR_PTR(-EINVAL); + + return register_mii_timestamper(arg.np, arg.args[0]); +} + +int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, + struct phy_device *phy, + struct fwnode_handle *child, u32 addr) +{ + int rc; + + rc = fwnode_irq_get(child, 0); + if (rc == -EPROBE_DEFER) + return rc; + + if (rc > 0) { + phy->irq = rc; + mdio->irq[addr] = rc; + } else { + phy->irq = mdio->irq[addr]; + } + + if (fwnode_property_read_bool(child, "broken-turn-around")) + mdio->phy_ignore_ta_mask |= 1 << addr; + + fwnode_property_read_u32(child, "reset-assert-us", + &phy->mdio.reset_assert_delay); + fwnode_property_read_u32(child, "reset-deassert-us", + &phy->mdio.reset_deassert_delay); + + /* Associate the fwnode with the device structure so it + * can be looked up later + */ + fwnode_handle_get(child); + phy->mdio.dev.fwnode = child; + + /* All data is now stored in the phy struct; + * register it + */ + rc = phy_device_register(phy); + if (rc) { + fwnode_handle_put(child); + return rc; + } + + dev_dbg(&mdio->dev, "registered phy %p fwnode at address %i\n", + child, addr); + return 0; +} +EXPORT_SYMBOL(fwnode_mdiobus_phy_device_register); + +int fwnode_mdiobus_register_phy(struct mii_bus *bus, + struct fwnode_handle *child, u32 addr) +{ + struct mii_timestamper *mii_ts = NULL; + struct phy_device *phy; + bool is_c45 = false; + u32 phy_id; + int rc; + + mii_ts = fwnode_find_mii_timestamper(child); + if (IS_ERR(mii_ts)) + return PTR_ERR(mii_ts); + + rc = fwnode_property_match_string(child, "compatible", + "ethernet-phy-ieee802.3-c45"); + if (rc >= 0) + is_c45 = true; + + if (is_c45 || fwnode_get_phy_id(child, &phy_id)) + phy = get_phy_device(bus, addr, is_c45); + else + phy = phy_device_create(bus, addr, phy_id, 0, NULL); + if (IS_ERR(phy)) { + unregister_mii_timestamper(mii_ts); + return PTR_ERR(phy); + } + + if (is_acpi_node(child)) { + phy->irq = bus->irq[addr]; + + /* Associate the fwnode with the device structure so it + * can be looked up later. + */ + phy->mdio.dev.fwnode = child; + + /* All data is now stored in the phy struct, so register it */ + rc = phy_device_register(phy); + if (rc) { + phy_device_free(phy); + fwnode_handle_put(phy->mdio.dev.fwnode); + return rc; + } + } else if (is_of_node(child)) { + rc = fwnode_mdiobus_phy_device_register(bus, phy, child, addr); + if (rc) { + unregister_mii_timestamper(mii_ts); + phy_device_free(phy); + return rc; + } + } + + /* phy->mii_ts may already be defined by the PHY driver. A + * mii_timestamper probed via the device tree will still have + * precedence. + */ + if (mii_ts) + phy->mii_ts = mii_ts; + return 0; +} +EXPORT_SYMBOL(fwnode_mdiobus_register_phy); diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index d73c0570f19c..9b1cadfd465d 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -32,65 +32,12 @@ static int of_get_phy_id(struct device_node *device, u32 *phy_id) return fwnode_get_phy_id(of_fwnode_handle(device), phy_id); } -static struct mii_timestamper *of_find_mii_timestamper(struct device_node *node) -{ - struct of_phandle_args arg; - int err; - - err = of_parse_phandle_with_fixed_args(node, "timestamper", 1, 0, &arg); - - if (err == -ENOENT) - return NULL; - else if (err) - return ERR_PTR(err); - - if (arg.args_count != 1) - return ERR_PTR(-EINVAL); - - return register_mii_timestamper(arg.np, arg.args[0]); -} - int of_mdiobus_phy_device_register(struct mii_bus *mdio, struct phy_device *phy, - struct device_node *child, u32 addr) + struct device_node *child, u32 addr) { - int rc; - - rc = of_irq_get(child, 0); - if (rc == -EPROBE_DEFER) - return rc; - - if (rc > 0) { - phy->irq = rc; - mdio->irq[addr] = rc; - } else { - phy->irq = mdio->irq[addr]; - } - - if (of_property_read_bool(child, "broken-turn-around")) - mdio->phy_ignore_ta_mask |= 1 << addr; - - of_property_read_u32(child, "reset-assert-us", - &phy->mdio.reset_assert_delay); - of_property_read_u32(child, "reset-deassert-us", - &phy->mdio.reset_deassert_delay); - - /* Associate the OF node with the device structure so it - * can be looked up later */ - of_node_get(child); - phy->mdio.dev.of_node = child; - phy->mdio.dev.fwnode = of_fwnode_handle(child); - - /* All data is now stored in the phy struct; - * register it */ - rc = phy_device_register(phy); - if (rc) { - of_node_put(child); - return rc; - } - - dev_dbg(&mdio->dev, "registered phy %pOFn at address %i\n", - child, addr); - return 0; + return fwnode_mdiobus_phy_device_register(mdio, phy, + of_fwnode_handle(child), + addr); } EXPORT_SYMBOL(of_mdiobus_phy_device_register); diff --git a/include/linux/fwnode_mdio.h b/include/linux/fwnode_mdio.h new file mode 100644 index 000000000000..faf603c48c86 --- /dev/null +++ b/include/linux/fwnode_mdio.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * FWNODE helper for the MDIO (Ethernet PHY) API + */ + +#ifndef __LINUX_FWNODE_MDIO_H +#define __LINUX_FWNODE_MDIO_H + +#include + +#if IS_ENABLED(CONFIG_FWNODE_MDIO) +int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, + struct phy_device *phy, + struct fwnode_handle *child, u32 addr); + +int fwnode_mdiobus_register_phy(struct mii_bus *bus, + struct fwnode_handle *child, u32 addr); + +#else /* CONFIG_FWNODE_MDIO */ +int fwnode_mdiobus_phy_device_register(struct mii_bus *mdio, + struct phy_device *phy, + struct fwnode_handle *child, u32 addr) +{ + return -EINVAL; +} + +static inline int fwnode_mdiobus_register_phy(struct mii_bus *bus, + struct fwnode_handle *child, + u32 addr) +{ + return -EINVAL; +} +#endif + +#endif /* __LINUX_FWNODE_MDIO_H */ From patchwork Thu Jun 10 16:39:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A14CC48BD1 for ; Thu, 10 Jun 2021 16:42:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D8F1613DD for ; Thu, 10 Jun 2021 16:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231794AbhFJQn5 (ORCPT ); Thu, 10 Jun 2021 12:43:57 -0400 Received: from mail-ed1-f42.google.com ([209.85.208.42]:36809 "EHLO mail-ed1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231620AbhFJQnh (ORCPT ); Thu, 10 Jun 2021 12:43:37 -0400 Received: by mail-ed1-f42.google.com with SMTP id w21so33743221edv.3; Thu, 10 Jun 2021 09:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cGYQZXC/NhPdwOiaUJSomKVZ7Ulae3WO3fpWEzXcO0k=; b=t+siAVMT3mT+Hwr7+PWLzFq6stbRRymsCcY5eDwBodVZr4+r2ylFc5CCcnRDzreu5W mOry5eFoT/Prr/AifIUIeIRVOD6m9Z6Y8k94R15vW+qROBDcWWv9SRwAij5Mtwxua44H 0ZFT2+96It96Ro1pocjcfTJMOBscl1FSzki/9KlqGNxyrLhF+aK8pfpND1upUUaJgZ+r LEOUCPD2LDf2FKZa1iyk2mSzCChZFWH7OappwPFw3MhRvQY/95l7gQDO3v6fY+C+BJwY VwWw3kSy50leyhCLYXnLxIFTitsxQtxC3c/pj7ThcEXCmb72xQNqFI9/IwGC8HOUA+ol +wVg== 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:mime-version:content-transfer-encoding; bh=cGYQZXC/NhPdwOiaUJSomKVZ7Ulae3WO3fpWEzXcO0k=; b=HVU/v8N1MMudGPvZqxOHF7oxDeG1EkuQhcJMi/hVIHENJ2Q2ffOmGn9aeasWSNzL9K CIBYNCJKJs+OR4LhQbPKUXNa3MMG9U4S8cc9FuStI7z5/BKrfve1hEEnD1/tcwAqu0o/ 4X9BFrMQwNWX18BFH1jvZIbu1TXPKeQwB7bFNdygOoukMnIgDkkc9QDRL2m0qsJBIwx8 yrBOoQhD39zIO9LGTfXT7gdOd5eBQwzzJxkfK4kiRciYIgi+RbbSAm6caMc6hfjnJSZS t9VqURWMJwIzWPsY4zKIkZD4Ni0by+H2zbvH/RWiEaD67/kxiA4n8dPc8Y8RBIkqnK7X B1vQ== X-Gm-Message-State: AOAM531HeBLO6ezGEgT0nEba/GEwp6ZPVJyiDJ/Q95UC7IvGNBleODnY 9IobK9WIQSxaQevRodZBStY= X-Google-Smtp-Source: ABdhPJxBPcPq2wh+9DGPniGVRDMxk7syTNqaJCS8A6g1PtD6sWxq+CLSZft5xX4PCum1ayk6wdY5cA== X-Received: by 2002:aa7:da8c:: with SMTP id q12mr358069eds.368.1623343234121; Thu, 10 Jun 2021 09:40:34 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:33 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 09/15] of: mdio: Refactor of_mdiobus_register_phy() Date: Thu, 10 Jun 2021 19:39:11 +0300 Message-Id: <20210610163917.4138412-10-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Refactor of_mdiobus_register_phy() to use fwnode_mdiobus_register_phy(). Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: - include fwnode_mdio.h Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/mdio/of_mdio.c | 39 ++------------------------------------ 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 9b1cadfd465d..8744b1e1c2b1 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -44,43 +45,7 @@ EXPORT_SYMBOL(of_mdiobus_phy_device_register); static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child, u32 addr) { - struct mii_timestamper *mii_ts; - struct phy_device *phy; - bool is_c45; - int rc; - u32 phy_id; - - mii_ts = of_find_mii_timestamper(child); - if (IS_ERR(mii_ts)) - return PTR_ERR(mii_ts); - - is_c45 = of_device_is_compatible(child, - "ethernet-phy-ieee802.3-c45"); - - if (!is_c45 && !of_get_phy_id(child, &phy_id)) - phy = phy_device_create(mdio, addr, phy_id, 0, NULL); - else - phy = get_phy_device(mdio, addr, is_c45); - if (IS_ERR(phy)) { - unregister_mii_timestamper(mii_ts); - return PTR_ERR(phy); - } - - rc = of_mdiobus_phy_device_register(mdio, phy, child, addr); - if (rc) { - unregister_mii_timestamper(mii_ts); - phy_device_free(phy); - return rc; - } - - /* phy->mii_ts may already be defined by the PHY driver. A - * mii_timestamper probed via the device tree will still have - * precedence. - */ - if (mii_ts) - phy->mii_ts = mii_ts; - - return 0; + return fwnode_mdiobus_register_phy(mdio, of_fwnode_handle(child), addr); } static int of_mdiobus_register_device(struct mii_bus *mdio, From patchwork Thu Jun 10 16:39:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02F06C48BD1 for ; Thu, 10 Jun 2021 16:42:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD2A6613F8 for ; Thu, 10 Jun 2021 16:42:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231937AbhFJQoT (ORCPT ); Thu, 10 Jun 2021 12:44:19 -0400 Received: from mail-ej1-f45.google.com ([209.85.218.45]:36688 "EHLO mail-ej1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231626AbhFJQnr (ORCPT ); Thu, 10 Jun 2021 12:43:47 -0400 Received: by mail-ej1-f45.google.com with SMTP id a11so227553ejf.3; Thu, 10 Jun 2021 09:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WYaGnISu1YfOE/7UiWGOnu7UNyMRUmG6vqNEYiYQnuw=; b=oOrrc83d8TfIoeXmdiRoiQg6glDODRsfbpbGcLCinVvDPPg4EwsRnclPpJGstuwomD Loe/4iW8ArsQULGi5DaAxbHMvjJ13BPDnbOvZFsEIy2ZPqa51dMbtxYcG4fAawlfR5Jw gKTx7B4SvmEIZY4c0R/PpJdoCQghcoPfzZVhxZ7hdlYVA+oiAlarlUZJGfRfK2IWs1Td UZzn1wJtbaW8kK82d/ly2IcvdtRmbDm2YUKBIz3x6xvsxQcsRVk/ALJGw+GQysJYmabr kg3GsAnLtefhEN7Mwo92YkIbiYiaolH7vbQ77mxVB7Hn9LPpR2OIxhHZvc1a34OC2264 AXQg== 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:mime-version:content-transfer-encoding; bh=WYaGnISu1YfOE/7UiWGOnu7UNyMRUmG6vqNEYiYQnuw=; b=tUixhB4BaaXSXiKsn+NiKFjlDVpgxidpzcGY4SC6jpNLQSITaHvgYlLU/yBhct4ZKK y/AkoXfHf+DFDPgbAi6nV6tvJGZxVDsHYoWNhE0gcvmL51H4sr1IbKimphu0TqyTaNcT MugTHXVjKPV3KBI8Dy0XmCjzgdYPOUIPReBym5bU0NNwFcNAMqsl0aVX3FCNV8/O8TOZ MppJfESDO+6xINqwuM+LBUiHt7SG/I9oEMa1cUanjs7JbUD+g7QYSWhh0w/2C7F2T+3r A0emKUlewr9vSYJMu3hpDPzx/FSKvNRMqNn3fH4fYhAu7NrfZI3rkT39si8ciN1c1Ldx ZeqQ== X-Gm-Message-State: AOAM5319UDdUvzCAUiJIg47d+eivf5FlUIGvzSAUbCvOi6KxVq7WRIoQ 9ewHvJ/TJ+rKt/Rd04Rihnw= X-Google-Smtp-Source: ABdhPJwO+2kntI2vKAnq2EhOGIoStYyq0+AsQrrHaXncx6UCvB7nJNv9I6rRDQY/bNNB9TrVGooJag== X-Received: by 2002:a17:906:714d:: with SMTP id z13mr515845ejj.48.1623343236264; Thu, 10 Jun 2021 09:40:36 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:35 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 10/15] ACPI: utils: Introduce acpi_get_local_address() Date: Thu, 10 Jun 2021 19:39:12 +0300 Message-Id: <20210610163917.4138412-11-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Introduce a wrapper around the _ADR evaluation. Signed-off-by: Calvin Johnson Reviewed-by: Andy Shevchenko Signed-off-by: Ioana Ciornei Acked-by: Rafael J. Wysocki --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: - Replace fwnode_get_id() with acpi_get_local_address() Changes in v4: - Improve code structure to handle all cases Changes in v3: - Modified to retrieve reg property value for ACPI as well - Resolved compilation issue with CONFIG_ACPI = n - Added more info into documentation drivers/acpi/utils.c | 14 ++++++++++++++ include/linux/acpi.h | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 3b54b8fd7396..e7ddd281afff 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -277,6 +277,20 @@ acpi_evaluate_integer(acpi_handle handle, EXPORT_SYMBOL(acpi_evaluate_integer); +int acpi_get_local_address(acpi_handle handle, u32 *addr) +{ + unsigned long long adr; + acpi_status status; + + status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &adr); + if (ACPI_FAILURE(status)) + return -ENODATA; + + *addr = (u32)adr; + return 0; +} +EXPORT_SYMBOL(acpi_get_local_address); + acpi_status acpi_evaluate_reference(acpi_handle handle, acpi_string pathname, diff --git a/include/linux/acpi.h b/include/linux/acpi.h index c60745f657e9..6ace3a0f1415 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -710,6 +710,8 @@ static inline u64 acpi_arch_get_root_pointer(void) } #endif +int acpi_get_local_address(acpi_handle handle, u32 *addr); + #else /* !CONFIG_ACPI */ #define acpi_disabled 1 @@ -965,6 +967,11 @@ static inline struct acpi_device *acpi_resource_consumer(struct resource *res) return NULL; } +static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) +{ + return -ENODEV; +} + #endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC From patchwork Thu Jun 10 16:39:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 975DDC48BD1 for ; Thu, 10 Jun 2021 16:42:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85562613E1 for ; Thu, 10 Jun 2021 16:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbhFJQoY (ORCPT ); Thu, 10 Jun 2021 12:44:24 -0400 Received: from mail-ej1-f46.google.com ([209.85.218.46]:45735 "EHLO mail-ej1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbhFJQnu (ORCPT ); Thu, 10 Jun 2021 12:43:50 -0400 Received: by mail-ej1-f46.google.com with SMTP id k7so161147ejv.12; Thu, 10 Jun 2021 09:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rRvwfKkukgnoScSahSMFZLRC5h4rW9MQ8oHY/dsa0CU=; b=aHI+Pj3SA0nCldSK7rXsO6hP+jGwaE6IW07XrKEEHSkDNew4YG2JTnjt27+2ZAPRnf RC8KXMTxfHm6qMHOVzaiVuTg1R+hy32Ms1HYer+OLcBUSksLHYvsXfNIMBW/bSojiIrS j6i9lzw1mqdS9KfllULTePyca9ec50Vqvv8K3LSpeI/TyvB1qD4SL2RKnMP8fLFWlmP5 HmN9oeWoBBr7l7edk8czk7jnUH+4sd/3KHzB4P73IJcWVtjImsWqfXX4EI/AlvjXR7JS Sy0wgnCFXcROo2l1ojBTXUJoL9V3GaN1kQa+2TQZP+h3gb7wEuULFBaana/6rE/tg9kK 9GNQ== 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:mime-version:content-transfer-encoding; bh=rRvwfKkukgnoScSahSMFZLRC5h4rW9MQ8oHY/dsa0CU=; b=JY31oBIx2ylsTvIUVIEKLdsKwuzAzfGDKArnugDAYfO9QpFLpCeGOToRiNB9+eMI/n m3kr3dVuggNB3bXd2/S9Ax1l3CDfpA3cNV84R0uMlHpU2c6Uzb25hgzHWbhJjNcTCbq7 X0nF+e85nEFDkEh1K/UixGej1IebKkhAN3uoQ0kKwaHuE4Hnv19tf6qXAgoabamuVU6s 37vqntUuPUE8O/RFyi4xlfDPn9Vnc7+LnUzaRQNjGwM2Ev9NOI1pgPsUGYWClXUX0NvF 6MpGhHbGGsByII/FKgFNDdW9/UQ13+W95ygTTGEIsvU9tS0eKitChWd1StcT1qoBrmmr z9GA== X-Gm-Message-State: AOAM532meHB67F27gr/PmOaA70kvI0kPMQ5bvmd/SPlJCoudHB2aLSJI ZxaYaJ3wrpDPZJWKZxebu44= X-Google-Smtp-Source: ABdhPJz4YWRBuxeFIQcGWxDtMKhJvdtWzIe7Vy6kryVThIQL7lMptpfJil7bBVFS+oUTz/kkBJ+dkg== X-Received: by 2002:a17:906:f889:: with SMTP id lg9mr509833ejb.82.1623343238190; Thu, 10 Jun 2021 09:40:38 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:37 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 11/15] net: mdio: Add ACPI support code for mdio Date: Thu, 10 Jun 2021 19:39:13 +0300 Message-Id: <20210610163917.4138412-12-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Define acpi_mdiobus_register() to Register mii_bus and create PHYs for each ACPI child node. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei Acked-by: Rafael J. Wysocki --- Changes in v8: None Changes in v7: - Include headers directly used in acpi_mdio.c Changes in v6: - use GENMASK() and ACPI_COMPANION_SET() - some cleanup - remove unwanted header inclusion Changes in v5: - add missing MODULE_LICENSE() - replace fwnode_get_id() with OF and ACPI function calls Changes in v4: None Changes in v3: None Changes in v2: None MAINTAINERS | 1 + drivers/net/mdio/Kconfig | 7 +++++ drivers/net/mdio/Makefile | 1 + drivers/net/mdio/acpi_mdio.c | 56 ++++++++++++++++++++++++++++++++++++ include/linux/acpi_mdio.h | 26 +++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 drivers/net/mdio/acpi_mdio.c create mode 100644 include/linux/acpi_mdio.h diff --git a/MAINTAINERS b/MAINTAINERS index e8f8b6c33a51..2172f594be8f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6811,6 +6811,7 @@ F: Documentation/devicetree/bindings/net/mdio* F: Documentation/devicetree/bindings/net/qca,ar803x.yaml F: Documentation/networking/phy.rst F: drivers/net/mdio/ +F: drivers/net/mdio/acpi_mdio.c F: drivers/net/mdio/fwnode_mdio.c F: drivers/net/mdio/of_mdio.c F: drivers/net/pcs/ diff --git a/drivers/net/mdio/Kconfig b/drivers/net/mdio/Kconfig index 422e9e042a3c..99a6c13a11af 100644 --- a/drivers/net/mdio/Kconfig +++ b/drivers/net/mdio/Kconfig @@ -34,6 +34,13 @@ config OF_MDIO help OpenFirmware MDIO bus (Ethernet PHY) accessors +config ACPI_MDIO + def_tristate PHYLIB + depends on ACPI + depends on PHYLIB + help + ACPI MDIO bus (Ethernet PHY) accessors + if MDIO_BUS config MDIO_DEVRES diff --git a/drivers/net/mdio/Makefile b/drivers/net/mdio/Makefile index 2e6813c709eb..15f8dc4042ce 100644 --- a/drivers/net/mdio/Makefile +++ b/drivers/net/mdio/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux MDIO bus drivers +obj-$(CONFIG_ACPI_MDIO) += acpi_mdio.o obj-$(CONFIG_FWNODE_MDIO) += fwnode_mdio.o obj-$(CONFIG_OF_MDIO) += of_mdio.o diff --git a/drivers/net/mdio/acpi_mdio.c b/drivers/net/mdio/acpi_mdio.c new file mode 100644 index 000000000000..60a86e3fc246 --- /dev/null +++ b/drivers/net/mdio/acpi_mdio.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ACPI helpers for the MDIO (Ethernet PHY) API + * + * This file provides helper functions for extracting PHY device information + * out of the ACPI ASL and using it to populate an mii_bus. + */ + +#include +#include +#include +#include +#include +#include +#include + +MODULE_AUTHOR("Calvin Johnson "); +MODULE_LICENSE("GPL"); + +/** + * acpi_mdiobus_register - Register mii_bus and create PHYs from the ACPI ASL. + * @mdio: pointer to mii_bus structure + * @fwnode: pointer to fwnode of MDIO bus. + * + * This function registers the mii_bus structure and registers a phy_device + * for each child node of @fwnode. + */ +int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode) +{ + struct fwnode_handle *child; + u32 addr; + int ret; + + /* Mask out all PHYs from auto probing. */ + mdio->phy_mask = GENMASK(31, 0); + ret = mdiobus_register(mdio); + if (ret) + return ret; + + ACPI_COMPANION_SET(&mdio->dev, to_acpi_device_node(fwnode)); + + /* Loop over the child nodes and register a phy_device for each PHY */ + fwnode_for_each_child_node(fwnode, child) { + ret = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &addr); + if (ret || addr >= PHY_MAX_ADDR) + continue; + + ret = fwnode_mdiobus_register_phy(mdio, child, addr); + if (ret == -ENODEV) + dev_err(&mdio->dev, + "MDIO device at address %d is missing.\n", + addr); + } + return 0; +} +EXPORT_SYMBOL(acpi_mdiobus_register); diff --git a/include/linux/acpi_mdio.h b/include/linux/acpi_mdio.h new file mode 100644 index 000000000000..0a24ab7cb66f --- /dev/null +++ b/include/linux/acpi_mdio.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * ACPI helper for the MDIO (Ethernet PHY) API + */ + +#ifndef __LINUX_ACPI_MDIO_H +#define __LINUX_ACPI_MDIO_H + +#include + +#if IS_ENABLED(CONFIG_ACPI_MDIO) +int acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode); +#else /* CONFIG_ACPI_MDIO */ +static inline int +acpi_mdiobus_register(struct mii_bus *mdio, struct fwnode_handle *fwnode) +{ + /* + * Fall back to mdiobus_register() function to register a bus. + * This way, we don't have to keep compat bits around in drivers. + */ + + return mdiobus_register(mdio); +} +#endif + +#endif /* __LINUX_ACPI_MDIO_H */ From patchwork Thu Jun 10 16:39:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85D10C48BE6 for ; Thu, 10 Jun 2021 16:42:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70155613E1 for ; Thu, 10 Jun 2021 16:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231923AbhFJQoQ (ORCPT ); Thu, 10 Jun 2021 12:44:16 -0400 Received: from mail-ej1-f52.google.com ([209.85.218.52]:41505 "EHLO mail-ej1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhFJQnp (ORCPT ); Thu, 10 Jun 2021 12:43:45 -0400 Received: by mail-ej1-f52.google.com with SMTP id ho18so191134ejc.8; Thu, 10 Jun 2021 09:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pjkqTURZcurLq7jUGUIyX7EynFbeWen/UMWsVgV3fKg=; b=cTpMc8jCE9xA8gcBZpV/laGcmSvfQK3/zLSvJRRa/LuR7xxJE4gn15+M/0/IFgg4AI fz9Hex/ZLp8rbn92FXt2tapsLYWXHsUl4+YjhJTOsBYlnqSQZdR4N4bJy3ad7JZo1sfO p0jpAg49x53M7TMyO6fE4DPL3r8iEbCkDbvZdoz2sj7ExMINwDyHcnqfMNfnNfhFgkAI 5NCXAFP/QA3+Hdx/VEmbB/MtxWuTewaxzpbSWUH2JkvNnsmnQhQ3irzYmhyyKa86mPTZ XChXStoNtCnPimL9DRzsZ08c/JmstHLShtpu+ITwhbHy9wIGqxKsIRv7QpCLxIAQ+mIU cROA== 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:mime-version:content-transfer-encoding; bh=pjkqTURZcurLq7jUGUIyX7EynFbeWen/UMWsVgV3fKg=; b=Vlup4JTxbwUHdyyxlAca6Yew9tTfUOiT36J7HV4tYM4CPu6bkUdL5RTXr8IOkLQSF9 I12n+dWA1KcCscR2JbIaZ9a8f61Xqz9UW3Au91nEfy5Q1IroTYgRmIRWTsf/eDm7baZ5 nP0RXxEgtI7WEfs61KjESK3hHQ3o13aYcs6QbBVWlw2OcXRFUhy1dVu0TUeAItssQbNU TvV63VWScjXWVggEn5fZk6mzcQLnV393sR1dO3u9EfUVFjEm9TMxm8zi4zaSJ9RWRfJR leD5ayK5uAIvqekT1lF5Ln4ytv7UDW0evawovlNaUoHK1j4aCidlcXSAcWgizZIfkKHl xzLg== X-Gm-Message-State: AOAM532xD8kp0ORr3oXuxS72MnsRq25g1CS1IbQQlZ3aFRI0phZLRnuP DNKgnB3egt+LFJWpp/Resmo= X-Google-Smtp-Source: ABdhPJyDIC3eLsbUKMaH2OPVPIW4L3pqRfdNlX77J3xTS/RFImBYy9jKRfsXYFs6JHtEUFOToqBLlQ== X-Received: by 2002:a17:906:82c3:: with SMTP id a3mr477659ejy.230.1623343240314; Thu, 10 Jun 2021 09:40:40 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:40 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 12/15] net/fsl: Use [acpi|of]_mdiobus_register Date: Thu, 10 Jun 2021 19:39:14 +0300 Message-Id: <20210610163917.4138412-13-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Depending on the device node type, call the specific OF or ACPI mdiobus_register function. Note: For both ACPI and DT cases, endianness of MDIO controller need to be specified using "little-endian" property. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: - Directly call the OF or ACPI variants of registering the MDIO bus. This is needed because the fwnode_mdio.c module should only implement features which can be achieved without going back to the OF/ACPI variants. Without this restrictions we directly end up in a dependency cycle: of_mdio -> fwnode_mdio -> of_mdio. - Changed the commit title since the fwnode_mdiobus_register() is no longer available Changes in v7: - Include fwnode_mdio.h - Alphabetically sort header inclusions Changes in v6: None Changes in v5: None Changes in v4: - Cleanup xgmac_mdio_probe() Changes in v3: - Avoid unnecessary line removal - Remove unused inclusion of acpi.h Changes in v2: None drivers/net/ethernet/freescale/xgmac_mdio.c | 30 ++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/freescale/xgmac_mdio.c b/drivers/net/ethernet/freescale/xgmac_mdio.c index bfa2826c5545..0b68852379da 100644 --- a/drivers/net/ethernet/freescale/xgmac_mdio.c +++ b/drivers/net/ethernet/freescale/xgmac_mdio.c @@ -2,6 +2,7 @@ * QorIQ 10G MDIO Controller * * Copyright 2012 Freescale Semiconductor, Inc. + * Copyright 2021 NXP * * Authors: Andy Fleming * Timur Tabi @@ -11,15 +12,17 @@ * kind, whether express or implied. */ -#include -#include +#include +#include #include -#include -#include +#include #include +#include #include -#include #include +#include +#include +#include /* Number of microseconds to wait for a register to respond */ #define TIMEOUT 1000 @@ -243,10 +246,10 @@ static int xgmac_mdio_read(struct mii_bus *bus, int phy_id, int regnum) static int xgmac_mdio_probe(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node; - struct mii_bus *bus; - struct resource *res; + struct fwnode_handle *fwnode; struct mdio_fsl_priv *priv; + struct resource *res; + struct mii_bus *bus; int ret; /* In DPAA-1, MDIO is one of the many FMan sub-devices. The FMan @@ -279,13 +282,22 @@ static int xgmac_mdio_probe(struct platform_device *pdev) goto err_ioremap; } + /* For both ACPI and DT cases, endianness of MDIO controller + * needs to be specified using "little-endian" property. + */ priv->is_little_endian = device_property_read_bool(&pdev->dev, "little-endian"); priv->has_a011043 = device_property_read_bool(&pdev->dev, "fsl,erratum-a011043"); - ret = of_mdiobus_register(bus, np); + fwnode = pdev->dev.fwnode; + if (is_of_node(fwnode)) + ret = of_mdiobus_register(bus, to_of_node(fwnode)); + else if (is_acpi_node(fwnode)) + ret = acpi_mdiobus_register(bus, fwnode); + else + ret = -EINVAL; if (ret) { dev_err(&pdev->dev, "cannot register MDIO bus\n"); goto err_registration; From patchwork Thu Jun 10 16:39:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9205C47094 for ; Thu, 10 Jun 2021 16:41:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC67A613DD for ; Thu, 10 Jun 2021 16:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231482AbhFJQnK (ORCPT ); Thu, 10 Jun 2021 12:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbhFJQmz (ORCPT ); Thu, 10 Jun 2021 12:42:55 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2200EC0617AF; Thu, 10 Jun 2021 09:40:44 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id ci15so174042ejc.10; Thu, 10 Jun 2021 09:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OP4A8JlGO2Dl0G4k2AQZx6BKD9WAdkVxy5GnYXxTceM=; b=Haz8Rvxk0LJKNvGhRutlpDPeXm316Wy2zEnVdHdcnw51FRnoU2177kL99J02Los+Mj D28c1hMiJ+wR6LBiQ5VLY4MKmeuwFKD0BCQUj2CjVTxmAEyxj8JWfObyrC2GkNZbehW2 u+LmOef1Bjiy01qhpI/epZ3AnTRKBnflmlKBqUkCbk1wr7bXsGoW0zqz48ufww0HlOXZ 7cPj8S27hzgp7wy1AoSnE+b4PlF8OFj+eR8QnczREi5nRuuiBzI4YUAjucjNTn7N97ck 737yYA1JcjMJ2CwXGVrnaddKR234jKwm5nxiw45pUoagy/fObrpoAeDEWxb94eG8r6SC oM/w== 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:mime-version:content-transfer-encoding; bh=OP4A8JlGO2Dl0G4k2AQZx6BKD9WAdkVxy5GnYXxTceM=; b=Ag08yXuqvt9dmhXmcjj1ouFfGFjeH7Duv2i2X9tKW4hdJB2dbhs8MN5TIkUln7AjRL B4/d7+4z1/eIL8r1o0RmUgV9SfLZvhDGxkvxrUf6uUWaPSfeQBdfVIbpCxPfcE3fw9Pk apy2j6bxtJ7nB2CFXUm+G7le9WI4tq5caFGI/lxUaYsVLxezti7TSIa3g3iC4GLp9Ykq 3+w/xmbMx/W325bWF18Vlubnt4UpTtuyXAARBCf2DMFgDWhb8ndJ2XlGYSjNnoUMSvls kRdvqk+YL+h1Kpv4hQ0JPRJXXFuHd4kBxxpMoyR4FZNSnkaJIOd+TlPknN9OOPxg2WsB /+rw== X-Gm-Message-State: AOAM533ibhIIRTFkCKjqn4FYV5VcMj+QmSs0pAl8xMGXVmPN0dpTYIPM tcYFVmmivXo7PRqX36BgaBw= X-Google-Smtp-Source: ABdhPJzZW5gzrfQuuDI152iey6UWe7uJ1Wa+K7+hykGv7xDljoQY+QU7h5SfzfJ6fJ1/O8f4Hiz+kQ== X-Received: by 2002:a17:906:7052:: with SMTP id r18mr445919ejj.449.1623343242563; Thu, 10 Jun 2021 09:40:42 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:42 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 13/15] net: phylink: introduce phylink_fwnode_phy_connect() Date: Thu, 10 Jun 2021 19:39:15 +0300 Message-Id: <20210610163917.4138412-14-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Define phylink_fwnode_phy_connect() to connect phy specified by a fwnode to a phylink instance. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: None Changes in v6: - remove OF check for fixed-link Changes in v5: None Changes in v4: - call phy_device_free() before returning Changes in v3: None Changes in v2: None drivers/net/phy/phylink.c | 54 +++++++++++++++++++++++++++++++++++++++ include/linux/phylink.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 96d8e88b4e46..9cc0f69faafe 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -5,6 +5,7 @@ * * Copyright (C) 2015 Russell King */ +#include #include #include #include @@ -1125,6 +1126,59 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn, } EXPORT_SYMBOL_GPL(phylink_of_phy_connect); +/** + * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode. + * @pl: a pointer to a &struct phylink returned from phylink_create() + * @fwnode: a pointer to a &struct fwnode_handle. + * @flags: PHY-specific flags to communicate to the PHY device driver + * + * Connect the phy specified @fwnode to the phylink instance specified + * by @pl. + * + * Returns 0 on success or a negative errno. + */ +int phylink_fwnode_phy_connect(struct phylink *pl, + struct fwnode_handle *fwnode, + u32 flags) +{ + struct fwnode_handle *phy_fwnode; + struct phy_device *phy_dev; + int ret; + + /* Fixed links and 802.3z are handled without needing a PHY */ + if (pl->cfg_link_an_mode == MLO_AN_FIXED || + (pl->cfg_link_an_mode == MLO_AN_INBAND && + phy_interface_mode_is_8023z(pl->link_interface))) + return 0; + + phy_fwnode = fwnode_get_phy_node(fwnode); + if (IS_ERR(phy_fwnode)) { + if (pl->cfg_link_an_mode == MLO_AN_PHY) + return -ENODEV; + return 0; + } + + phy_dev = fwnode_phy_find_device(phy_fwnode); + /* We're done with the phy_node handle */ + fwnode_handle_put(phy_fwnode); + if (!phy_dev) + return -ENODEV; + + ret = phy_attach_direct(pl->netdev, phy_dev, flags, + pl->link_interface); + if (ret) { + phy_device_free(phy_dev); + return ret; + } + + ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface); + if (ret) + phy_detach(phy_dev); + + return ret; +} +EXPORT_SYMBOL_GPL(phylink_fwnode_phy_connect); + /** * phylink_disconnect_phy() - disconnect any PHY attached to the phylink * instance. diff --git a/include/linux/phylink.h b/include/linux/phylink.h index fd2acfd9b597..afb3ded0b691 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -441,6 +441,9 @@ void phylink_destroy(struct phylink *); int phylink_connect_phy(struct phylink *, struct phy_device *); int phylink_of_phy_connect(struct phylink *, struct device_node *, u32 flags); +int phylink_fwnode_phy_connect(struct phylink *pl, + struct fwnode_handle *fwnode, + u32 flags); void phylink_disconnect_phy(struct phylink *); void phylink_mac_change(struct phylink *, bool up); From patchwork Thu Jun 10 16:39:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2071C47094 for ; Thu, 10 Jun 2021 16:42:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFF02613F1 for ; Thu, 10 Jun 2021 16:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231977AbhFJQoo (ORCPT ); Thu, 10 Jun 2021 12:44:44 -0400 Received: from mail-ed1-f50.google.com ([209.85.208.50]:34439 "EHLO mail-ed1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbhFJQn5 (ORCPT ); Thu, 10 Jun 2021 12:43:57 -0400 Received: by mail-ed1-f50.google.com with SMTP id cb9so33856002edb.1; Thu, 10 Jun 2021 09:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GEHy85q0SvH7LpLvuhvoCSHDRdNVkwU8DE0B2plpG7c=; b=WSAtPKodO4Z5ZkaBgYVJo0XDPRsYxK6DQU3oyGwYxiknYsEJO6EXFxSmAmXtKLoFWA 7NzUAvAhZqrxtSX9jO5VTlZegCJMMNP12jmANjKyTXxNQk0FN69kwgaD/3vG4NBvLeec v3SA60KAvFEizQPGyrjyfB8WWd01y57umXfQjRRgY2xc0GiR8olqpqHJMaH7qrR6NwZ7 R7o4FzhW6I51C/Z7YpcAY/y0g1uS4jgl1DWcY5jV903rg03J3MDbx/iDyALUIj2DBxji k603sVkxt834meOvbcoKzbA3Njp1KgJMbb4vpEQM3BUQ/+f8HczLwwH78xUeseoH/63y F4gA== 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:mime-version:content-transfer-encoding; bh=GEHy85q0SvH7LpLvuhvoCSHDRdNVkwU8DE0B2plpG7c=; b=LSvqoVHY7hAjforSu5iNZ2yaOPMZcbwzHqJs8xg6uYQ8ezjhQtnyzjw2IGZ8uGuDDb 0pJbWqnB0co6x+frlzqdiBFeCNPu94q5qr/nfJqmbuJq1kC5bcR6BaYTWVTGIqemm7EF ca8UNDe53ZsOr4dgDB2vft2HPVnEIx3xK0BLYol3RbunS7Xlmqf48S+kk3x5lyQpbMFX QAeBmMUnKeT5WjTDQlWEomB1VGQVLcuG9Q7tB7L29Onz3w5UboNAUJlaRYnH1fkjiKaN Ooobff86fsWyLXkQhH+lQzK29/qxB4zGCfwH9NYVwIrRatJDBp8NRlDN22JSk1qx1R7q QSDQ== X-Gm-Message-State: AOAM530J3faB6utOsnnaDiXjkAxLyLU8GgkCWoTmYNraW14HqJLfGap9 IKk9jilHKUzBux8omuLxg1A= X-Google-Smtp-Source: ABdhPJwQxi77NYWZzwyeBZ6JRxE2Ln77b8EMAjeDOYvdd+ppU/Jd5pu9ZLv4ODCvaH12uzIOI7YheQ== X-Received: by 2002:aa7:cc87:: with SMTP id p7mr379277edt.82.1623343244520; Thu, 10 Jun 2021 09:40:44 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:44 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 14/15] net: phylink: Refactor phylink_of_phy_connect() Date: Thu, 10 Jun 2021 19:39:16 +0300 Message-Id: <20210610163917.4138412-15-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Refactor phylink_of_phy_connect() to use phylink_fwnode_phy_connect(). Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei --- Changes in v8: None Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/phy/phylink.c | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 9cc0f69faafe..bb9eeb74f70a 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1085,44 +1085,7 @@ EXPORT_SYMBOL_GPL(phylink_connect_phy); int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn, u32 flags) { - struct device_node *phy_node; - struct phy_device *phy_dev; - int ret; - - /* Fixed links and 802.3z are handled without needing a PHY */ - if (pl->cfg_link_an_mode == MLO_AN_FIXED || - (pl->cfg_link_an_mode == MLO_AN_INBAND && - phy_interface_mode_is_8023z(pl->link_interface))) - return 0; - - phy_node = of_parse_phandle(dn, "phy-handle", 0); - if (!phy_node) - phy_node = of_parse_phandle(dn, "phy", 0); - if (!phy_node) - phy_node = of_parse_phandle(dn, "phy-device", 0); - - if (!phy_node) { - if (pl->cfg_link_an_mode == MLO_AN_PHY) - return -ENODEV; - return 0; - } - - phy_dev = of_phy_find_device(phy_node); - /* We're done with the phy_node handle */ - of_node_put(phy_node); - if (!phy_dev) - return -ENODEV; - - ret = phy_attach_direct(pl->netdev, phy_dev, flags, - pl->link_interface); - if (ret) - return ret; - - ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface); - if (ret) - phy_detach(phy_dev); - - return ret; + return phylink_fwnode_phy_connect(pl, of_fwnode_handle(dn), flags); } EXPORT_SYMBOL_GPL(phylink_of_phy_connect); From patchwork Thu Jun 10 16:39:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 12313537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED4CBC48BE0 for ; Thu, 10 Jun 2021 16:42:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D84AF613E1 for ; Thu, 10 Jun 2021 16:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231724AbhFJQoP (ORCPT ); Thu, 10 Jun 2021 12:44:15 -0400 Received: from mail-ed1-f47.google.com ([209.85.208.47]:36848 "EHLO mail-ed1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbhFJQno (ORCPT ); Thu, 10 Jun 2021 12:43:44 -0400 Received: by mail-ed1-f47.google.com with SMTP id w21so33743944edv.3; Thu, 10 Jun 2021 09:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yvHFyQ/agosabwkcKUcNoOmx65V0N/UbwYIAHR5bR5w=; b=GPsbG6YiuA0hWWC6GQYoQLw98R+dnbg3lepYbmDUS/B+uLwtN/p+3iM2p/31MGfN87 SbCnDYQ6uT87nDYVV9poNQSYTeRXmCQDHAjPOU4A9La2dgdmR+ocC6Yqx18lqY4aEsU6 EEuWO3QqF21w2h+umfMXuLkvQDhxLDcM7iaOQz2ysjQtJziE4I7oEucWw3G04IZUF+zL H8oVocPk+73eXnDH8D1MLhViZotjm/ArsEWUAgvePPXgBYVq/Vw3D9fTubMXOKBrEhK8 6R1f4rCi99wttsYibEfWCIX82e0AG63/as9+gITtxcrw+V/PKap2EwCe/REeJuqGJRYZ GvZw== 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:mime-version:content-transfer-encoding; bh=yvHFyQ/agosabwkcKUcNoOmx65V0N/UbwYIAHR5bR5w=; b=TXNJiToszVT+JXOH3YD95s8gMx6GbCXwyDMUdrxRUUDYXjgG1WsETUpCdcdXNn8LcH U1qm6wdxJtA6xJQlLKG8/C+bnjfvPIbuKm8/1GGGYoJ/dXhOnDEeygqu/7/VahNeXBAs ATBmAwOK7sdXXU/0YW4K/ZLKFgJuQdUr+46ovmuoOdkhpvyBpfheHUxESU0mTMEsmxgG kgKoHnZ+wHhAKtmay1SWRd8CW8GiSasJLA23r2AbbOhL6BNOgHAWnKZJhbIYWqb6EoC4 1Q2G/mjQu97SFwnz1BLwzIHjIFOxkg+b62vLyZgawtUk69K2en7g2wNFaXK1QSQHnNSu JgdQ== X-Gm-Message-State: AOAM5336ekZswKI1bdlL02UvEoPV0nOvfT+iOZy0vbXoAmt7luNAnTWq crcL5BFtO1z+N+Sl8RD2798= X-Google-Smtp-Source: ABdhPJxKWEyLvrBNQBzGx/LDQrqfxoDGWqOMvSzIDoHJQ2idKxwuEt6UqvBSrJJweVxZG19zuf6VTQ== X-Received: by 2002:a05:6402:5256:: with SMTP id t22mr404335edd.54.1623343246463; Thu, 10 Jun 2021 09:40:46 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id e22sm1657166edv.57.2021.06.10.09.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jun 2021 09:40:46 -0700 (PDT) From: Ioana Ciornei To: Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, netdev@vger.kernel.org, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Calvin Johnson , Ioana Ciornei Subject: [PATCH net-next v8 15/15] net: dpaa2-mac: Add ACPI support for DPAA2 MAC driver Date: Thu, 10 Jun 2021 19:39:17 +0300 Message-Id: <20210610163917.4138412-16-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210610163917.4138412-1-ciorneiioana@gmail.com> References: <20210610163917.4138412-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Calvin Johnson Modify dpaa2_mac_get_node() to get the dpmac fwnode from either DT or ACPI. Modify dpaa2_mac_get_if_mode() to get interface mode from dpmac_node which is a fwnode. Modify dpaa2_pcs_create() to create pcs from dpmac_node fwnode. Modify dpaa2_mac_connect() to support ACPI along with DT. Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei Acked-by: Rafael J. Wysocki --- Changes in v8: - adjust code over latest changes applied on the driver Changes in v7: - remove unnecassary checks Changes in v6: - use dev_fwnode() - remove useless else - replace of_device_is_available() to fwnode_device_is_available() Changes in v5: - replace fwnode_get_id() with OF and ACPI function calls Changes in v4: None Changes in v3: None Changes in v2: - Refactor OF functions to use fwnode functions .../net/ethernet/freescale/dpaa2/dpaa2-mac.c | 88 +++++++++++-------- .../net/ethernet/freescale/dpaa2/dpaa2-mac.h | 2 +- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c index 4dfadf2b70d6..ae6d382d8735 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.c @@ -1,6 +1,9 @@ // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) /* Copyright 2019 NXP */ +#include +#include + #include "dpaa2-eth.h" #include "dpaa2-mac.h" @@ -34,39 +37,51 @@ static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode) return 0; } -/* Caller must call of_node_put on the returned value */ -static struct device_node *dpaa2_mac_get_node(u16 dpmac_id) +static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev, + u16 dpmac_id) { - struct device_node *dpmacs, *dpmac = NULL; - u32 id; + struct fwnode_handle *fwnode, *parent, *child = NULL; + struct device_node *dpmacs = NULL; int err; + u32 id; - dpmacs = of_find_node_by_name(NULL, "dpmacs"); - if (!dpmacs) - return NULL; + fwnode = dev_fwnode(dev->parent); + if (is_of_node(fwnode)) { + dpmacs = of_find_node_by_name(NULL, "dpmacs"); + if (!dpmacs) + return NULL; + parent = of_fwnode_handle(dpmacs); + } else if (is_acpi_node(fwnode)) { + parent = fwnode; + } - while ((dpmac = of_get_next_child(dpmacs, dpmac)) != NULL) { - err = of_property_read_u32(dpmac, "reg", &id); + fwnode_for_each_child_node(parent, child) { + err = -EINVAL; + if (is_acpi_device_node(child)) + err = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &id); + else if (is_of_node(child)) + err = of_property_read_u32(to_of_node(child), "reg", &id); if (err) continue; - if (id == dpmac_id) - break; - } + if (id == dpmac_id) { + of_node_put(dpmacs); + return child; + } + } of_node_put(dpmacs); - - return dpmac; + return NULL; } -static int dpaa2_mac_get_if_mode(struct device_node *node, +static int dpaa2_mac_get_if_mode(struct fwnode_handle *dpmac_node, struct dpmac_attr attr) { phy_interface_t if_mode; int err; - err = of_get_phy_mode(node, &if_mode); - if (!err) - return if_mode; + err = fwnode_get_phy_mode(dpmac_node); + if (err > 0) + return err; err = phy_mode(attr.eth_if, &if_mode); if (!err) @@ -235,26 +250,27 @@ static const struct phylink_mac_ops dpaa2_mac_phylink_ops = { }; static int dpaa2_pcs_create(struct dpaa2_mac *mac, - struct device_node *dpmac_node, int id) + struct fwnode_handle *dpmac_node, + int id) { struct mdio_device *mdiodev; - struct device_node *node; + struct fwnode_handle *node; - node = of_parse_phandle(dpmac_node, "pcs-handle", 0); - if (!node) { + node = fwnode_find_reference(dpmac_node, "pcs-handle", 0); + if (IS_ERR(node)) { /* do not error out on old DTS files */ netdev_warn(mac->net_dev, "pcs-handle node not found\n"); return 0; } - if (!of_device_is_available(node)) { + if (!fwnode_device_is_available(node)) { netdev_err(mac->net_dev, "pcs-handle node not available\n"); - of_node_put(node); + fwnode_handle_put(node); return -ENODEV; } - mdiodev = of_mdio_find_device(node); - of_node_put(node); + mdiodev = fwnode_mdio_find_device(node); + fwnode_handle_put(node); if (!mdiodev) return -EPROBE_DEFER; @@ -283,13 +299,13 @@ static void dpaa2_pcs_destroy(struct dpaa2_mac *mac) int dpaa2_mac_connect(struct dpaa2_mac *mac) { struct net_device *net_dev = mac->net_dev; - struct device_node *dpmac_node; + struct fwnode_handle *dpmac_node; struct phylink *phylink; int err; mac->if_link_type = mac->attr.link_type; - dpmac_node = mac->of_node; + dpmac_node = mac->fw_node; if (!dpmac_node) { netdev_err(net_dev, "No dpmac@%d node found.\n", mac->attr.id); return -ENODEV; @@ -304,7 +320,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) * error out if the interface mode requests them and there is no PHY * to act upon them */ - if (of_phy_is_fixed_link(dpmac_node) && + if (of_phy_is_fixed_link(to_of_node(dpmac_node)) && (mac->if_mode == PHY_INTERFACE_MODE_RGMII_ID || mac->if_mode == PHY_INTERFACE_MODE_RGMII_RXID || mac->if_mode == PHY_INTERFACE_MODE_RGMII_TXID)) { @@ -324,7 +340,7 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) mac->phylink_config.type = PHYLINK_NETDEV; phylink = phylink_create(&mac->phylink_config, - of_fwnode_handle(dpmac_node), mac->if_mode, + dpmac_node, mac->if_mode, &dpaa2_mac_phylink_ops); if (IS_ERR(phylink)) { err = PTR_ERR(phylink); @@ -335,9 +351,9 @@ int dpaa2_mac_connect(struct dpaa2_mac *mac) if (mac->pcs) phylink_set_pcs(mac->phylink, &mac->pcs->pcs); - err = phylink_of_phy_connect(mac->phylink, dpmac_node, 0); + err = phylink_fwnode_phy_connect(mac->phylink, dpmac_node, 0); if (err) { - netdev_err(net_dev, "phylink_of_phy_connect() = %d\n", err); + netdev_err(net_dev, "phylink_fwnode_phy_connect() = %d\n", err); goto err_phylink_destroy; } @@ -384,8 +400,8 @@ int dpaa2_mac_open(struct dpaa2_mac *mac) /* Find the device node representing the MAC device and link the device * behind the associated netdev to it. */ - mac->of_node = dpaa2_mac_get_node(mac->attr.id); - net_dev->dev.of_node = mac->of_node; + mac->fw_node = dpaa2_mac_get_node(&mac->mc_dev->dev, mac->attr.id); + net_dev->dev.of_node = to_of_node(mac->fw_node); return 0; @@ -399,8 +415,8 @@ void dpaa2_mac_close(struct dpaa2_mac *mac) struct fsl_mc_device *dpmac_dev = mac->mc_dev; dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle); - if (mac->of_node) - of_node_put(mac->of_node); + if (mac->fw_node) + fwnode_handle_put(mac->fw_node); } static char dpaa2_mac_ethtool_stats[][ETH_GSTRING_LEN] = { diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h index 8ebcb3420d02..7842cbb2207a 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-mac.h @@ -24,7 +24,7 @@ struct dpaa2_mac { phy_interface_t if_mode; enum dpmac_link_type if_link_type; struct lynx_pcs *pcs; - struct device_node *of_node; + struct fwnode_handle *fw_node; }; bool dpaa2_mac_is_type_fixed(struct fsl_mc_device *dpmac_dev,