From patchwork Sun Mar 19 19:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13180538 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 9B5A4C7618A for ; Sun, 19 Mar 2023 19:19:47 +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=buiN1QSFbAxxtR2zpFuKJbqmi/f+X3lxCX6uFPKfBnM=; b=tOBTGkeJ4Zxl0F LDxKOgvel2px3mGzXbGhG9UObGKLYyKxZUyD2WzHCAUxfi43RxliG2Uvb8h34o1WUqACKkStlevop TjdrzABe7hCGYhQyGegL+TrJBXRgPlAGXAQ+baaDGK96oJJg04CBq59zazLemy7y5A7vRAZHOxEKQ zXIVprqi2KI5IsvlEMjOfLenN1kMxylSQHrcGQO1CQkny973XFtQZKKQR9f9pThIkAKwvQX0lR1bI C0Frbpsnc/AwRZq/fmeQaG6Lj7eCLzMftWRLfF+HHkfr7HY1vorE3HSSu4bsvGyHqJQ2aiOLCApfl cRZt/YCQ+/XtwiOp4zhw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pdyYQ-007Ego-0w; Sun, 19 Mar 2023 19:18:54 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pdyYF-007EZP-2d for linux-arm-kernel@lists.infradead.org; Sun, 19 Mar 2023 19:18:45 +0000 Received: by mail-wr1-x42f.google.com with SMTP id m2so8523706wrh.6 for ; Sun, 19 Mar 2023 12:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679253523; 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=NCx6caR6IZgTqSPdn2HwL+62wmCa1NHNRk8GEDmxS/c=; b=MMxVlZBgzFIcfZOHEwBaQwsI4ky4mTC9a0gj8/TxWSMHVPI9j3Qak2ZLUGvgfSX7Mx Dmr4mHC3hGAvUYAvivjDzt9B4vwWBvnm1ntuGwATuvl2skEjDKX07ttVZCwblzkZrLay OsWlINOoYzymwsYKwyVCbvD/e5P6jBddf6lG4RvBT2fMNMFNLIRYvDfRYCwNbsoOMfWo M/yIzvOJqBWvzngpzBIXELOwq2Ad9F4u+Q1yGDHsyRa1LLdFLE7Jgir4QQTjbSFCo8Qe Osk1yMdVUQYgrW0hnxCkWdK02K9GILrsgyKx1Ctl0tsmkEzRHAFYl9lDRC4IDB6h9vLR 7GvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679253523; 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=NCx6caR6IZgTqSPdn2HwL+62wmCa1NHNRk8GEDmxS/c=; b=AnCcTJ5Bv/CwJt+b7Bk9aaVEChl5836jLR/jrqdySQpHEpqRkdThHqpt2bH5kjKIKm Xc601eRvO6TkB4hRDI4RlrzfQSxcNlUX0l6v4Hd/145NATe54fqZPHbNw2HysnIx0qj8 o7iM/czPn/xY0NQQkgn49AIRrOJyzcbM5D0IpU6vpGJSZ2+FEkeYZ2RKi1x0uVF6dUjB TmnVNb+SIj9Erp2UljUm+j9r+eHSeC3rVvkmzVdyezQU9RruR+SRsxOGkQwxJRIAgRjT bSSu0L5CKkCbA0yooOnlHkDZuIuXMXFydwH7Oud3WTyUwKSJkl86LQY3EvSP/tDD7OcY bofQ== X-Gm-Message-State: AO0yUKXNLmlk9MWiS7Kzej0tkS5VOoSgbRL9R7Afqw4PuQSGQQr5FqSJ Vo7del9Pfhb0OLyHuzO5qQk= X-Google-Smtp-Source: AK7set8fsq6zQlxjf9ZFshDSZySkAXi7AJNk/hdFefpQPp7yImbuKtjN2QnYSs99mmKQyNUyTYQYuw== X-Received: by 2002:adf:de90:0:b0:2ce:aed4:7f22 with SMTP id w16-20020adfde90000000b002ceaed47f22mr12428360wrl.50.1679253523176; Sun, 19 Mar 2023 12:18:43 -0700 (PDT) Received: from localhost.localdomain (93-34-89-197.ip49.fastwebnet.it. [93.34.89.197]) by smtp.googlemail.com with ESMTPSA id b7-20020a5d4b87000000b002cfe0ab1246sm7165167wrt.20.2023.03.19.12.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 12:18:42 -0700 (PDT) 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 , Andy Gross , Bjorn Andersson , Konrad Dybcio , Pavel Machek , Lee Jones , Christian Marangi , John Crispin , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-leds@vger.kernel.org Subject: [net-next PATCH v5 06/15] net: phy: phy_device: Call into the PHY driver to set LED brightness Date: Sun, 19 Mar 2023 20:18:05 +0100 Message-Id: <20230319191814.22067-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230319191814.22067-1-ansuelsmth@gmail.com> References: <20230319191814.22067-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230319_121843_866282_B072FCF5 X-CRM114-Status: GOOD ( 19.34 ) 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 Signed-off-by: Christian Marangi Reviewed-by: Michal Kubiak --- drivers/net/phy/phy_device.c | 15 ++++++++++++--- include/linux/phy.h | 11 +++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 39af989947f9..141d63ef3897 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2991,11 +2991,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, @@ -3012,12 +3019,14 @@ static int of_phy_led(struct phy_device *phydev, return -ENOMEM; cdev = &phyled->led_cdev; + phyled->phydev = phydev; err = of_property_read_u32(led, "reg", &phyled->index); 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 11fb76a1c507..2a5ee66b79b0 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -841,15 +841,19 @@ struct phy_plca_status { * struct phy_led: An LED driven by the PHY * * @list: List of LEDs + * @phydev: PHY this LED is attached to * @led_cdev: Standard LED class structure * @index: Number of the LED */ struct phy_led { struct list_head list; + struct phy_device *phydev; struct led_classdev led_cdev; 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 * @@ -1072,6 +1076,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)