From patchwork Mon Feb 5 16:48:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 196934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1000197dyb; Mon, 5 Feb 2024 08:51:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFawfp5Nyvgw+NAQr2PwYatVP+sg/qPIWONl9ipuAKdbeyg5ShLzj0ueFDTcUromorRzDa/ X-Received: by 2002:a17:907:971e:b0:a36:708f:a197 with SMTP id jg30-20020a170907971e00b00a36708fa197mr4887ejc.37.1707151859956; Mon, 05 Feb 2024 08:50:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707151859; cv=pass; d=google.com; s=arc-20160816; b=J3AifNCyDlWJ2yKekxMR4p+bPpuS43G+1HA5Nek8tVeOWNUfE6suA4Q3O+DVSh1HF0 GPAPISoxsk2Y86G8z9l/FIbfWVxW5iEugshLme9RZ/F2W2cIpZbQ6sddych41lFZMVry LjqANH23Yg7g2bz8jB3yRKSZEQQjQeYNZadf6/TC59HMVZjo23dept51qT71lTqcuI1e XoYMpukpTrjc8bM4wGW1hDWS6Rl+GDGC7YMxomMebIpY2KtcBjLzewTv58YU+dAnKzgN /my6TM4XPFhjMnMGQ2x79mg6F83hDS9p58RlnvpokJWgAzg4U5FQ0dCRTifQA/h1+3PP OjtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=ozVMLwHgKVfJzWQo5tW7oNNWQr0MV/j4f/0n469yn4M=; fh=8RK5RtpuvKMvKB9KcY84YUgEkU0eZX/XQ4qumGA4HJw=; b=Mqgn1BvNi65MJ7Sj9r8CfXh8TvaP+4WHnqcIj9+OdLr/fg85xA5wpNJuj3wz5Cy7E6 d5f5D9OPC1ZIe7b/8DYaBQCSEFjbtpXFl/dQBe3xClM2Xtq0sGolRhUOhaLyGNi2dxbu 1Sq7hlzarKkID9zB28wk/BIqqAyZfkzscq5MH46rptDpqIHffQ0PnRqanEVCsQZvMNXX 8kH6TDnX1T0wgl17eCjl4pjOEB8bFRA5ALDhreMNQUG5hoARw1mBKCTMVX2ZN7V7eUrA tFm0ive4SjnceI11FHJ0j1sGi1Z9JG6dLqhYyN8NOCkeYXH99UlvSSVxZxpTNRh/MOnz Yxww==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Vd1VHMQs; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53040-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53040-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCU0kRkfGRowyPgLUeLZBWwTUC17oSy73QfZ2Ps4N/NFo9Q6sg4i9ePrdwbKrUW+k6mOI7i5KsZjfODuyOHHUfFXbmUJww== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id k1-20020a170906a38100b00a37ad50dec8si13148ejz.781.2024.02.05.08.50.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:50:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53040-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Vd1VHMQs; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53040-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53040-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 632D91F227E0 for ; Mon, 5 Feb 2024 16:50:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5741E47F77; Mon, 5 Feb 2024 16:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vd1VHMQs" Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 729B73D99E; Mon, 5 Feb 2024 16:49:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151749; cv=none; b=m4mnjPnI8kP5j15G+BgnA6kDCFKXCI+oDkjU4k1OIYYKoKKw2hjkshrxG7+KRbAN/obv4977vFzvSVrI44weIATsndTaUaCf5GIwuI+FdbreZnKCYqhvzX35WCUejiAZmbatn4eHETMWVQnLDqAWPKcXU4NN+tIexo7MEm4xGSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151749; c=relaxed/simple; bh=QUMd/pymTNWROMEPvOP0tST5nIvBnoIZpBFhJ64dhxw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=In3vxFC9KZLPw50dEHTHcy288lSJebBPCu9pJqxzhPrzOk8/KoDV/gTEkmijnet8Qf/OOnOAzL8A24PjOgOr+XjTdPpt92FXk9s7etHaw0rcSxutv/avRHPyG6O3T/ot922BoRm0z5XlL2kBQd6JibFllwMUqxkdnGNQlxlDhHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vd1VHMQs; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-511538be947so954846e87.3; Mon, 05 Feb 2024 08:49:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707151745; x=1707756545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ozVMLwHgKVfJzWQo5tW7oNNWQr0MV/j4f/0n469yn4M=; b=Vd1VHMQs9c3r3r+ysu2zpPPGpmm5Hd7eqG19wc3Ea2hrbZEYtW6nk44T9NSeQBZMiS CnceKXI7pIC91hw4BrYfkqRyIgPrx9Z8zPWv6//qtuUWKOo6QCdCChdrGpuQFHccmwnK NRCCfUbiurE+Dkh0EQV2yzIBSC2pYk+dW/oGD445FfZ/p26el3R0JPhN306uU4XEjFul XMDUKi4croPMqjPNGIdhAUXS2nRfHYHR3D6YjyYXPE4CpAiKcGTODVDcjhcZcVOeYNEP aZAFordVImTlDcAJBj4UuRhfj5HT+i0G601ybOYf9E4fzOUrXjPFmCVpHh54PL/ireC4 QLOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707151745; x=1707756545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ozVMLwHgKVfJzWQo5tW7oNNWQr0MV/j4f/0n469yn4M=; b=Of0KqOC0xpwAUc6JvVNKxrHc7ECc39CQZ1qBd+7bnP/d+Kf6uFL25iRlcl41bdaGqm 8yVhFlwchG19XoEHuLna5z4uSqcwhMOVwlPfxRGNF5PIPIPbwt/JB9lr+g12Cuw1ozFI TW7JvP01bfq3+zgE4dKTgbiOw6woIrZ2CXJC1aKzo4AvLXZzYsGOea54SUYgHqSl5ELh 84wusPHT4paGlaLWeuP9W+lDO2f4sqZwqPxV36iquCqrmFRV9xvwMQGsTF76KHJWs5Kd hhkPxXKj1Hvaz7BgurbRG7M7hNclnVOlDAIgiP+AzNMc7jkBLPqV3RgibGLzAJ2hTJVN txfw== X-Gm-Message-State: AOJu0Yxt+FYSyx935zu0zd4kTnsHf0klJB/8ag/EipDUoYEBRkztsqeh 3nGADBU1bhY4rPmB0dGcAL/opiMbCa7mioWJv/Y5QQdbiiMlRZIamyev9ROu X-Received: by 2002:a19:8c19:0:b0:511:297f:2732 with SMTP id o25-20020a198c19000000b00511297f2732mr122812lfd.31.1707151745386; Mon, 05 Feb 2024 08:49:05 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUS+2aX1gUn1eBXcvBG1RDeE6hlA+QE0aGi3kidpjPYVsE2gAh1X/9dM7bboBH19pbuZ45ndzo9BVB8uX87ueeQXzAEzoObEItsmaUqhA71e+aY3BOvItwLtXf4GOHMfRbUswwZBiQHgkiA4v2TCh8SbU6s9G9LeZYXHa/1Wvnanugxc8AIZL0KXheyOMj8buAm42wdUCgKeAIv6A+97bDFWjyM6sB/73pG0X+01Ywr1i69RN57Xm+J1StqjWor2ylI4qq1DSZL4R6sA+ov6UCcC1scIugU/10qTnXguJ3HKF3jDPIcOFx2UZfwt52SSP3gJXJjYQ/lQQjxJ0CNTxFShg5zE5qx3lzLkhZHGU3mrU7teoF0YFXv9PTJQZhQ4g/AV70BhgVC8al9HFT8SvS/oJBXcVXCjrUSLkSD4MNF7vjhp1NDt2yt/3buETBJRpB2BVIImnqDQiismudmCUEVUh22yW7IQhLDFmMoslt01uxnlZ5rcs63bICdypZ5MgK0bUxsfd28ADTNAde427DDYz6XIfyXgVdPkzXzUDLmRMxyt7Y1+g1f1w0aULQfnPpcu556F5qX7Ll6MpwtJFt4qgntBit4lB9I7o2ChAeqk8/Oxi3rI+CpAco2BBQS9MMNnghrkEazD+CdhS0zpzQetLCfMSjawp5juvemgasNJQkD5C+fmQ== Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id k2-20020a05600c1c8200b0040fafd84095sm9140567wms.41.2024.02.05.08.49.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:49:04 -0800 (PST) From: Christian Marangi To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Christian Marangi , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [net-next PATCH v6 02/10] net: phy: add support for scanning PHY in PHY packages nodes Date: Mon, 5 Feb 2024 17:48:34 +0100 Message-ID: <20240205164851.1351-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240205164851.1351-1-ansuelsmth@gmail.com> References: <20240205164851.1351-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790078468920201697 X-GMAIL-MSGID: 1790078468920201697 Add support for scanning PHY in PHY package nodes. PHY packages nodes are just container for actual PHY on the MDIO bus. Their PHY address defined in the PHY package node are absolute and reflect the address on the MDIO bus. mdio_bus.c and of_mdio.c is updated to now support and parse also PHY package subnode by checking if the node name match "ethernet-phy-package". As PHY package reg is mandatory and each PHY in the PHY package must have a reg, every invalid PHY Package node is ignored and will be skipped by the autoscan fallback. Signed-off-by: Christian Marangi --- drivers/net/mdio/of_mdio.c | 79 +++++++++++++++++++++++++++----------- drivers/net/phy/mdio_bus.c | 44 +++++++++++++++++---- 2 files changed, 92 insertions(+), 31 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 64ebcb6d235c..08e607f62e10 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -139,6 +139,53 @@ bool of_mdiobus_child_is_phy(struct device_node *child) } EXPORT_SYMBOL(of_mdiobus_child_is_phy); +static int __of_mdiobus_parse_phys(struct mii_bus *mdio, struct device_node *np, + bool *scanphys) +{ + struct device_node *child; + int addr, rc = 0; + + /* Loop over the child nodes and register a phy_device for each phy */ + for_each_available_child_of_node(np, child) { + if (of_node_name_eq(child, "ethernet-phy-package")) { + /* Ignore invalid ethernet-phy-package node */ + if (!of_property_present(child, "reg")) + continue; + + rc = __of_mdiobus_parse_phys(mdio, child, NULL); + if (rc && rc != -ENODEV) + goto exit; + + continue; + } + + addr = of_mdio_parse_addr(&mdio->dev, child); + if (addr < 0) { + /* Skip scanning for invalid ethernet-phy-package node */ + if (scanphys) + *scanphys = true; + continue; + } + + if (of_mdiobus_child_is_phy(child)) + rc = of_mdiobus_register_phy(mdio, child, addr); + else + rc = of_mdiobus_register_device(mdio, child, addr); + + if (rc == -ENODEV) + dev_err(&mdio->dev, + "MDIO device at address %d is missing.\n", + addr); + else if (rc) + goto exit; + } + + return 0; +exit: + of_node_put(child); + return rc; +} + /** * __of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure @@ -180,33 +227,18 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np, return rc; /* Loop over the child nodes and register a phy_device for each phy */ - for_each_available_child_of_node(np, child) { - addr = of_mdio_parse_addr(&mdio->dev, child); - if (addr < 0) { - scanphys = true; - continue; - } - - if (of_mdiobus_child_is_phy(child)) - rc = of_mdiobus_register_phy(mdio, child, addr); - else - rc = of_mdiobus_register_device(mdio, child, addr); - - if (rc == -ENODEV) - dev_err(&mdio->dev, - "MDIO device at address %d is missing.\n", - addr); - else if (rc) - goto unregister; - } + rc = __of_mdiobus_parse_phys(mdio, np, &scanphys); + if (rc) + goto unregister; if (!scanphys) return 0; /* auto scan for PHYs with empty reg property */ for_each_available_child_of_node(np, child) { - /* Skip PHYs with reg property set */ - if (of_property_present(child, "reg")) + /* Skip PHYs with reg property set or ethernet-phy-package node */ + if (of_property_present(child, "reg") || + of_node_name_eq(child, "ethernet-phy-package")) continue; for (addr = 0; addr < PHY_MAX_ADDR; addr++) { @@ -227,15 +259,16 @@ int __of_mdiobus_register(struct mii_bus *mdio, struct device_node *np, if (!rc) break; if (rc != -ENODEV) - goto unregister; + goto put_unregister; } } } return 0; -unregister: +put_unregister: of_node_put(child); +unregister: mdiobus_unregister(mdio); return rc; } diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index afbad1ad8683..08624f073014 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -459,19 +459,34 @@ EXPORT_SYMBOL(of_mdio_find_bus); * found, set the of_node pointer for the mdio device. This allows * auto-probed phy devices to be supplied with information passed in * via DT. + * If a PHY package is found, PHY is searched also there. */ -static void of_mdiobus_link_mdiodev(struct mii_bus *bus, - struct mdio_device *mdiodev) +static int of_mdiobus_find_phy(struct device *dev, struct mdio_device *mdiodev, + struct device_node *np) { - struct device *dev = &mdiodev->dev; struct device_node *child; - if (dev->of_node || !bus->dev.of_node) - return; - - for_each_available_child_of_node(bus->dev.of_node, child) { + for_each_available_child_of_node(np, child) { int addr; + if (of_node_name_eq(child, "ethernet-phy-package")) { + /* Validate PHY package reg presence */ + if (!of_property_present(child, "reg")) { + of_node_put(child); + return -EINVAL; + } + + if (!of_mdiobus_find_phy(dev, mdiodev, child)) { + /* The refcount for the PHY package will be + * incremented later when PHY join the Package. + */ + of_node_put(child); + return 0; + } + + continue; + } + addr = of_mdio_parse_addr(dev, child); if (addr < 0) continue; @@ -481,9 +496,22 @@ static void of_mdiobus_link_mdiodev(struct mii_bus *bus, /* The refcount on "child" is passed to the mdio * device. Do _not_ use of_node_put(child) here. */ - return; + return 0; } } + + return -ENODEV; +} + +static void of_mdiobus_link_mdiodev(struct mii_bus *bus, + struct mdio_device *mdiodev) +{ + struct device *dev = &mdiodev->dev; + + if (dev->of_node || !bus->dev.of_node) + return; + + of_mdiobus_find_phy(dev, mdiodev, bus->dev.of_node); } #else /* !IS_ENABLED(CONFIG_OF_MDIO) */ static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio, From patchwork Mon Feb 5 16:48:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 196935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1001089dyb; Mon, 5 Feb 2024 08:52:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4AufVrvWkRTauaxSQwGQmZwBM0jWjoqaUQ8APAxgvaP50mkOyd/jAI9TEqQib50Z+rvul X-Received: by 2002:a05:651c:2129:b0:2d0:9c62:fbaa with SMTP id a41-20020a05651c212900b002d09c62fbaamr237280ljq.32.1707151950432; Mon, 05 Feb 2024 08:52:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707151950; cv=pass; d=google.com; s=arc-20160816; b=N6p47x7xQqyH8Aleq7LccWvQ35Rp6Y1JvI/U1Jsha8DBp6IqX9/vN1BsnrrVAL2M5F mUpSrgrHFRs3svegwrKI3bBDMG2yBaC3ITCTkHzaORXukxweIn68OPCTtgIpDI6I9l8t mkzwf8w63Gv4y+5to+mvzXas6xXFHb1dy24THWZ/uZCArn0vTQffeVu5xM3RyaNe5Sj0 LfK6Na604ELPTttEWxcgudJPyP+QrNbyGjhXfowLYQmKTd67A1fblNkjy0uDPtstmOua RMG/9SdOm3eZKTZNCXmXMfx3nbdKN9+IdA/DHbRxuy6ZHcptmXQsmFijcettHMwK2Nrv e5zg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=MCJZjdTnS6Uq1X+PLH0vDHoWwK/834bPA12yZFCUGH4=; fh=MpnzIF+opIUk6bgwtiUEB381qJ5hqYUQjV/FYpv3zSA=; b=idi6Tb9pnFgPr+RTZlx7USYDFf4jtudPV+0wTpfgFoIRGNo3JfVI7upTo0DO3SgbSM evO51uQZbKZA0j3B0Wxgs4PezysmE99scUV5Sj/JkihnVm02yfU7HCrIXDPtSGm09kC+ yK/+7aDCRmwcJe8P9/D6KaB4ha3uvVMmmeA6JiFYUPECXfmnW1jXbLpnnka2rJoP18wx /l0ogPLyYyCT6rmqExbetlWYvxEGmfwd8AHQPkgA6HCPKjvT4JRegopEB8e3cdYNOemS 0kx+vuwTrO+WGtdcTm+gcma+c2oha63qd7XUzGXC2JpQAplp8RsCxe33/Q7Kgi1Mfp9A V9pQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Xg64uf4B; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCU1IF1SHCqDqxScgeGfauucQ8nGuUtfA8jA6giVgT+bIOubUtnuTBdo3IkE9wrqcZYRQp8D5cL20uOQsufkqvhO9nYeXA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d21-20020a056402517500b0056008a26a22si60973ede.381.2024.02.05.08.52.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:52:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Xg64uf4B; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53044-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4D5CF1F22406 for ; Mon, 5 Feb 2024 16:52:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E03AB495F0; Mon, 5 Feb 2024 16:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xg64uf4B" Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A68B47796; Mon, 5 Feb 2024 16:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151754; cv=none; b=HK/Y06IemDTbmCIsW5nRCrVYuFosP9zVpj0+QMM6DKDBzCsKhRNcSM6odlzw6xSrRZbY3a+dZiVIetimLvQ4EDS3kLSvBdnT4JNVItLtVAahFlkFbpcMFst+JLdFVPvbhRSNmj3soHPq+XQmB7Maxy0rnpdns1n7zYg+DptnHa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151754; c=relaxed/simple; bh=mG+KMNv/A3mLJpuaFQD/GBoSpPY4XzSaY9y3kPO1C5A=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YmRDehx8u236e4NCnZA/2gHjdl3t2l0fwzfjk7CCnG4n/0mmqfo+jPUt/lmeUUDrMS6Bhf4iJ170/sl4iq6iVxz8ohOJjj1httPcBIfPLdMPwMNEStVM3DqTPttJM4FdGBQ9wtkS55jrUdZEeildlUwlxoB0pV4Zz3cVoi5Jv6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Xg64uf4B; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40fb3b5893eso38065025e9.0; Mon, 05 Feb 2024 08:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707151750; x=1707756550; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=MCJZjdTnS6Uq1X+PLH0vDHoWwK/834bPA12yZFCUGH4=; b=Xg64uf4B7iqs9vzSCnAVB7P6ckktfC9TkGc4J4Wzt2zcSkEwsVXgXlp3KPj3iNdwoN sc4khUzX7n6dT4j7yC6vciRTyNAoQGUUJNP1NSbZCdppiRHEmKq4XO5KHsBEVeU+/0xN CndH6th8MRQuTEXEwq0zuMWF4ui0o7gA7SvlAQ3RSxs7nLhrgZ/IRdh+AxacfYcfh/AS jXUmoeGK0M/y+MryYIF7C2m7Ej1JqbJ7PH4wnAFcrueY5ExUmc6G7Wc6rNgdcpl8IrL5 V4qhgKJU+B6x/CU1c6ko1rseTq2mZ8YWifOA4gVCKAVaX8UqTpEPNkDV2QriXMEexk+N /I6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707151750; x=1707756550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MCJZjdTnS6Uq1X+PLH0vDHoWwK/834bPA12yZFCUGH4=; b=tYh4zpY6wm2FFrYVKYA9hFcw80uQacdjkqNAUIi0I1b+8WJnS6XShK/CUfyDialyW+ xoSzR+WUvzseOueRb4mhuVTyz9wfpJMFQ0D0BMa30ZOSrhMI86N+Q8woCgKJ2Lmy4HlX zbOZolFOzUGRY2gdUBUH1LucvynoTe7DkdVCusHz12jeAPDx1vfy6kznVZh3uX/Y1PvK JGSXvAY8xGNq8WVMLSZLefogOaH4JjUvPxG5RNjKofrLVVArUsZkmwAeunRfzuQljLK0 elnn1CCJsfJeZ3z+iw84SwFNUOQiNK3F/vIf/GhkC8AM+i8qGppoEqB4gT4CdMpupYgF OrOg== X-Gm-Message-State: AOJu0Yx815ekoIsl2YnlOlvsC9hn2K/M70XnQCDU0WyVaH+DilM0wG+9 1bv3RzM7K6BJtksBscs70srwrFbbKxoeryyW2tF0AjnqG8ocKk78 X-Received: by 2002:a05:600c:1c02:b0:40e:46b6:bc48 with SMTP id j2-20020a05600c1c0200b0040e46b6bc48mr230699wms.41.1707151750255; Mon, 05 Feb 2024 08:49:10 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXYbMPE+KrWwopIcUqLHL16J9m6BrOCevgdpd2u1GVnbEiPmgZjMoN85aoaPGSanbLLOrnRdBQl8GeWH8dRPmXZWfx1irZM+1N4VtIOCOR9cwDSj0+o52pJxbHrk+zqKeAvk2qH6TVBTfE4E3FHo0mCd2QTFNX01UOf64BNM4Ciqmpzl5BjUIobL4RyMnJN4Rk7Gikwk266UOaAiMtrJv09ZmSbGmzoa5jRkic4cn6mGu7wupM/fxfvrG/V2hrtZ7kxi8qsVThlEuNyhHzFEWT8Re+m6AhtJJXlCHC7Bmpajg3EkbMgso+hrMvHd637o+G2WEbEns+LY0XcujdimL7ShEajJxOzt6yU/8IYZeGxha/Ea1u4vTZWKxrIq5TJoJdDVS4FP3Wu2L5mHR4b49C3XebXKc6IrXPZLdaVEtac/e0lAdZ59H4rAsSvS2agQfGvK+DcD0rQD2ROgLhKzeMgv4I4NZMOakd7UpQrpEGTQBLAfyge0DjDijckp7jWflw5Q7PyXJZv0yWDpJPRtorDWvm6/OCspzGQ8UEnPcMstHyDs5qm/W6hRZryEEjKoxUbd1LQpXT9FXnl2NS9UnhNbevgtrAWHlDOnkaYy93+U+DQYJTDkbFku5h9oDgyVjiXyTUfHcswaupC7bfDjWR1oEN8tQS9G7NReVpcPx+ReT0fpNgRbA== Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id k2-20020a05600c1c8200b0040fafd84095sm9140567wms.41.2024.02.05.08.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:49:09 -0800 (PST) From: Christian Marangi To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Christian Marangi , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [net-next PATCH v6 06/10] net: phy: provide whether link has changed in c37_read_status Date: Mon, 5 Feb 2024 17:48:38 +0100 Message-ID: <20240205164851.1351-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240205164851.1351-1-ansuelsmth@gmail.com> References: <20240205164851.1351-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790078563883900839 X-GMAIL-MSGID: 1790078563883900839 Some PHY driver might require additional regs call after genphy_c37_read_status() is called. Expand genphy_c37_read_status to provide a bool wheather the link has changed or not to permit PHY driver to skip additional regs call if nothing has changed. Every user of genphy_c37_read_status() is updated with the new additional bool. Signed-off-by: Christian Marangi --- drivers/net/phy/broadcom.c | 3 ++- drivers/net/phy/phy_device.c | 11 +++++++++-- drivers/net/phy/qcom/at803x.c | 3 ++- include/linux/phy.h | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index 312a8bb35d78..370e4ed45098 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -665,10 +665,11 @@ static int bcm54616s_config_aneg(struct phy_device *phydev) static int bcm54616s_read_status(struct phy_device *phydev) { struct bcm54616s_phy_priv *priv = phydev->priv; + bool changed; int err; if (priv->mode_1000bx_en) - err = genphy_c37_read_status(phydev); + err = genphy_c37_read_status(phydev, &changed); else err = genphy_read_status(phydev); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c30907dc9fb7..b36839414dfc 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2617,12 +2617,15 @@ EXPORT_SYMBOL(genphy_read_status); /** * genphy_c37_read_status - check the link status and update current link state * @phydev: target phy_device struct + * @changed: pointer where to store if link changed * * Description: Check the link, then figure out the current state * by comparing what we advertise with what the link partner * advertises. This function is for Clause 37 1000Base-X mode. + * + * If link has changed, @changed is set to true, false otherwise. */ -int genphy_c37_read_status(struct phy_device *phydev) +int genphy_c37_read_status(struct phy_device *phydev, bool *changed) { int lpa, err, old_link = phydev->link; @@ -2632,9 +2635,13 @@ int genphy_c37_read_status(struct phy_device *phydev) return err; /* why bother the PHY if nothing can have changed */ - if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) + if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) { + *changed = false; return 0; + } + /* Signal link has changed */ + *changed = true; phydev->duplex = DUPLEX_UNKNOWN; phydev->pause = 0; phydev->asym_pause = 0; diff --git a/drivers/net/phy/qcom/at803x.c b/drivers/net/phy/qcom/at803x.c index 3e3ee4c1d4bc..4717c59d51d0 100644 --- a/drivers/net/phy/qcom/at803x.c +++ b/drivers/net/phy/qcom/at803x.c @@ -912,9 +912,10 @@ static int at8031_config_intr(struct phy_device *phydev) static int at8031_read_status(struct phy_device *phydev) { struct at803x_priv *priv = phydev->priv; + bool changed; if (priv->is_1000basex) - return genphy_c37_read_status(phydev); + return genphy_c37_read_status(phydev, &changed); return at803x_read_status(phydev); } diff --git a/include/linux/phy.h b/include/linux/phy.h index 2aed925e6c23..8f7f0101de13 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1876,7 +1876,7 @@ int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum, /* Clause 37 */ int genphy_c37_config_aneg(struct phy_device *phydev); -int genphy_c37_read_status(struct phy_device *phydev); +int genphy_c37_read_status(struct phy_device *phydev, bool *changed); /* Clause 45 PHY */ int genphy_c45_restart_aneg(struct phy_device *phydev); From patchwork Mon Feb 5 16:48:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 196936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1001650dyb; Mon, 5 Feb 2024 08:53:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvdOmyXshYsbxDxTQmiiO9QURuu3uQinCON/YMi/suRCO/vmS2ly8bo30f2qHamfhiWvmK X-Received: by 2002:a25:d305:0:b0:da0:3bfc:b915 with SMTP id e5-20020a25d305000000b00da03bfcb915mr15372849ybf.11.1707152021872; Mon, 05 Feb 2024 08:53:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707152021; cv=pass; d=google.com; s=arc-20160816; b=RmotybQN/WUa9zBdmUVsmHyNsqnRscs+WtRgXYgjJVRqc8gk7nnt4LRjGyH7+jEosh NdxAW3JRMTwodFoAck+T4zx42Uma5AkmbPo4URyHuyu81UZVdYbkwMUuqywetFdWCjAM RvCdDYosnUyg1X0w+6bIlVBIxuM6PpmApZUcdPgD5FXq7coYgNftU5alm9zAOVOmufRb 4W9cx7kjWmszN0PWV/xO56qwPHr2TZqIyzkNZh+mtBIM608IRKqlVt+Oi3YwfKBEXuhY NdKe4h1pTFumE2f2WXyKxUmGb1SpRrsb0zNrQn1rZmWUzx3FmQhPXiZvdy4xcRmitVIa G9FA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=60K7HYoyD/okN2s+2wGpw5kK4uYop3FwQq/xBHnBh9I=; fh=1RuuWMK7HLXyK/yvGAmAPNoDEulSh60XxLoEkNafVm8=; b=rww6wMpK1Wu1HdC+6hH/dtmIz6Yk9bhscRCr9iEhQdH2sD/ANGqNeeeG2SSBPbvk+o OO7nz7GCZpp0VGUfCJ3z9BT6dZs3ok/NKQKLk9V4mVK4jNFnNuBADyX/UoQKeCXz6YXD QNAWJD75xgEDh6oA6ZJSUqImInRzcJRp3luSU/Nnp3h//lqYNcZBk4PZdYXIrhxgksjD mNYOmhYWtT7OgtwnYMbPSTyOTunSHoY3BGgGsyUMGIHiK022sLrV1ZVEpO72Ei2B4NmK 4GAwfJFn8ScZ1N5ZDhUQRwOQ3ORiT8HzEwedPOWfvkTNZ4ei2iInsOmM7URrNc8by1OB 9tPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=njNzfEvm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53047-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCUE8X+bRfeZExkXwed7dNH70K3SpM09hPe3zPghJI/xB+8IN4brH+LBnr3G10ejejPr3dIiG8r0Mvul6C/9xVPKgQYspw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l4-20020a05620a0c0400b00785559a133fsi192790qki.391.2024.02.05.08.53.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:53:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53047-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=njNzfEvm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53047-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 981971C2239E for ; Mon, 5 Feb 2024 16:53:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F4C24F210; Mon, 5 Feb 2024 16:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="njNzfEvm" Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 198414879C; Mon, 5 Feb 2024 16:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151758; cv=none; b=njvkVzZSSeY8smagVWWxVnE6uLBeZMCJTzqK/iMjJDqMu0eV1xpPKtSgSKfj4tsBiO1nMEFqq8SsntKyUv4oSMmr6HSksBTagnjPExc8LFd5zj26M71E5lvxWBLqSgyP20k1PsKcUel5F2lwIfmGF83OkEI1hbXZlCHWdCXaUYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151758; c=relaxed/simple; bh=0dGPT223KlpSppcb4Q5nKzooandtEzP9beu2JwjbgUA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YlMGf0XtLdZ5W/Fh5TjKRtulLAZsotOc2MtwJ4/bw9aqGo6ivDHccib/gWSN8SU1ZAS/ZnLh6cI1dzFcuIYQ3rhHNtRI04auACdyb7oP/ovNhMGKqPKjro7RWzvzUlAkmhuCarx/DltU0e9r2RpWQHEnd1cmtOfwFINH0yK4kxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=njNzfEvm; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40ef3f351d2so32318225e9.1; Mon, 05 Feb 2024 08:49:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707151754; x=1707756554; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=60K7HYoyD/okN2s+2wGpw5kK4uYop3FwQq/xBHnBh9I=; b=njNzfEvmoLHoNplsGuSjfwBYGhKPlBhdkhYI6eRxGbTB/JMBAViSZazu7pJivPC1YY 5F0a7Q6WVVudoRGEB0ltnVYG5AxoOUBfT8CCZ2yTXmJ+o58mpZA6A81Evf0rqAL3FQhj gkb7J34HvzeM3cFZ9DsabIaBgh/4byLtkaHcB0ByCNSlz7R/6tLf99PRChszE8l3w227 Kdtyskrd0dvrD47yiTHBCbncbfEUgzUxHW9S2Jh5Q24MIjy7yP36D5gXXKvWqxE4BTk0 hJW7hz9uhP2NznL9iquav6Dc8kZYMxaaq6JRKYxi6TVBAgzohp5SFcJhfIfHyJI8UCny iPHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707151754; x=1707756554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=60K7HYoyD/okN2s+2wGpw5kK4uYop3FwQq/xBHnBh9I=; b=w7YVFIq64kFIwRaYM+FJCqbop4bSFMo/BY/lk7FjPXUz8TdinXe/IyH5nGYuPHGrt2 AOZzveHRhp9yPvkNKdyaie8WZ292BpZfZaNqKULaAgTeB31kge3ih8EVo4Xh/MmWVraZ kGGGhI9p7NeHBnB/TcWeXU5Rb19kFBfk3QxIpZP7uIahkcRjXn5+1VQVX0HYGh80ya4X k7JLTcIXtivJ+sGWGL8NiIwZYfhktCDCp88CZADUvszB1vVNE5pSq0SueN2JzcJEuRNp ZDw0zD5nESRU3aLRgRBbeA0r9JkW9MjM/lNfddqcHQ6OZcUOdKSC2pFIntdaeP5HSSGr wspQ== X-Gm-Message-State: AOJu0YxrnHe13fVtpoZJKb5nPcE5K8gjriMZtUBmbFdgqS0QBbcIrcfW zD1jjhAK/8XCgVKIGJ1IzDihne0TL/vDP4wgZrUuaUnnDEMcET5f X-Received: by 2002:a05:6000:4023:b0:33b:39cb:a83c with SMTP id cp35-20020a056000402300b0033b39cba83cmr3461914wrb.13.1707151754191; Mon, 05 Feb 2024 08:49:14 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWV+k4V5nnGJpOX/+Cm5V49MEkEns0GMUpTAJOm2Xytj2NZmqyAwSCxUpeXvUd9IE+wmHlCNv3USbAIfUFDTs4nkQbPR4UayHjH1xbT+2M1e+a78QmHEjjhy59BF6FisTK7z7uLWL2WGl2TSAvw2NF/IhmrIqZ+BD00WqxlV2ratZc0h8RC+S0x3ijR0wae8aSj9Vx/CIaDfrPDC2tbJlKcOQoFMjGbivbVKdswOubn+t0GNJrRzuEl70FwZSMvkiNY8kHtxgOgFC5CQx7G9iL2tsQOMH0o1RwHzm4YMnx0Gpep/cNtcCDLdE5qrkWUa2MqyDRDzlWTrrxbl5ICRtQHOcjkivntzjesbPAdKO8agyS6qFyk/9iFEdor4Crx2LX8+1kHk2QG4Y58wqX/ucoOJuZcErkm4CQMA/Pe7rYrw7Cj23JMToQGjCga3G7/+OdvJFJq2+mcgwo/U8Ra467fS1DSdfw9EqjaAuT94ka/jbbwfgHCcKqLnh2K5OBdrKFjMxtsXAmcY7Ko9FZEJpDQDnqYjjCx6/qUHmT8DKx/QCBnu2ABNqqxZep0v8QQGLQ2QpD+QvnoY7ZjccWTO+okaczhc06Ltt3iYy+Ycp9FgH2mjLlHBMpTdGOLBHA5z4X3Mehd2omvpncp8CQ8GIahlx5wpuMnkgwtJtkDRLNl7vDGGKCesA== Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id k2-20020a05600c1c8200b0040fafd84095sm9140567wms.41.2024.02.05.08.49.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:49:13 -0800 (PST) From: Christian Marangi To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Christian Marangi , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [net-next PATCH v6 09/10] net: phy: qcom: generalize some qca808x LED functions Date: Mon, 5 Feb 2024 17:48:41 +0100 Message-ID: <20240205164851.1351-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240205164851.1351-1-ansuelsmth@gmail.com> References: <20240205164851.1351-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790078638185654990 X-GMAIL-MSGID: 1790078638185654990 Generalize some qca808x LED functions in preparation for qca807x LED support. The LED implementation of qca808x and qca807x is the same but qca807x supports also Fiber port and have different hw control bits for Fiber port. To limit code duplication introduce micro functions that takes reg instead of LED index to tweak all the supported LED modes. Signed-off-by: Christian Marangi --- drivers/net/phy/qcom/qca808x.c | 38 +++----------------- drivers/net/phy/qcom/qcom-phy-lib.c | 54 +++++++++++++++++++++++++++++ drivers/net/phy/qcom/qcom.h | 7 ++++ 3 files changed, 65 insertions(+), 34 deletions(-) diff --git a/drivers/net/phy/qcom/qca808x.c b/drivers/net/phy/qcom/qca808x.c index b6ff2676d921..325e22ce8972 100644 --- a/drivers/net/phy/qcom/qca808x.c +++ b/drivers/net/phy/qcom/qca808x.c @@ -427,9 +427,7 @@ static int qca808x_led_hw_control_enable(struct phy_device *phydev, u8 index) return -EINVAL; reg = QCA808X_MMD7_LED_FORCE_CTRL(index); - - return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg, - QCA808X_LED_FORCE_EN); + return qca808x_led_reg_hw_control_enable(phydev, reg); } static int qca808x_led_hw_is_supported(struct phy_device *phydev, u8 index, @@ -470,16 +468,12 @@ static int qca808x_led_hw_control_set(struct phy_device *phydev, u8 index, static bool qca808x_led_hw_control_status(struct phy_device *phydev, u8 index) { u16 reg; - int val; if (index > 2) return false; reg = QCA808X_MMD7_LED_FORCE_CTRL(index); - - val = phy_read_mmd(phydev, MDIO_MMD_AN, reg); - - return !(val & QCA808X_LED_FORCE_EN); + return qca808x_led_reg_hw_control_status(phydev, reg); } static int qca808x_led_hw_control_get(struct phy_device *phydev, u8 index, @@ -547,44 +541,20 @@ static int qca808x_led_brightness_set(struct phy_device *phydev, } reg = QCA808X_MMD7_LED_FORCE_CTRL(index); - - return phy_modify_mmd(phydev, MDIO_MMD_AN, reg, - QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK, - QCA808X_LED_FORCE_EN | value ? QCA808X_LED_FORCE_ON : - QCA808X_LED_FORCE_OFF); + return qca808x_led_reg_brightness_set(phydev, reg, value); } static int qca808x_led_blink_set(struct phy_device *phydev, u8 index, unsigned long *delay_on, unsigned long *delay_off) { - int ret; u16 reg; if (index > 2) return -EINVAL; reg = QCA808X_MMD7_LED_FORCE_CTRL(index); - - /* Set blink to 50% off, 50% on at 4Hz by default */ - ret = phy_modify_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_LED_GLOBAL, - QCA808X_LED_BLINK_FREQ_MASK | QCA808X_LED_BLINK_DUTY_MASK, - QCA808X_LED_BLINK_FREQ_4HZ | QCA808X_LED_BLINK_DUTY_50_50); - if (ret) - return ret; - - /* We use BLINK_1 for normal blinking */ - ret = phy_modify_mmd(phydev, MDIO_MMD_AN, reg, - QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK, - QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_BLINK_1); - if (ret) - return ret; - - /* We set blink to 4Hz, aka 250ms */ - *delay_on = 250 / 2; - *delay_off = 250 / 2; - - return 0; + return qca808x_led_reg_blink_set(phydev, reg, delay_on, delay_off); } static int qca808x_led_polarity_set(struct phy_device *phydev, int index, diff --git a/drivers/net/phy/qcom/qcom-phy-lib.c b/drivers/net/phy/qcom/qcom-phy-lib.c index 786bfc39912c..d28815ef56bb 100644 --- a/drivers/net/phy/qcom/qcom-phy-lib.c +++ b/drivers/net/phy/qcom/qcom-phy-lib.c @@ -620,3 +620,57 @@ int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished) return 0; } EXPORT_SYMBOL_GPL(qca808x_cable_test_get_status); + +int qca808x_led_reg_hw_control_enable(struct phy_device *phydev, u16 reg) +{ + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_FORCE_EN); +} +EXPORT_SYMBOL_GPL(qca808x_led_reg_hw_control_enable); + +bool qca808x_led_reg_hw_control_status(struct phy_device *phydev, u16 reg) +{ + int val; + + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg); + return !(val & QCA808X_LED_FORCE_EN); +} +EXPORT_SYMBOL_GPL(qca808x_led_reg_hw_control_status); + +int qca808x_led_reg_brightness_set(struct phy_device *phydev, + u16 reg, enum led_brightness value) +{ + return phy_modify_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK, + QCA808X_LED_FORCE_EN | (value ? QCA808X_LED_FORCE_ON : + QCA808X_LED_FORCE_OFF)); +} +EXPORT_SYMBOL_GPL(qca808x_led_reg_brightness_set); + +int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg, + unsigned long *delay_on, + unsigned long *delay_off) +{ + int ret; + + /* Set blink to 50% off, 50% on at 4Hz by default */ + ret = phy_modify_mmd(phydev, MDIO_MMD_AN, QCA808X_MMD7_LED_GLOBAL, + QCA808X_LED_BLINK_FREQ_MASK | QCA808X_LED_BLINK_DUTY_MASK, + QCA808X_LED_BLINK_FREQ_4HZ | QCA808X_LED_BLINK_DUTY_50_50); + if (ret) + return ret; + + /* We use BLINK_1 for normal blinking */ + ret = phy_modify_mmd(phydev, MDIO_MMD_AN, reg, + QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_MODE_MASK, + QCA808X_LED_FORCE_EN | QCA808X_LED_FORCE_BLINK_1); + if (ret) + return ret; + + /* We set blink to 4Hz, aka 250ms */ + *delay_on = 250 / 2; + *delay_off = 250 / 2; + + return 0; +} +EXPORT_SYMBOL_GPL(qca808x_led_reg_blink_set); diff --git a/drivers/net/phy/qcom/qcom.h b/drivers/net/phy/qcom/qcom.h index 9e24997c355f..4bb541728846 100644 --- a/drivers/net/phy/qcom/qcom.h +++ b/drivers/net/phy/qcom/qcom.h @@ -234,3 +234,10 @@ int at803x_cdt_start(struct phy_device *phydev, u32 cdt_start); int at803x_cdt_wait_for_completion(struct phy_device *phydev, u32 cdt_en); int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finished); +int qca808x_led_reg_hw_control_enable(struct phy_device *phydev, u16 reg); +bool qca808x_led_reg_hw_control_status(struct phy_device *phydev, u16 reg); +int qca808x_led_reg_brightness_set(struct phy_device *phydev, + u16 reg, enum led_brightness value); +int qca808x_led_reg_blink_set(struct phy_device *phydev, u16 reg, + unsigned long *delay_on, + unsigned long *delay_off); From patchwork Mon Feb 5 16:48:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 196937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1002266dyb; Mon, 5 Feb 2024 08:55:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuShKeZ9najAvmFBg5gUekAeoeA78khL07wtkYTLEJ01Cz0TdwvpbAB5eLbeEqrbpP09+1 X-Received: by 2002:a17:90a:bc89:b0:293:d87e:c0fa with SMTP id x9-20020a17090abc8900b00293d87ec0famr12274692pjr.17.1707152100866; Mon, 05 Feb 2024 08:55:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707152100; cv=pass; d=google.com; s=arc-20160816; b=xXhBhm2u8N3ryE7UJDr6uS1NpatDS/FsfQs4LeCyNeaE6qhu7rWKipaN4fq+ViYrFK U6/1v8PqgQbepk4pKp5cYKalKu+WVO9K0vx7zqKmXVXFbgxiWTF5RKKm0wV2gd+3Pmc6 +aZjO/gNAS26dPfObeyHlCokLC/3VcGjxljZwCC1OvuRXm8wDdcjXDQ6vfSZtxnVpcxu Paqql63ma6kJIjLp6NWu8yqBVlIEZHDcsrMh9dFWgI1pNFHmEciXHw4JyoRi1h5VuZ3D 279U4aR+74i8eGFJ1zUr35ClV3YCF6IjI4lZOBEl/CtJCauQhyd8sqgJEtMIwSbjmv36 MZNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=bYMtIg24uuXRIsgSP6U1ynvtwWf0bDfr47PWEVug3DI=; fh=k0/+Sq1uQ5xJKeq97Pbx2Tp5LIzTG1BFV8dn9s5pSTs=; b=suBzzsQgFlcNs4IIfcceBLhB5UMl+6GYQQqWhoEOVI++hNJPt7MTWgldLsQVd1ET0N xUJdPIvLDdm35sXhkegJZ3f/yoxx6m2u47euFUyPyoG+C0lN4TIbV9zw63LOw5lj2Zv1 H+FG/VXZI9uNqpOFS7tY6Ou1L7TIOvJVNZSwaqgGHCzoaeTFmvCFkW8l0Enuiqu9MMDY HNHIqhIN3BgjiPw2NtbZUSUs6GaphLZrFuvNahLOL6ZxP7N/lKTgOGUJg2d9/sK6rY5g uPasdQx06oouAzrF4cz65ArcUosTcZGAcd0Q+ElDJK1Hii1KWoQceBoAHtDlwfL5sHZ7 +tcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dulMkqUV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCUpyHbTQBAO+T/UUnAC1NdjcaT8wcHqa/gf4MjwzNakVPvkE6tkvKcNc3xb32D73eI1q5kO/w0tt9GRUbKmqG+lRbx90Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id ob13-20020a17090b390d00b00296908f6464si2303714pjb.53.2024.02.05.08.55.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:55:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dulMkqUV; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-53048-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B049B28161F for ; Mon, 5 Feb 2024 16:53:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D0553D558; Mon, 5 Feb 2024 16:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dulMkqUV" Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DB3A48CC6; Mon, 5 Feb 2024 16:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151759; cv=none; b=kDV3jYbd8WbOony1FYgzNs443brE9A1RbOT9f7CrH1eBjXLo4yLuNxOa9fzLxOrQXUbQLJb2nCn6rS80Ac5o3+qj65V8CmuQv8w8DqkfwpF3O72Os8WtrD+dqmfFFkQKslYHu8wjCObvgHftIr+gSzTL0LzkjH4JPhND9JIfkd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151759; c=relaxed/simple; bh=CpFiKt9arcAd/DdvTfXA++kS54iSLovvRvO3R5Xb+n0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FONmCxTOhvz/lGsDboIkN03IPpSejAHHmQsR++C7MYoG1GXFskVttKhxJzc1XxQ7fWhNwLazR2OUao7BHZyATLRpgPk3YLFANsPGROc12262MSRqj/tz/ixbMHUI08TVypc0zEDj8s9RSGroAtBWopLD+JFx3pSjIau0j3zaY7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dulMkqUV; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40ef3f351d2so32318365e9.1; Mon, 05 Feb 2024 08:49:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707151755; x=1707756555; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bYMtIg24uuXRIsgSP6U1ynvtwWf0bDfr47PWEVug3DI=; b=dulMkqUVKhjak1U9MiqknnEk24hi34gEIH2n3HDK0hzv4NkhdmY5oZOmsBT2M3KoGy yhghr+ROc1HX7g9FKT5qDDiBgnkuGkIly9TX348TLUCJfdDttA5y8C7nDI6ujuTidGNv OwjXenArg/sBpEXu9cCyaGEfLx6/yRoAEwbQQUwIwNUhXU+aVDpV2LdQNAYE9rt+08JC 6xijSIt2FaJ/SF0pIcuaAGJNbiQgDxePBklKmwJDBSvgsCheJ7/KENLd96cuegt3BDzi Xja9CpeEnNlM1WCe1ZePGhnzUrF1+NUuWEeWCDjze/2S3V2DkwG7BpDIpbzIDAOOjM6k Eb8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707151755; x=1707756555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bYMtIg24uuXRIsgSP6U1ynvtwWf0bDfr47PWEVug3DI=; b=FpcP14YxD4xpHRbimp3tG7+2+gNNKTNtVE/ESkKljbUXhAIaSzp1QHMrcZ2dW1w/xH 2cFr9moZnGo6f/6IRN4cMFsmskOt/yVaxJcBXJZrVAeNTWY00LRSbWoH+yWwh2ZWceQs AEIMOG+fBFRDV5uphgPEWbL6uIldckDncAKjfSaP6IZ5NHBkEhCG0oXo+U1Wg9a+90jd IhV0+cI/ayTYkxoUoBWYWifa9nyFquhwsK4qySGxB7tXmMWElGXEAnDoPklD8HHBU0uB WvWkygADiNAfeYRXo1C8osd9QTXXhVB/sjtKapblRMA/1Pdrfx3GJkPDkcWdYqlNuz74 NfEw== X-Gm-Message-State: AOJu0YxwS0mtKw72ezXuGVTm2tYjQFrBXyZ1A66P479WEZx1Sad5YV5b fQ+XszqccsVE4eSoDDDmM8nIi0KDYhDKJpx/BQNE8/mlywQplBDJ X-Received: by 2002:a05:600c:35cf:b0:40f:dc7e:e286 with SMTP id r15-20020a05600c35cf00b0040fdc7ee286mr177541wmq.13.1707151755398; Mon, 05 Feb 2024 08:49:15 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW/3uOUeZhpHZvSDxp4PR2FAfP70ve3t1SpGhfGkEOb3LU5Xilm2HOcMbTQGdsrji1efEw0amW1O7ZqoNFRrpe8zLZErYie2reMvwxQigfLh14m8q40Yw4qffaqdwj6P+ea1vLNhcsEzZX6QFdovi7k9cod4R8Y44jofeB0HknIFmL9rk4zMM1mSBpYcsNcY5PiIszlIZXYQDmSyA4yU7yWXxkVL5fMFUx2rm0DmOP2NKtMgO7GEyrMVjxPixaehdkEO9jkK+48zOes0XmPkD5WAwPncLi2MJryaFY/hd8scT6mlu3OVex278r3v3+vVcueT/7XcQCuYPJWTaUmK/CdC6NB+wNEVPBtVFJnxqWbKsV8iKEviZWfoo2w2sIbgPJj+NdyO9sJLM1A90j/IYl3Dlb8+dTybkYztz+eEwEYI0vIxJZ5+38CHURfc6S1dxaQgkjyC7MPAYsD/Fx5gHPLctPiYAVDptyC1/TQtMuV34Wcrqv1fM2aL94CpN75ABxKVXksI/9BI/p1vZ36jdDa9GHezu4PszG7hfD1uspnbljopQ9gSFurzChW4JEZNwJ7d0Ml7vfZCZElKsXYQovjiYKnW9ZRpDdzr6fzV/rHQoi55TKSff1Z6P0CMIjyaHP1trQpQfzi8Jt3qD0W4sc+cxaCaf8taP5ZXgJGnx3vZ3Sf7rjitg== Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id k2-20020a05600c1c8200b0040fafd84095sm9140567wms.41.2024.02.05.08.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:49:15 -0800 (PST) From: Christian Marangi To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Andrew Lunn , Heiner Kallweit , Russell King , Florian Fainelli , Broadcom internal kernel review list , Christian Marangi , Robert Marko , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [net-next PATCH v6 10/10] net: phy: qca807x: add support for configurable LED Date: Mon, 5 Feb 2024 17:48:42 +0100 Message-ID: <20240205164851.1351-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240205164851.1351-1-ansuelsmth@gmail.com> References: <20240205164851.1351-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790078720989464571 X-GMAIL-MSGID: 1790078720989464571 QCA8072/5 have up to 2 LEDs attached for PHY. LEDs can be configured to be ON/hw blink or be set to HW control. Hw blink mode is set to blink at 4Hz or 250ms. PHY can support both copper (TP) or fiber (FIBRE) kind and supports different HW control modes based on the port type. HW control modes supported for netdev trigger for copper ports are: - LINK_10 - LINK_100 - LINK_1000 - TX - RX - FULL_DUPLEX - HALF_DUPLEX HW control modes supported for netdev trigger for fiber ports are: - LINK_100 - LINK_1000 - TX - RX - FULL_DUPLEX - HALF_DUPLEX LED support conflicts with GPIO controller feature and must be disabled if gpio-controller is used for the PHY. Signed-off-by: Christian Marangi --- drivers/net/phy/qcom/qca807x.c | 256 ++++++++++++++++++++++++++++++++- 1 file changed, 254 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/qcom/qca807x.c b/drivers/net/phy/qcom/qca807x.c index de8ea94c15f7..1ec60eeca3c3 100644 --- a/drivers/net/phy/qcom/qca807x.c +++ b/drivers/net/phy/qcom/qca807x.c @@ -57,8 +57,18 @@ #define QCA807X_MMD7_LED_CTRL(x) (0x8074 + ((x) * 2)) #define QCA807X_MMD7_LED_FORCE_CTRL(x) (0x8075 + ((x) * 2)) -#define QCA807X_GPIO_FORCE_EN BIT(15) -#define QCA807X_GPIO_FORCE_MODE_MASK GENMASK(14, 13) +/* LED hw control pattern for fiber port */ +#define QCA807X_LED_FIBER_PATTERN_MASK GENMASK(11, 1) +#define QCA807X_LED_FIBER_TXACT_BLK_EN BIT(10) +#define QCA807X_LED_FIBER_RXACT_BLK_EN BIT(9) +#define QCA807X_LED_FIBER_FDX_ON_EN BIT(6) +#define QCA807X_LED_FIBER_HDX_ON_EN BIT(5) +#define QCA807X_LED_FIBER_1000BX_ON_EN BIT(2) +#define QCA807X_LED_FIBER_100FX_ON_EN BIT(1) + +/* Some device repurpose the LED as GPIO out */ +#define QCA807X_GPIO_FORCE_EN QCA808X_LED_FORCE_EN +#define QCA807X_GPIO_FORCE_MODE_MASK QCA808X_LED_FORCE_MODE_MASK #define QCA807X_FUNCTION_CONTROL 0x10 #define QCA807X_FC_MDI_CROSSOVER_MODE_MASK GENMASK(6, 5) @@ -121,6 +131,233 @@ static int qca807x_cable_test_start(struct phy_device *phydev) return 0; } +static int qca807x_led_parse_netdev(struct phy_device *phydev, unsigned long rules, + u16 *offload_trigger) +{ + /* Parsing specific to netdev trigger */ + switch (phydev->port) { + case PORT_TP: + if (test_bit(TRIGGER_NETDEV_TX, &rules)) + *offload_trigger |= QCA808X_LED_TX_BLINK; + if (test_bit(TRIGGER_NETDEV_RX, &rules)) + *offload_trigger |= QCA808X_LED_RX_BLINK; + if (test_bit(TRIGGER_NETDEV_LINK_10, &rules)) + *offload_trigger |= QCA808X_LED_SPEED10_ON; + if (test_bit(TRIGGER_NETDEV_LINK_100, &rules)) + *offload_trigger |= QCA808X_LED_SPEED100_ON; + if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules)) + *offload_trigger |= QCA808X_LED_SPEED1000_ON; + if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &rules)) + *offload_trigger |= QCA808X_LED_HALF_DUPLEX_ON; + if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &rules)) + *offload_trigger |= QCA808X_LED_FULL_DUPLEX_ON; + break; + case PORT_FIBRE: + if (test_bit(TRIGGER_NETDEV_TX, &rules)) + *offload_trigger |= QCA807X_LED_FIBER_TXACT_BLK_EN; + if (test_bit(TRIGGER_NETDEV_RX, &rules)) + *offload_trigger |= QCA807X_LED_FIBER_RXACT_BLK_EN; + if (test_bit(TRIGGER_NETDEV_LINK_100, &rules)) + *offload_trigger |= QCA807X_LED_FIBER_100FX_ON_EN; + if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules)) + *offload_trigger |= QCA807X_LED_FIBER_1000BX_ON_EN; + if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &rules)) + *offload_trigger |= QCA807X_LED_FIBER_HDX_ON_EN; + if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &rules)) + *offload_trigger |= QCA807X_LED_FIBER_FDX_ON_EN; + break; + default: + return -EOPNOTSUPP; + } + + if (rules && !*offload_trigger) + return -EOPNOTSUPP; + + return 0; +} + +static int qca807x_led_hw_control_enable(struct phy_device *phydev, u8 index) +{ + u16 reg; + + if (index > 1) + return -EINVAL; + + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + return qca808x_led_reg_hw_control_enable(phydev, reg); +} + +static int qca807x_led_hw_is_supported(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + u16 offload_trigger = 0; + + if (index > 1) + return -EINVAL; + + return qca807x_led_parse_netdev(phydev, rules, &offload_trigger); +} + +static int qca807x_led_hw_control_set(struct phy_device *phydev, u8 index, + unsigned long rules) +{ + u16 reg, mask, offload_trigger = 0; + int ret; + + if (index > 1) + return -EINVAL; + + ret = qca807x_led_parse_netdev(phydev, rules, &offload_trigger); + if (ret) + return ret; + + ret = qca807x_led_hw_control_enable(phydev, index); + if (ret) + return ret; + + switch (phydev->port) { + case PORT_TP: + reg = QCA807X_MMD7_LED_CTRL(index); + mask = QCA808X_LED_PATTERN_MASK; + break; + case PORT_FIBRE: + /* HW control pattern bits are in LED FORCE reg */ + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + mask = QCA807X_LED_FIBER_PATTERN_MASK; + break; + default: + return -EINVAL; + } + + return phy_modify_mmd(phydev, MDIO_MMD_AN, reg, mask, + offload_trigger); +} + +static bool qca807x_led_hw_control_status(struct phy_device *phydev, u8 index) +{ + u16 reg; + + if (index > 1) + return false; + + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + return qca808x_led_reg_hw_control_status(phydev, reg); +} + +static int qca807x_led_hw_control_get(struct phy_device *phydev, u8 index, + unsigned long *rules) +{ + u16 reg; + int val; + + if (index > 1) + return -EINVAL; + + /* Check if we have hw control enabled */ + if (qca807x_led_hw_control_status(phydev, index)) + return -EINVAL; + + /* Parsing specific to netdev trigger */ + switch (phydev->port) { + case PORT_TP: + reg = QCA807X_MMD7_LED_CTRL(index); + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg); + if (val & QCA808X_LED_TX_BLINK) + set_bit(TRIGGER_NETDEV_TX, rules); + if (val & QCA808X_LED_RX_BLINK) + set_bit(TRIGGER_NETDEV_RX, rules); + if (val & QCA808X_LED_SPEED10_ON) + set_bit(TRIGGER_NETDEV_LINK_10, rules); + if (val & QCA808X_LED_SPEED100_ON) + set_bit(TRIGGER_NETDEV_LINK_100, rules); + if (val & QCA808X_LED_SPEED1000_ON) + set_bit(TRIGGER_NETDEV_LINK_1000, rules); + if (val & QCA808X_LED_HALF_DUPLEX_ON) + set_bit(TRIGGER_NETDEV_HALF_DUPLEX, rules); + if (val & QCA808X_LED_FULL_DUPLEX_ON) + set_bit(TRIGGER_NETDEV_FULL_DUPLEX, rules); + break; + case PORT_FIBRE: + /* HW control pattern bits are in LED FORCE reg */ + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + val = phy_read_mmd(phydev, MDIO_MMD_AN, reg); + if (val & QCA807X_LED_FIBER_TXACT_BLK_EN) + set_bit(TRIGGER_NETDEV_TX, rules); + if (val & QCA807X_LED_FIBER_RXACT_BLK_EN) + set_bit(TRIGGER_NETDEV_RX, rules); + if (val & QCA807X_LED_FIBER_100FX_ON_EN) + set_bit(TRIGGER_NETDEV_LINK_100, rules); + if (val & QCA807X_LED_FIBER_1000BX_ON_EN) + set_bit(TRIGGER_NETDEV_LINK_1000, rules); + if (val & QCA807X_LED_FIBER_HDX_ON_EN) + set_bit(TRIGGER_NETDEV_HALF_DUPLEX, rules); + if (val & QCA807X_LED_FIBER_FDX_ON_EN) + set_bit(TRIGGER_NETDEV_FULL_DUPLEX, rules); + break; + default: + return -EINVAL; + } + + return 0; +} + +static int qca807x_led_hw_control_reset(struct phy_device *phydev, u8 index) +{ + u16 reg, mask; + + if (index > 1) + return -EINVAL; + + switch (phydev->port) { + case PORT_TP: + reg = QCA807X_MMD7_LED_CTRL(index); + mask = QCA808X_LED_PATTERN_MASK; + break; + case PORT_FIBRE: + /* HW control pattern bits are in LED FORCE reg */ + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + mask = QCA807X_LED_FIBER_PATTERN_MASK; + break; + default: + return -EINVAL; + } + + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, reg, mask); +} + +static int qca807x_led_brightness_set(struct phy_device *phydev, + u8 index, enum led_brightness value) +{ + u16 reg; + int ret; + + if (index > 1) + return -EINVAL; + + /* If we are setting off the LED reset any hw control rule */ + if (!value) { + ret = qca807x_led_hw_control_reset(phydev, index); + if (ret) + return ret; + } + + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + return qca808x_led_reg_brightness_set(phydev, reg, value); +} + +static int qca807x_led_blink_set(struct phy_device *phydev, u8 index, + unsigned long *delay_on, + unsigned long *delay_off) +{ + u16 reg; + + if (index > 1) + return -EINVAL; + + reg = QCA807X_MMD7_LED_FORCE_CTRL(index); + return qca808x_led_reg_blink_set(phydev, reg, delay_on, delay_off); +} + #ifdef CONFIG_GPIOLIB static int qca807x_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) { @@ -496,6 +733,16 @@ static int qca807x_probe(struct phy_device *phydev) "qcom,dac-disable-bias-current-tweak"); if (IS_ENABLED(CONFIG_GPIOLIB)) { + /* Make sure we don't have mixed leds node and gpio-controller + * to prevent registering leds and having gpio-controller usage + * conflicting with them. + */ + if (of_find_property(node, "leds", NULL) && + of_find_property(node, "gpio-controller", NULL)) { + phydev_err(phydev, "Invalid property detected. LEDs and gpio-controller are mutually exclusive."); + return -EINVAL; + } + /* Do not register a GPIO controller unless flagged for it */ if (of_property_read_bool(node, "gpio-controller")) { ret = qca807x_gpio(phydev); @@ -580,6 +827,11 @@ static struct phy_driver qca807x_drivers[] = { .suspend = genphy_suspend, .cable_test_start = qca807x_cable_test_start, .cable_test_get_status = qca808x_cable_test_get_status, + .led_brightness_set = qca807x_led_brightness_set, + .led_blink_set = qca807x_led_blink_set, + .led_hw_is_supported = qca807x_led_hw_is_supported, + .led_hw_control_set = qca807x_led_hw_control_set, + .led_hw_control_get = qca807x_led_hw_control_get, }, }; module_phy_driver(qca807x_drivers);