From patchwork Tue Mar 7 17:00:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13164872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E0B3C6FA99 for ; Tue, 7 Mar 2023 22:34:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gjI0vTnWq5Qx1zJory79QAy66x6xtAeJtdjN0NSuHrk=; b=LHpxozyItzRuAq /N5O0rhH+5QGK7dnKUCpbE//SrRi+UwqmWr0zziuO/5aMXDyJhwa2ID9W2gVAm7QLfrH9Dq4XbVTk t5kz+pI3fqk5zrPHY/9DgZuIed+TY4+QVLYX1T6DViTETCe/X0yVqSJMGbTne6QxNIXM12BhA1Czf 4HIoW+g4uMsVmAmItHOXyPJUm5qjTnrnuzwAPE7V4qeskTaUn7ZWsbKafKoLWzkHcJoGaaBGyj18k RDlqlIk8651yTw+sd0T0kuWGubz0A7Q+qP7dZoN7JYqNP06CLJTwOd8ZuUmkQjzqNdrfp+zNi1qiP ZxK348pb6MdUjS49DPGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZfsW-002gxG-Ud; Tue, 07 Mar 2023 22:33:53 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZfsB-002gnY-8u for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 22:33:34 +0000 Received: by mail-wm1-x32e.google.com with SMTP id t25-20020a1c7719000000b003eb052cc5ccso86522wmi.4 for ; Tue, 07 Mar 2023 14:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678228410; 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=WKaejEkwd7x7h0zVDdJBQrWswFotreBUxLmSKtjxwLI=; b=di+9QEKVE16tj01XPCZMIyCFK7Anfrsm/6mIfACWi15xdVPAF2EGAhvTM9IdRpw9ci te1m+VbZXvxI4235YjygsOcjBJuyKGGKx2eMeTbCKaJhDh/d1jw87//ALmRbSqc5q2+F /9BvcJ4xRtTxjluUvFuoii/kKcUDAdPC750MkMuhCnr5Hziu0aCaJLPfXt5zcddcdzmf chBhXASMkrZZJL1XjDH2a774Mw2lzvULIg7EYshR1e9fRj9OX8jNkayWjihhhg6NdGpX yrMAq3QlBZaT0X3dHMfeipe5Y/mBJeBV8pAwjfUMi9Ohak7kxOPbCqCY5qFLyWHR9Imy IAhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678228410; 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=WKaejEkwd7x7h0zVDdJBQrWswFotreBUxLmSKtjxwLI=; b=bWdyg99oijxvnaXwZIdSSPYQ2Nou1CJgXer50TznJEy7WT/soC0VYLmSG8rAkcw34p QRKkdvSfSSP3JgJDYccix/3kjasx2QLkY9bOVFpIJh5mOfjxdgaAZijyqWFGnvbVJmog k78lQxEggIBVG+MwfYG61SuMsqxErkHwOPrN409CBfcndJ4TdMEsYoZ2VDsDGu8wHE6B 3cCxrQXXdxIxdThrRTUghxfzJViQVx2Q4hxn67CJhIjsaSNUvQfDvSjsF4ECaJb2rUPJ snyjKPZK5I9r9Ke3v/IRm4pwEHYZrBW4Rr6Gtl+xhfU2UUGIhjtX9E+6O2cLHR0JN8eZ GXKg== X-Gm-Message-State: AO0yUKXpTB5PwHu334WkablzOq+gkxrXcsRRbozyvwf/ETqJLl/UpBDP P7Kmup1eUDsXKjK9dL+bARc= X-Google-Smtp-Source: AK7set+X1R7wL4H+5FLmHv81NW3Frc4k/b4zPNyfVIi5ntM6gTNEfdWfJjKyJXPWyS8i48ZaQdOk/g== X-Received: by 2002:a05:600c:4ec6:b0:3e2:147f:ac16 with SMTP id g6-20020a05600c4ec600b003e2147fac16mr14763611wmq.10.1678228409772; Tue, 07 Mar 2023 14:33:29 -0800 (PST) Received: from localhost.localdomain (93-34-89-197.ip49.fastwebnet.it. [93.34.89.197]) by smtp.googlemail.com with ESMTPSA id q11-20020a05600c46cb00b003dc1d668866sm19233101wmo.10.2023.03.07.14.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 14:33:29 -0800 (PST) From: Christian Marangi To: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Heiner Kallweit , Russell King , Gregory Clement , Sebastian Hesselbarth , Christian Marangi , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lee Jones , linux-leds@vger.kernel.org Subject: [net-next PATCH 04/11] net: phy: phy_device: Call into the PHY driver to set LED brightness. Date: Tue, 7 Mar 2023 18:00:39 +0100 Message-Id: <20230307170046.28917-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307170046.28917-1-ansuelsmth@gmail.com> References: <20230307170046.28917-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_143331_341130_10159B14 X-CRM114-Status: GOOD ( 18.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Andrew Lunn Linux LEDs can be software controlled via the brightness file in /sys. LED drivers need to implement a brightness_set function which the core will call. Implement an intermediary in phy_device, which will call into the phy driver if it implements the necessary function. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy_device.c | 14 +++++++++++--- include/linux/phy.h | 9 +++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8acade42615c..e4df4fcb6b05 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2967,11 +2967,18 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) return phydrv->config_intr && phydrv->handle_interrupt; } -/* Dummy implementation until calls into PHY driver are added */ static int phy_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) { - return 0; + struct phy_led *phyled = to_phy_led(led_cdev); + struct phy_device *phydev = phyled->phydev; + int err; + + mutex_lock(&phydev->lock); + err = phydev->drv->led_brightness_set(phydev, phyled->index, value); + mutex_unlock(&phydev->lock); + + return err; } static int of_phy_led(struct phy_device *phydev, @@ -2995,7 +3002,8 @@ static int of_phy_led(struct phy_device *phydev, if (err) return err; - cdev->brightness_set_blocking = phy_led_set_brightness; + if (phydev->drv->led_brightness_set) + cdev->brightness_set_blocking = phy_led_set_brightness; cdev->max_brightness = 1; init_data.devicename = dev_name(&phydev->mdio.dev); init_data.fwnode = of_fwnode_handle(led); diff --git a/include/linux/phy.h b/include/linux/phy.h index 1b1efe120f0f..83d3ed7485e0 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -841,6 +841,8 @@ struct phy_led { u32 index; }; +#define to_phy_led(d) container_of(d, struct phy_led, led_cdev) + /** * struct phy_driver - Driver structure for a particular PHY type * @@ -1063,6 +1065,13 @@ struct phy_driver { /** @get_plca_status: Return the current PLCA status info */ int (*get_plca_status)(struct phy_device *dev, struct phy_plca_status *plca_st); + + /* Set a PHY LED brightness. Index indicates which of the PHYs + * led should be set. Value follows the standard LED class meaning, + * e.g. LED_OFF, LED_HALF, LED_FULL. + */ + int (*led_brightness_set)(struct phy_device *dev, + u32 index, enum led_brightness value); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv)