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: 65898 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2362wrd; Tue, 7 Mar 2023 14:43:24 -0800 (PST) X-Google-Smtp-Source: AK7set8coJTlCidvBZCiKeT2953JZ8A3PSUmkdsf8P0eUGmRkNS2Tvfvg1SAznOzfSQAhhCA+S0R X-Received: by 2002:a17:90b:3143:b0:237:1f17:68ad with SMTP id ip3-20020a17090b314300b002371f1768admr16825789pjb.18.1678229004212; Tue, 07 Mar 2023 14:43:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678229004; cv=none; d=google.com; s=arc-20160816; b=lg4WJdt+lzLT8qgNdGcdo/Mf6AWy390omTjD53+j/15Kw/R1OvgbUmWfx5hnvfJx1v CJv3KlcPiHHa4sXwDX1VLWCtQMok5IMVmSF5FJ87rpcU+/2xGqYM8EzLDo5NlZh6WMPC bsYWV5b/f4hR0v3Lpd3NBjPUgPFeEZup8NUjZw8WMQZXCMnBaNpC/WGVPOUUUS2I2nZY rao75e7N8PzRXrCH6w60fcs50LvfzEQNiqpH2k8NpM/sFclv/7WQzGOjQSBIHjKumCVy r+PKq9p/kITzPKQJiIJoT0BoNkJvHfPAp7lY4dpw1uMjg3LW1+tRjULZzV7XP0ba/d6Y IFSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=WKaejEkwd7x7h0zVDdJBQrWswFotreBUxLmSKtjxwLI=; b=QRf7OCDr0ABA+e2IB9vha5hY+LBj3Sd1ab8RYLUDMAya/m47MNmf/2iS/YDE3WeLUA q0BnxrIM0GfV4l0FxEKYxRI1xeRNfwQ0z73eSEDwzDSfcaC+P+Gjr0dvIJIgZ6dj+bCq 6wEPWr00/tA5MlYvJvZebNQw1274QCywiN4OZuHAyHp0vCOqTfrJ65tnBRADNPOZu82h VSwkJ6owtU9Rur5e2b36/n68N6wpsZPpX085kEMoMBMhNMAHQ28GCfIlGtmLVPjxVaq/ X0+xkv/OJNXnp3HsY6yVO+TV/MFDf4xkLK/hoRBvPF88nyUD1GhWfY6yLI2LYPX8Pr24 uOIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=di+9QEKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a17090a410200b0023750b695e1si13603886pjf.156.2023.03.07.14.43.11; Tue, 07 Mar 2023 14:43:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=di+9QEKV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231414AbjCGWdy (ORCPT + 99 others); Tue, 7 Mar 2023 17:33:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjCGWdf (ORCPT ); Tue, 7 Mar 2023 17:33:35 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 031D79BE3C; Tue, 7 Mar 2023 14:33:31 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id ay29-20020a05600c1e1d00b003e9f4c2b623so88358wmb.3; 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=euSdGRkinHmeu7KC+PIer1UxDErUlPgDQttpaqPio6ZJlcBjDNpG8nYWHc/J13zAJq MgZoA8swcDAqpmmhb8frmI4LQS4Ib/ULA2/8j+MBtfhkRCjbKWi11rA5W9TYjNGTUYJs SB+l4m7dKmB4MY3LnjlQmsB7zGfJ34p4e5amRL4FtyPJjnhBGODTKDNsVqvLHMB7vSwg 3LqV7qR8SOsRQzoRc3Yjml7vNulDPq3ePu2QH4SlHTJkQg7u+hHaODr5H7h1sw0NW5tE 7N1ZfcttDYTRQn3wBCLFy6myjGZXFxbTCu4cc3wmKtmUiXxEMJ6pi0x8FwVu48QV/fH3 MyhA== X-Gm-Message-State: AO0yUKV0sBOT68VhSG4aI2QIUgrK9zA7C27zfPlYiNPE8+dfl8bKL+L4 GfvZsNdWkAs0K9tTEFh2aDQ= 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-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759750656308685202?= X-GMAIL-MSGID: =?utf-8?q?1759750656308685202?= 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)