From patchwork Sat May 27 11:28:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687584 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45E89C7EE2C for ; Sat, 27 May 2023 11:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232334AbjE0L3V (ORCPT ); Sat, 27 May 2023 07:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbjE0L3S (ORCPT ); Sat, 27 May 2023 07:29:18 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AED80EC; Sat, 27 May 2023 04:29:17 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f6e72a1464so11282895e9.1; Sat, 27 May 2023 04:29:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186956; x=1687778956; 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=cKIEgFgmjScZJvZv6lwQPPIWSzDEZLIyZZgdXEW7tPM=; b=Qm7mtFvwyOtLsXMIBBdsJUUvDcTdhgqd7uvMQvrFYKE+PN5lndQuLSUSG3eNRNNcrl KYrI706mvURTxKfjsRzxAQ1XnSO6uKcOtiCvoLCbS8gZgPYA16FfQBoNFSTbHZcTlARs Hj/yKs8+BF/hkg02+3kNfu+ekWKXIA9DZKzDALjWAjV9k0Hn/zKowW5rgiGaNdqResMu +nMzJ5lSBWSrgo+KLd5ZckJuUnBPkXmgh9E6OjkboGwvOboQ7lwoyGedWUDBDiRfYG7m TwO68GP7st33FwoiMdbcJLjczZW6dT/odDu3MTtpBFsxmPA7lTPmP5p+QGVMDs2wgBMN JfDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186956; x=1687778956; 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=cKIEgFgmjScZJvZv6lwQPPIWSzDEZLIyZZgdXEW7tPM=; b=MkPcWJ8jNMAW6NsPpEPEpc9i3wyuF74Jmjju3PL/6PYszVx7jq55A9Pekv5XqGK/jp DUAoXsdTORSU8+q+D/q0nduSylRMZVpK8fcHANuO9BCacKo1pX8EnpesI7SYY3yjA85u qMlyDRoOHYPVK19JVhPuL2XJMx7EF8oPZAERK9RbSkIB4ROBuTl6zVvvBlOpCNzpUW1q TuEv8oIKu9SNL30RXQwFpxlsoMIUuh/ouDm91rJ2i2SR1qFjElaBKMewONgEhd/6Z+pv m2rqOUD49bn5T1Psp9/1yYXctkDeXspHiyo1PbrI2mUygkumGLDgc4iLa/DfdI8a86Wv HcPQ== X-Gm-Message-State: AC+VfDwaQ10+f9dZFpPSvGydkCjSr9y0u3PaS2QG4P+dmG6jLLqZxGoe uv/43E1aFEMcIMwc0Q2dFs0= X-Google-Smtp-Source: ACHHUZ7o1wkUaLli52LDfkiyqcqaayfOslQnq6OTbtulevqOtcaRNvN2RNEo5wvbWH7Ls3yp8J6Mig== X-Received: by 2002:a7b:c853:0:b0:3f4:239c:f19 with SMTP id c19-20020a7bc853000000b003f4239c0f19mr3880291wml.36.1685186955862; Sat, 27 May 2023 04:29:15 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:15 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 01/13] leds: add APIs for LEDs hw control Date: Sat, 27 May 2023 13:28:42 +0200 Message-Id: <20230527112854.2366-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add an option to permit LED driver to declare support for a specific trigger to use hw control and setup the LED to blink based on specific provided modes. Add APIs for LEDs hw control. These functions will be used to activate hardware control where a LED will use the provided flags, from an unique defined supported trigger, to setup the LED to be driven by hardware. Add hw_control_is_supported() to ask the LED driver if the requested mode by the trigger are supported and the LED can be setup to follow the requested modes. Deactivate hardware blink control by setting brightness to LED_OFF via the brightness_set() callback. Signed-off-by: Christian Marangi --- include/linux/leds.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index c39bbf17a25b..4caf559b1922 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -183,6 +183,43 @@ struct led_classdev { /* LEDs that have private triggers have this set */ struct led_hw_trigger_type *trigger_type; + + /* Unique trigger name supported by LED set in hw control mode */ + const char *hw_control_trigger; + /* + * Check if the LED driver supports the requested mode provided by the + * defined supported trigger to setup the LED to hw control mode. + * + * Return 0 on success. Return -EOPNOTSUPP when the passed flags are not + * supported and software fallback needs to be used. + * Return a negative error number on any other case for check fail due + * to various reason like device not ready or timeouts. + */ + int (*hw_control_is_supported)(struct led_classdev *led_cdev, + unsigned long flags); + /* + * Activate hardware control, LED driver will use the provided flags + * from the supported trigger and setup the LED to be driven by hardware + * following the requested mode from the trigger flags. + * Deactivate hardware blink control by setting brightness to LED_OFF via + * the brightness_set() callback. + * + * Return 0 on success, a negative error number on flags apply fail. + */ + int (*hw_control_set)(struct led_classdev *led_cdev, + unsigned long flags); + /* + * Get from the LED driver the current mode that the LED is set in hw + * control mode and put them in flags. + * Trigger can use this to get the initial state of a LED already set in + * hardware blink control. + * + * Return 0 on success, a negative error number on failing parsing the + * initial mode. Error from this function is NOT FATAL as the device + * may be in a not supported initial state by the attached LED trigger. + */ + int (*hw_control_get)(struct led_classdev *led_cdev, + unsigned long *flags); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED From patchwork Sat May 27 11:28:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686592 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60F8DC77B7C for ; Sat, 27 May 2023 11:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbjE0L3X (ORCPT ); Sat, 27 May 2023 07:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231678AbjE0L3T (ORCPT ); Sat, 27 May 2023 07:29:19 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C606CF3; Sat, 27 May 2023 04:29:18 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f6d01d390bso17282645e9.2; Sat, 27 May 2023 04:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186957; x=1687778957; 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=2XcetGsyY64nRsofxWNfYd5cm6afWXm/2XDUNvEa4CI=; b=dItUINqJ0j/EFzW9NkTjcU1vd9oNOuBXLj1889FO0p+5zqglA2/dqcacpIqXZSQApP fjwxnijxiC+GIao/6+lMnOoUshp63q4Ur8Tm3B26ERlVYjGh22ZOlSDs54h/BG6kRmJM ADdQ2we+9gXqsh6MEICdBNegPLsBf7mNtZ6VBgiWf1QTqDgnudM+qe8yM7hdHLrY0nN5 tG5gzA+fjyBJoO9HE2Yv7+UjgHfIirVT59zzswA2hX/EaV/aYDLjB5tFpcN+vP3EHKSf 5faA+7Na0f5/hHttMkH/JGFWuQMgNDpO79OzP9dqEzNO0rrBvOIIVycoVlJRnyGZWoY9 llOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186957; x=1687778957; 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=2XcetGsyY64nRsofxWNfYd5cm6afWXm/2XDUNvEa4CI=; b=bJGEfRBsH/jgcTtAJAZwGB+q2sPoRiMRMbEbt8kHi2ywNRC6zW+zaVYySjqU5Vvi/p V2Xa/AQJse4OGxvXnmStN7jAjzEfqNITJO4hi/zcUJJyuRwmeMlwm5qwbOLWHftZpZDU 2YrYBF6MIeevx+fJa5AytmcB7MN2qG5VF82TMn7sbqoGunAnoizMlfuV1NPx1DzFx3l1 Sr4lkAWKPhkr7/loDh8pJFPFStBbBWRWUxV9eIPpm7gPbepvJFAfS0TA5MndXzqiMwi1 yineszN0JfuPtMUCzq4LKc6+aeCgDLFN6831iUVay/mBmW+bGDDPoU1RjUfopoav7JWr J7Fw== X-Gm-Message-State: AC+VfDz8V0HfAbh6uIyZdwZo2nnqUOd7GfkNKS6olIAjGTxo4SIMVKiJ S8gHCtH4P6HWrYuagpC02Os= X-Google-Smtp-Source: ACHHUZ6xaD419xhM4dliKQFPwJi+MNWqeiTC2+J0+4So6yJxgnfzQvOTTUW6FTpD/GW0RWKVeW0kUA== X-Received: by 2002:a7b:c7c6:0:b0:3f5:f83:4d72 with SMTP id z6-20020a7bc7c6000000b003f50f834d72mr4531992wmk.38.1685186957126; Sat, 27 May 2023 04:29:17 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:16 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 02/13] leds: add API to get attached device for LED hw control Date: Sat, 27 May 2023 13:28:43 +0200 Message-Id: <20230527112854.2366-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Andrew Lunn Some specific LED triggers blink the LED based on events from a device or subsystem. For example, an LED could be blinked to indicate a network device is receiving packets, or a disk is reading blocks. To correctly enable and request the hw control of the LED, the trigger has to check if the network interface or block device configured via a /sys/class/led file match the one the LED driver provide for hw control for. Provide an API call to get the device which the LED blinks for. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- include/linux/leds.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index 4caf559b1922..3268b4e789d6 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -220,6 +220,12 @@ struct led_classdev { */ int (*hw_control_get)(struct led_classdev *led_cdev, unsigned long *flags); + /* + * Get the device this LED blinks in response to. + * e.g. for a PHY LED, it is the network device. If the LED is + * not yet associated to a device, return NULL. + */ + struct device *(*hw_control_get_device)(struct led_classdev *led_cdev); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED From patchwork Sat May 27 11:28:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687583 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 668E3C77B7E for ; Sat, 27 May 2023 11:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232370AbjE0L3Y (ORCPT ); Sat, 27 May 2023 07:29:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232338AbjE0L3V (ORCPT ); Sat, 27 May 2023 07:29:21 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04AFAEB; Sat, 27 May 2023 04:29:20 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3093d10442aso950186f8f.1; Sat, 27 May 2023 04:29:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186958; x=1687778958; 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=MgugxQZ+bMvGGxcEF4OyoNgsowC99irm6wJEB6lkhic=; b=p1gtB7w93BrsAnIdHC/SZ0tL2/Uk8WY7TIYkBFo11l4+3GETDj0VbCIAOa04T7kO/I bYmgqV/mWbv7gcBkhv3c26kDTATF5ltCvZjX2W5y/gRPaybKfPGKOL+dnCCENCOSe3Gx /PDlu0IFdvcnZcIL9BLHRP71v18Sp8Omxnkt2ICCbhHSlKSBgki+ydAApg4vu6JmGPHA S/wpnYlWAyNvkJghUdoD2z8ijY/Tem59qqqFnhhH/bzXNeme/Q3Yw65qZzTyaz45en+f 5Dc2n4b1cq0Gd6QuwcFoqeBV169IqjrSCWadHKDCqxrzqWkHEtTITR/A00MXAwLg16Iw LaTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186958; x=1687778958; 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=MgugxQZ+bMvGGxcEF4OyoNgsowC99irm6wJEB6lkhic=; b=ebQ6Y1NWtn34ooEopI31944h7sdPn4lO6LKUnGZkp2M8tTsSGr8fnPauZMDSgqXvJL 9GyJGBY4da81ugv/4ELe/eJbXENy3yiJl7OJLfuePM8JpBxcX5No+wWUmjcCn52UNZmR NM0WxRreh+zTnQ51jmGT/F7JYIkZYMatmd2v3PXbgYP3mNkUxPQr0S9nok6qs6KulWOP IyK8u054GftUpPH2bjsJNnJPMXPN+afwBvtgarPDccWWzxkwhjn9A/oKCTIz/eiR7Exl T1oAKoMr4phq/y15C4Eg7tAuEiXWvUmSgi1w1hvnh03loYoJIUrt6xw5LLkvYHZGARSW Hpjw== X-Gm-Message-State: AC+VfDzYv5MRGL/ljWQc81n3FU+yej01AZmxfbPawZBOcByxtW7rb1aA 6gmcK3IPEu+jfkGQaBPme5iwHRIJgDQ= X-Google-Smtp-Source: ACHHUZ7OOZunDzq9xudIHF/Hnk0SRfwCWYS+fM6RUgQ0fUDsJE+Ll3HNtpugNJKRDsq9a3g86Ff6lA== X-Received: by 2002:a5d:6e53:0:b0:306:4550:f651 with SMTP id j19-20020a5d6e53000000b003064550f651mr3615976wrz.4.1685186958279; Sat, 27 May 2023 04:29:18 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:17 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Date: Sat, 27 May 2023 13:28:44 +0200 Message-Id: <20230527112854.2366-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Document new Hardware driven LEDs APIs. Some LEDs can be programmed to be driven by hardware. This is not limited to blink but also to turn off or on autonomously. To support this feature, a LED needs to implement various additional ops and needs to declare specific support for the supported triggers. Add documentation for each required value and API to make hw control possible and implementable by both LEDs and triggers. Signed-off-by: Christian Marangi --- Documentation/leds/leds-class.rst | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index cd155ead8703..3d7874c18982 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -169,6 +169,86 @@ Setting the brightness to zero with brightness_set() callback function should completely turn off the LED and cancel the previously programmed hardware blinking function, if any. +Hardware driven LEDs +==================== + +Some LEDs can be programmed to be driven by hardware. This is not +limited to blink but also to turn off or on autonomously. +To support this feature, a LED needs to implement various additional +ops and needs to declare specific support for the supported triggers. + +With hw control we refer to the LED driven by hardware. + +LED driver must define the following value to support hw control: + + - hw_control_trigger: + unique trigger name supported by the LED in hw control + mode. + +LED driver must implement the following API to support hw control: + - hw_control_is_supported: + check if the flags passed by the supported trigger can + be parsed and activate hw control on the LED. + + Return 0 if the passed flags mask is supported and + can be set with hw_control_set(). + + If the passed flags mask is not supported -EOPNOTSUPP + must be returned, the LED trigger will use software + fallback in this case. + + Return a negative error in case of any other error like + device not ready or timeouts. + + - hw_control_set: + activate hw control. LED driver will use the provided + flags passed from the supported trigger, parse them to + a set of mode and setup the LED to be driven by hardware + following the requested modes. + + Set LED_OFF via the brightness_set to deactivate hw control. + + Return 0 on success, a negative error number on flags apply + fail. + + - hw_control_get: + get active modes from a LED already in hw control, parse + them and set in flags the current active flags for the + supported trigger. + + Return 0 on success, a negative error number on failing + parsing the initial mode. + Error from this function is NOT FATAL as the device may + be in a not supported initial state by the attached LED + trigger. + + - hw_control_get_device: + return the device associated with the LED driver in + hw control. A trigger might use this to match the + returned device from this function with a configured + device for the trigger as the source for blinking + events and correctly enable hw control. + (example a netdev trigger configured to blink for a + particular dev match the returned dev from get_device + to set hw control) + + Return a device or NULL if nothing is currently attached. + +LED driver can activate additional modes by default to workaround the +impossibility of supporting each different mode on the supported trigger. +Example are hardcoding the blink speed to a set interval, enable special +feature like bypassing blink if some requirements are not met. + +A trigger should first check if the hw control API are supported by the LED +driver and check if the trigger is supported to verify if hw control is possible, +use hw_control_is_supported to check if the flags are supported and only at +the end use hw_control_set to activate hw control. + +A trigger can use hw_control_get to check if a LED is already in hw control +and init their flags. + +When the LED is in hw control, no software blink is possible and doing so +will effectively disable hw control. Known Issues ============ From patchwork Sat May 27 11:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687582 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 770A1C7EE39 for ; Sat, 27 May 2023 11:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232453AbjE0L33 (ORCPT ); Sat, 27 May 2023 07:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232376AbjE0L3Y (ORCPT ); Sat, 27 May 2023 07:29:24 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CA02EC; Sat, 27 May 2023 04:29:21 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f6e13940daso17602775e9.0; Sat, 27 May 2023 04:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186959; x=1687778959; 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=v7RZChTfO9Ux9viKPzKi7S1xLwMfKhuE6t9va88Kj50=; b=iN6MZBh3bwnGbc/rVTFMLjWGBVZYD40/7LBWCiGdf3EgrxXSR0FXg7N+P3V3UmgXXU XtBnf4Gb+DN/QlYPBwdvMZPb3SFpMJEjriX3ERsRHUpc1XzwFWMdRWEcgNsN/xWQcGBx x+xQtiR4FvmzXm7yvhOPbr8ZiVF47kJdFfVqQ7lGtOvQGOl95BpBWVMd51o3o61d8/2Q BWM42jj7IZFxWK++cx53Fm2KR9Y3Q7vC1VmcsEYRkZmy9tAkuWfj9UPoGZAg/F5srzkY rYic2cUHW+utChLenD7t5WMewxGXigZLWHGD0lvQocIsPV8Ypl0bBdpPbEn/9MWLvg+l hAlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186959; x=1687778959; 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=v7RZChTfO9Ux9viKPzKi7S1xLwMfKhuE6t9va88Kj50=; b=fvuNh5O4myFSadwA7N8eMWspKgdQbvwWmHLwm5IzfqoeRq3US8Yo9AYdF98tyP3q2y F89+JiV1qwI2NhFLPoM+6vcVTpdKF36KEyEujIMBigOiyHVEExNhpW0j5bYB+/Nkgss/ Squs8ILzU5CNeth2hnrvPbe1MIpxOicU2vcYPl5LBvJueD3xZQ6D8IAcqBvzzUx8TNA6 Iin+KqCkHDnSEmSCO9MYherkmp/7aK3rT4F+tBvoWVd2ULivQd/lWZlAiaDqAOEM+F4H +mBCifkAhxf0dFKlBu+mKLzioAHy5qH3zRClQEH3vdxEVuC4KSRMsWx5APf8nh/GkkO4 /csg== X-Gm-Message-State: AC+VfDzDul8lnfcWCIxOYxNaJyZSbPWuKF6rLE6WWgmmCbiNvgfVxVp1 ta4PRcQHYyaBeIRoIGn26A4= X-Google-Smtp-Source: ACHHUZ4udMvx+fzP447XANUJFeyP1f8M3T1T0wrGajT8JUCwePayM+xyaPaxx+/8+NnlkjPwXrEPTA== X-Received: by 2002:a05:600c:ac8:b0:3f4:16bc:bd19 with SMTP id c8-20020a05600c0ac800b003f416bcbd19mr4382139wmr.23.1685186959537; Sat, 27 May 2023 04:29:19 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:19 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 04/13] leds: trigger: netdev: refactor code setting device name Date: Sat, 27 May 2023 13:28:45 +0200 Message-Id: <20230527112854.2366-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Andrew Lunn Move the code into a helper, ready for it to be called at other times. No intended behaviour change. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 29 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 305eb543ba84..c93ac3bc85a6 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -104,15 +104,9 @@ static ssize_t device_name_show(struct device *dev, return len; } -static ssize_t device_name_store(struct device *dev, - struct device_attribute *attr, const char *buf, - size_t size) +static int set_device_name(struct led_netdev_data *trigger_data, + const char *name, size_t size) { - struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); - - if (size >= IFNAMSIZ) - return -EINVAL; - cancel_delayed_work_sync(&trigger_data->work); mutex_lock(&trigger_data->lock); @@ -122,7 +116,7 @@ static ssize_t device_name_store(struct device *dev, trigger_data->net_dev = NULL; } - memcpy(trigger_data->device_name, buf, size); + memcpy(trigger_data->device_name, name, size); trigger_data->device_name[size] = 0; if (size > 0 && trigger_data->device_name[size - 1] == '\n') trigger_data->device_name[size - 1] = 0; @@ -140,6 +134,23 @@ static ssize_t device_name_store(struct device *dev, set_baseline_state(trigger_data); mutex_unlock(&trigger_data->lock); + return 0; +} + +static ssize_t device_name_store(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t size) +{ + struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); + int ret; + + if (size >= IFNAMSIZ) + return -EINVAL; + + ret = set_device_name(trigger_data, buf, size); + + if (ret < 0) + return ret; return size; } From patchwork Sat May 27 11:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686591 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42BE2C7EE37 for ; Sat, 27 May 2023 11:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232153AbjE0L3a (ORCPT ); Sat, 27 May 2023 07:29:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232382AbjE0L3Z (ORCPT ); Sat, 27 May 2023 07:29:25 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 404C710E; Sat, 27 May 2023 04:29:22 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f6094cb2d2so16690365e9.2; Sat, 27 May 2023 04:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186960; x=1687778960; 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=DnUn0MEBWwXZf1tNVwC84UFbfwX24B+J30/BoHmbFJQ=; b=WDG8dMQW2OJkDbZJwqovUVF48h94OIk058AqmVj43fg7xKPIaWYRt9Bwx8HNbSCHAr TlUCxKk8z35xCy7U+Nbu91//2NJz6krRzUhYXe/e6IeURArepUOYjtlaFDtFJXNYoel9 osOGqPPt5DvKQ4f2UUh5GN/UY5NuOioubpYsuTE6VxH51Ax7t+y3GMTUOE/MfQFcMajO nMITJWFN0uk0vMLCYza86euM7GigVDEy3xAE963zR6sz6AeTizSNUl8ysB/BnRoBoca4 10lWB6jCuVtTFoFF2DTNMrEFWateUji3hHDI/P/mz+SoSr/3fiViZY3d/uWzACfSceFw maqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186960; x=1687778960; 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=DnUn0MEBWwXZf1tNVwC84UFbfwX24B+J30/BoHmbFJQ=; b=NlCEKwMugop4lw9CewOkvDXahK4owqibc7Yjn0P84lghWw8OofWf2JwPc/RYTJagX2 Oxjj3c6wFeUsS8pNWM1KC1OF8o03NFtFTwbMH9nQLHDXoFaQFixWqzBkp2QeDW+6ZcEL ugtZFihgkKji3AJ0agbKdqw06GWRE88J59KRg8wmRU9WR+9DvinzdTj/bV1Qc0iQH4zU orpbqqVBrqWHq0LWhxMxE6xEyJoDkosSCoT6R1sUZh1uaddf6tK7D8VY37V3P8Jt5ilp +YDtlvrqPArVKFPnH8L2/LzOASOXEUwf8HM2TC4KrRllpUFt91bit4uqgEBPk/COEw0F KmuA== X-Gm-Message-State: AC+VfDyMrBFgPj/eoHMn998dkM9gdHcfO+iNDl3owsfLw7yx5sIMRt9V Y3pXfjmCmMI2DmHJKS6Y9MY= X-Google-Smtp-Source: ACHHUZ6JTM8XbpmvCJlxYj8Rtvz6dBuZ+ot4DFiudILzmBmNW2iG45IvJ6F2Xx2tycvqnv61PTr8bg== X-Received: by 2002:a05:600c:22d7:b0:3f5:fb98:729e with SMTP id 23-20020a05600c22d700b003f5fb98729emr4048371wmg.22.1685186960578; Sat, 27 May 2023 04:29:20 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:20 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 05/13] leds: trigger: netdev: introduce check for possible hw control Date: Sat, 27 May 2023 13:28:46 +0200 Message-Id: <20230527112854.2366-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Introduce function to check if the requested mode can use hw control in preparation for hw control support. Currently everything is handled in software so can_hw_control will always return false. Add knob with the new value hw_control in trigger_data struct to set hw control possible. Useful for future implementation to implement in set_baseline_state() the required function to set the requested mode using LEDs hw control ops and in other function to reject set if hw control is currently active. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index c93ac3bc85a6..e1f3cedd5d57 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -51,6 +51,7 @@ struct led_netdev_data { unsigned long mode; bool carrier_link_up; + bool hw_control; }; enum led_trigger_netdev_modes { @@ -91,6 +92,11 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) } } +static bool can_hw_control(struct led_netdev_data *trigger_data) +{ + return false; +} + static ssize_t device_name_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -204,6 +210,8 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, else clear_bit(bit, &trigger_data->mode); + trigger_data->hw_control = can_hw_control(trigger_data); + set_baseline_state(trigger_data); return size; From patchwork Sat May 27 11:28:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686590 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBA96C7EE3A for ; Sat, 27 May 2023 11:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232465AbjE0L3c (ORCPT ); Sat, 27 May 2023 07:29:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbjE0L30 (ORCPT ); Sat, 27 May 2023 07:29:26 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4540C124; Sat, 27 May 2023 04:29:23 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f6e4554453so11240475e9.3; Sat, 27 May 2023 04:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186962; x=1687778962; 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=9HiOL7lEFVgjMaEJrcmVlJpY1uQMDGELzriKpZXWbcM=; b=aOrW7o/W6hFBEZhqXwl4wHAvgp9au7WiULHRilZP3Q2xTYOZXVCsfnJtUSMDULCdhZ wS0bl+5AwKCS3Ij4UhZHZr2r5bWkFsq5j6WHJtOyJ3p4QKEHdqFXaxmPo+O6tycDvf9G 7V/6pSpzPBgJOc8Z3zpvAWm5iQ40CrorrnwA/LvI8bFsBKx/u0jPL9xv2pIAGWizjXX2 VQppOBgLTzwH3ScwWOvvFFR24VPQtLYAls76cUloxJCYlUGdQ7hl9gAs/wzQH031LwtO I4mYQ8e9buVjU1DD0lUzaGHZtz6ZZtn0HuxTZCdOvp28KkuhORcD2HkfuTvWFWf6iYZK HaXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186962; x=1687778962; 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=9HiOL7lEFVgjMaEJrcmVlJpY1uQMDGELzriKpZXWbcM=; b=Y8PFSfYPH22KeOaNfqHFTDMnCNrV5owbBHk8RhBLZ/GDikeOwiHtayDiwscglKnwmv vjuIOTvd30yajHPAALxk37wclTLO5p3zg2nvIxqYm0H74P6/FZy6ErM08/PuiPijXhS1 yO54lf3UUKB+TIu+hXKMzoCCTvmS8AhT2oNtfHhZDVyJLi4LzDqunFw0X0UIFA8NdtyO aZ9jbx6ajEKGh8b3ge11XzsuPiz9fYYmLJj84a77TmPERiJM7UBANrfSVhvZT31ps55C KIndHhZBH+FjrQ72T8c6/vCKdO5rf1zvskM5Uo5nz1NIJMuZqIscwyrPfID4YLAQb7CE ihsA== X-Gm-Message-State: AC+VfDwASpHCl/vSsllf1McAVX/Riufh9Zr6ImeZadY8RDZcIJtUuIGt Z9Q60udpQkdXe4S81sC9W2w= X-Google-Smtp-Source: ACHHUZ43haHLT1VQPLx8RjLuJVgl+/TPgdU/L/CT5L2PRDJ5Aj8MhWYqBbx1RqbtoGUVysE4syfKxg== X-Received: by 2002:a05:600c:d2:b0:3f6:536:a4b2 with SMTP id u18-20020a05600c00d200b003f60536a4b2mr3400538wmm.27.1685186961649; Sat, 27 May 2023 04:29:21 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:21 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 06/13] leds: trigger: netdev: add basic check for hw control support Date: Sat, 27 May 2023 13:28:47 +0200 Message-Id: <20230527112854.2366-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add basic check for hw control support. Check if the required API are defined and check if the defined trigger supported in hw control for the LED driver match netdev. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index e1f3cedd5d57..2101cbbda707 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -92,8 +92,22 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) } } +static bool supports_hw_control(struct led_classdev *led_cdev) +{ + if (!led_cdev->hw_control_get || !led_cdev->hw_control_set || + !led_cdev->hw_control_is_supported) + return false; + + return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name); +} + static bool can_hw_control(struct led_netdev_data *trigger_data) { + struct led_classdev *led_cdev = trigger_data->led_cdev; + + if (!supports_hw_control(led_cdev)) + return false; + return false; } From patchwork Sat May 27 11:28:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687581 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D64DC7EE2F for ; Sat, 27 May 2023 11:29:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232444AbjE0L3b (ORCPT ); Sat, 27 May 2023 07:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232403AbjE0L30 (ORCPT ); Sat, 27 May 2023 07:29:26 -0400 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 5D657125; Sat, 27 May 2023 04:29:24 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f6ef9a928fso8566775e9.3; Sat, 27 May 2023 04:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186963; x=1687778963; 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=AMFIVEMdnhDK+r9aZC4DEh7b5Mu4DnfdJk/ks7MSEOs=; b=oFS8fXqtG7ZzSuNm/074P17qC0dmFGT4gs+MWNTauiCXW3DHK1fzFIR1FAT74pZgmf Ci/P+tr5R9RLoMHNe56yI/7JKswjwBn17I8HtrBhkQCDPOJ7XTPO2uDj/Z7rcJAlvsLn CjNlTI7pN5oGJtmhASWQU/EXUZMe88XOpOG/itu2v7+NHUL7C/zLvcXLeP2iXTmMqnl4 Y3TYquVnsoS2cZtxt5QQihphNZpsYzqYrCp3RUAQgsfGoc43Eftrf8nF9sE/799zmBRD Yh4EEip0MJh4gLKrc4ryCj3yX3P9eYVyPWkIryv+tTMcwYrimzzoUtqyD1VJVpOuarko j3Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186963; x=1687778963; 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=AMFIVEMdnhDK+r9aZC4DEh7b5Mu4DnfdJk/ks7MSEOs=; b=gos0rUCHJ1vQmIPoRaxYcpHAPPHO/rArNFvcDiY5BlyY/6uSSDZepUP8jRCm1x6hzw /vVMIIfYrRe0OrnGaB5QPPwawc/9YQvG97+HHkZqBFLM+VwQNQj520ZxanPjy9/lDQEA QbmV8Doqtg/0UlQepSr/MOlVLjOSJSuZ72Dj3rU79/En1481A72XKuROnt+pkW3EgZ1H yHQw2D9KvDYLFWH/Mi/WQvwSB9d/5KcmyAIZOHNySRZGiArj9kjC1EsJeRaB0qC11PUJ OxXG78v1Vk2zIh65XWOou0NozMc56KJ7HaRfF2wQAYeCPiIJ/OFcN40OJdbjYsbImdIo PQSg== X-Gm-Message-State: AC+VfDwozvlxskTVhyG0SaANwKw497Ig8UourYxRA/lPaS5JDvTWk4BP jYX36cjhkzYa0BxWlPG+Ekk= X-Google-Smtp-Source: ACHHUZ4R4Z0admEnxkOxbdFIsjOFf2n29cgaZ0FjPhx7IlY+1Jrxi6DivoP338TZYARWn9TzhP14uw== X-Received: by 2002:adf:e30c:0:b0:2f7:e3aa:677a with SMTP id b12-20020adfe30c000000b002f7e3aa677amr3535704wrj.46.1685186962745; Sat, 27 May 2023 04:29:22 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:22 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 07/13] leds: trigger: netdev: reject interval store for hw_control Date: Sat, 27 May 2023 13:28:48 +0200 Message-Id: <20230527112854.2366-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Reject interval store with hw_control enabled. It's are currently not supported and MUST be set to the default value with hw control enabled. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 2101cbbda707..cb2ec33abc4e 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -265,6 +265,9 @@ static ssize_t interval_store(struct device *dev, unsigned long value; int ret; + if (trigger_data->hw_control) + return -EINVAL; + ret = kstrtoul(buf, 0, &value); if (ret) return ret; From patchwork Sat May 27 11:28:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686589 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08D04C7EE45 for ; Sat, 27 May 2023 11:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232487AbjE0L3d (ORCPT ); Sat, 27 May 2023 07:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjE0L31 (ORCPT ); Sat, 27 May 2023 07:29:27 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EDDFEC; Sat, 27 May 2023 04:29:25 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f6dbe3c230so17238705e9.3; Sat, 27 May 2023 04:29:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186964; x=1687778964; 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=duk7D4T1VAqrdSK3J+2RtTub/SxkfwJR2fWIQ5D7Ni0=; b=Q4eeR6uHB+pvn7nDFCDWVsNawzmGyfWCckzPa50tB46duXdpYa0FUEXppo34gUP5Ve KhZ41gWPtIIYeCeDCVUewl21fw46CGKI/QT50xt6SlyFwf9eGXNDBZJSzWCaJZsZ2UQ0 x744nbGK93FJa24T5L2aHkI3jGXn5TvqHkdCktB525myHQdZioP1rN//ul3w0CN/tWGA VEIfaGGCLVcglYU6EkLPCa8kkkRI5xDPAhY9KDdSlrlTBhTfMn9le7eVTxm/ZqKgew0K 3Lq2EjHORjkQTlPxvcgmPSNmmSm3StJYpeoeIWMivHhqjcaYHEuGp4rv/MLO9EZGcC6s Sj5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186964; x=1687778964; 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=duk7D4T1VAqrdSK3J+2RtTub/SxkfwJR2fWIQ5D7Ni0=; b=Tmeyhu3QvbnOqI4xYduce39zEVMyq3SV4yf/lIQcLRGY74wbWT5W+v2DlFDiy40Gtf NSJ8Vn2xwm/QTG5CdvAktLGnlZWLDpB6hAFv/eTUD4dY4Q7XMbr3wb3XvkB+lPpe6Il/ 0SHcYZza9x6NwdubjY+dvJedYxzjdS5R7j7GN92PdvpX7rESeftBf9l6erhr0UG84j1A nh6/JW5MY9kW4+NoCH9HZETcxwBmOrGKjf2mtcHtJCPHMrKejIkg8og5NqM6bF9eEsX4 9A/0bzB4BzqUd1Gp9jtvSnF8EICAqit7QZV+173Swqeq7bUaeAmD0jZBpg5qpjX5hkWs 3b0A== X-Gm-Message-State: AC+VfDx3Jt2bN5BKv3ZWDA8/JM45JK4AUEwjJXiGgbA86hOlzYXvNBJD jSBmGtlH17nfmB6VFbMrMUQ= X-Google-Smtp-Source: ACHHUZ5VvE6ydMGvSDb5vXsf3ZAjcrS5fakqvmcWUY+9rLxNoqR6cmva9vmr/Tj0XmTfWeD7VJw8Eg== X-Received: by 2002:a7b:c40f:0:b0:3f4:f7c2:d681 with SMTP id k15-20020a7bc40f000000b003f4f7c2d681mr4293720wmi.29.1685186963963; Sat, 27 May 2023 04:29:23 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:23 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 08/13] leds: trigger: netdev: add support for LED hw control Date: Sat, 27 May 2023 13:28:49 +0200 Message-Id: <20230527112854.2366-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add support for LED hw control for the netdev trigger. The trigger on calling set_baseline_state to configure a new mode, will do various check to verify if hw control can be used for the requested mode in can_hw_control() function. It will first check if the LED driver supports hw control for the netdev trigger, then will use hw_control_is_supported() and finally will call hw_control_set() to apply the requested mode. To use such mode, interval MUST be set to the default value and net_dev MUST be set. If one of these 2 value are not valid, hw control will never be used and normal software fallback is used. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 39 ++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index cb2ec33abc4e..8d6381415208 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -68,6 +68,13 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) int current_brightness; struct led_classdev *led_cdev = trigger_data->led_cdev; + /* Already validated, hw control is possible with the requested mode */ + if (trigger_data->hw_control) { + led_cdev->hw_control_set(led_cdev, trigger_data->mode); + + return; + } + current_brightness = led_cdev->brightness; if (current_brightness) led_cdev->blink_brightness = current_brightness; @@ -103,12 +110,42 @@ static bool supports_hw_control(struct led_classdev *led_cdev) static bool can_hw_control(struct led_netdev_data *trigger_data) { + unsigned int interval = atomic_read(&trigger_data->interval); struct led_classdev *led_cdev = trigger_data->led_cdev; + unsigned long default_interval = msecs_to_jiffies(50); + int ret; if (!supports_hw_control(led_cdev)) return false; - return false; + /* + * Interval must be set to the default + * value. Any different value is rejected if in hw + * control. + */ + if (interval != default_interval) + return false; + + /* + * net_dev must be set with hw control, otherwise no + * blinking can be happening and there is nothing to + * offloaded. + */ + if (!trigger_data->net_dev) + return false; + + /* Check if the requested mode is supported */ + ret = led_cdev->hw_control_is_supported(led_cdev, trigger_data->mode); + /* Fall back to software blinking if not supported */ + if (ret == -EOPNOTSUPP) + return false; + if (ret) { + dev_warn(led_cdev->dev, + "Current mode check failed with error %d\n", ret); + return false; + } + + return true; } static ssize_t device_name_show(struct device *dev, From patchwork Sat May 27 11:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687580 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48D0BC7EE32 for ; Sat, 27 May 2023 11:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232376AbjE0L3d (ORCPT ); Sat, 27 May 2023 07:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232452AbjE0L33 (ORCPT ); Sat, 27 May 2023 07:29:29 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBEB0134; Sat, 27 May 2023 04:29:26 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f603ff9c02so10975905e9.2; Sat, 27 May 2023 04:29:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186965; x=1687778965; 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=bzjSHLcSLKuyYbnB5oKrxVcxoSmgJOggg+ZfYlmNaGM=; b=QvdxWdjS+hkm5YxMe4Xjwx6raCsHbgdApVs96yBMFyu4JBQGn7WL9PTQjAf0MFsLhx ukBY+kIwoOZ1VW+GZt6vKfZ0XaRj/Xv4v0sukbM71DPI9aaxDYGow3jSnMGmvhqkjKCE J/keKNKvgB/O7f4DHcfj4Qh9iHIyz1cQW+XV1QBUy8zX3cvcq4/w+BTwDMjWmykuHmYo yQ2QNooQIEOuCLCS/Xo9FW75yFAzhqkU9ggDFFB3Injx28fVaYJgETUw9Yc7XgkMobgd J7p+68EqlpkZLPGF4yVngmqm+k5XmVPOEmbXhigcpaRkskDj5zyg9wWhOTmqpBSAtE3a 1jgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186965; x=1687778965; 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=bzjSHLcSLKuyYbnB5oKrxVcxoSmgJOggg+ZfYlmNaGM=; b=FhhBqoscuIs8qVhecoqhUa416htFYCS1bKOy4yKl4dTu2kWZrlnujSLFl/cWvaG9pd R54RXP6NCYmQKUj8fgOTCbVwflFmzxkEA4C24OOgjo8fESwIrPOu2s1geuQozWmLP8Lo NMswDrZm5fIrwdakOAnibbiXnvxDJ0Srd6Dj/lEq9ACF2Hhs+WlNQ/f7/2fLwsIfzyvk wNt2Zu2z19no59bdL2edPwGtGRuWbzw32rEhcb0XbGDO4Fv/kh8vizFR+T0TB7attcO8 skM1JS6adV638Wdrit7cnf+UDvL35PPPLt9Hy65J83I7L+19J7+hSaYsLim4klVugWGG 1XwA== X-Gm-Message-State: AC+VfDzDq2hqSUTr8pbxzObNiJwwnsM/ZS/J6UuPvdt4pyyoNW/xGJV0 oJg+k3tNAA13eRsBYFx+Fh4= X-Google-Smtp-Source: ACHHUZ6y9k7RyQ4acYi1QtYqybdqeTHG7B+8XEu2DH1j+5XI68i03hl312Mm/633WgXOLA6wjaYI3g== X-Received: by 2002:a1c:f70e:0:b0:3f5:1728:bde9 with SMTP id v14-20020a1cf70e000000b003f51728bde9mr3682830wmh.2.1685186965133; Sat, 27 May 2023 04:29:25 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:24 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 09/13] leds: trigger: netdev: validate configured netdev Date: Sat, 27 May 2023 13:28:50 +0200 Message-Id: <20230527112854.2366-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Andrew Lunn The netdev which the LED should blink for is configurable in /sys/class/led/foo/device_name. Ensure when offloading that the configured netdev is the same as the netdev the LED is associated with. If it is not, only perform software blinking. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 8d6381415208..5b59441fc415 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -108,6 +108,24 @@ static bool supports_hw_control(struct led_classdev *led_cdev) return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name); } +/* + * Validate the configured netdev is the same as the one associated with + * the LED driver in hw control. + */ +static bool validate_net_dev(struct led_classdev *led_cdev, + struct net_device *net_dev) +{ + struct device *dev = led_cdev->hw_control_get_device(led_cdev); + struct net_device *ndev; + + if (!dev) + return false; + + ndev = to_net_dev(dev); + + return ndev == net_dev; +} + static bool can_hw_control(struct led_netdev_data *trigger_data) { unsigned int interval = atomic_read(&trigger_data->interval); @@ -129,9 +147,11 @@ static bool can_hw_control(struct led_netdev_data *trigger_data) /* * net_dev must be set with hw control, otherwise no * blinking can be happening and there is nothing to - * offloaded. + * offloaded. Additionally, for hw control to be + * valid, the configured netdev must be the same as + * netdev associated to the LED. */ - if (!trigger_data->net_dev) + if (!validate_net_dev(led_cdev, trigger_data->net_dev)) return false; /* Check if the requested mode is supported */ From patchwork Sat May 27 11:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687579 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67D64C7EE2C for ; Sat, 27 May 2023 11:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231620AbjE0LaA (ORCPT ); Sat, 27 May 2023 07:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232486AbjE0L3c (ORCPT ); Sat, 27 May 2023 07:29:32 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A34E10E; Sat, 27 May 2023 04:29:29 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f68fc6b479so17456815e9.2; Sat, 27 May 2023 04:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186966; x=1687778966; 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=t032UqrKs2qK0Tmykkb/w0e10wBacVTlNSbQa7zNqmM=; b=BtKLeJJ6fl8D8E5IMrP9Oxr77Zt7QurslcYfR5GljVurKTTc5GRZccpr08y8UpmThl nQPxCuHPMkmroDFGSw/qNAU+qYz1bJy+klGJi5JgtZ1ETqGzKVzkRD27PT7r5Eb51y18 VT3xrNliCqVXK11joOG10TLSdMqyAXmOLslC0XWsHTDsx8FA0j2zTOicl9EVM37wBXdx aCuBAGkNU6gA2v83VqEEpjtW3Tt3IP/jgDRB27bMkaoaC/Gs1YjPHIrD8dDA4c/0usDr Bdo++hH7aVn9irKHKFtbp/R8im7SpHkb9KnpwnOd0x47R8fXofYkA2BsaTfnnq4nJ9NE J1PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186966; x=1687778966; 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=t032UqrKs2qK0Tmykkb/w0e10wBacVTlNSbQa7zNqmM=; b=V2qAHIPDinPCz+1nSmlhD3XQXNKNy7Vdx45VspTKaCTJYXNi3U5YI/mYejmKS7sSU8 aK3D3aVrJwfruPwbriJM8LzaiFKcebjAgrZgI5fo4jxK0fY1XMYxCghN8gCv4E7SC9Oq e8A8vOVw88euRK5WZ9ZHsz4YGcatslAYnmkuxX4gtVhGX62rrBbIDc65orraS+PeZvJf +gs2NT6npe/XAbYDCbJ50/lgmgJ7vJzWZr+jLoVInmjqC23VIhlKG+4ccRAt05fyHJTa lr90h0aVj5t+cIY62prlRc1VGSfLoDQf9kY5haIYntHnbo2BhoOmyiGvD5snYNOBoALk +GbQ== X-Gm-Message-State: AC+VfDzics8kJqJVFQwwdUWjxmb/hqNKJ6W3PIq+GlXn7FZEKiKXTTZH wfwYMk3xHFn6e/swwdHoO2E= X-Google-Smtp-Source: ACHHUZ42ImUe7BEsBhYL4fF76zPWy0NTUQC2m5IjDGbQpJKn6UtUD18UbfN/McWUMIzEQH5gAzpVdA== X-Received: by 2002:a05:600c:2209:b0:3f6:15f:e401 with SMTP id z9-20020a05600c220900b003f6015fe401mr3869447wml.37.1685186966404; Sat, 27 May 2023 04:29:26 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:25 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 10/13] leds: trigger: netdev: init mode if hw control already active Date: Sat, 27 May 2023 13:28:51 +0200 Message-Id: <20230527112854.2366-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org On netdev trigger activation, hw control may be already active by default. If this is the case and a device is actually provided by hw_control_get_device(), init the already active mode and set the bool to hw_control bool to true to reflect the already set mode in the trigger_data. Co-developed-by: Andrew Lunn Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 5b59441fc415..b0cab2b84ce2 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -452,6 +452,8 @@ static void netdev_trig_work(struct work_struct *work) static int netdev_trig_activate(struct led_classdev *led_cdev) { struct led_netdev_data *trigger_data; + unsigned long mode; + struct device *dev; int rc; trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); @@ -473,6 +475,21 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); trigger_data->last_activity = 0; + /* Check if hw control is active by default on the LED. + * Init already enabled mode in hw control. + */ + if (supports_hw_control(led_cdev) && + !led_cdev->hw_control_get(led_cdev, &mode)) { + dev = led_cdev->hw_control_get_device(led_cdev); + if (dev) { + const char *name = dev_name(dev); + + set_device_name(trigger_data, name, strlen(name)); + trigger_data->hw_control = true; + trigger_data->mode = mode; + } + } + led_set_trigger_data(led_cdev, trigger_data); rc = register_netdevice_notifier(&trigger_data->notifier); From patchwork Sat May 27 11:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686588 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 182B8C77B7E for ; Sat, 27 May 2023 11:30:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232532AbjE0L37 (ORCPT ); Sat, 27 May 2023 07:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232478AbjE0L3c (ORCPT ); Sat, 27 May 2023 07:29:32 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A951194; Sat, 27 May 2023 04:29:29 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f603ff9c02so10976015e9.2; Sat, 27 May 2023 04:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186968; x=1687778968; 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=KxSZPUywOkLEyYIsTb69Uiy6IYUweaN3dPoh9bCN08U=; b=URCGY0DjnJr3dFx90UfzqHf9Qhb+oM6F7KdENTY7rAPOShs5L/VQkM6OUP7fduRylO v5gfdDLoqq6iSgI+il56PB+q7lMsBvoc6/oael6KD0xBjkmVJ4QtavVkk7u6MqHt7CQL S3qR/5PGjLt7d4zUr6FQDwR71qmrwrfz+2ygNlI6SlK5G6ATHQaPZJIiuia0qVqdhj2B Givsn2i2wchhYdQ+MBIbSnq7cpB0bUo/NCDkpWECM27U/NiYE0hUQYuO4C0DTH8mA2kC ImssXuO4v2SnIYVy2dkwmEdMEC2RIvyB8xCEHNFUBfKXVc2fElHxNYcSO1Un7a1qe616 LySw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186968; x=1687778968; 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=KxSZPUywOkLEyYIsTb69Uiy6IYUweaN3dPoh9bCN08U=; b=kW1G97tcBz52BjPxhM4jwcFbTBdMDjJAIiMtKVV+nZug5iI6pBcRMRVJkgv6Yf7JPw 1GHP3rdaHsgsQgezoRyR8A2ZFMF9Z6k2VWX3nesbbwm25HtzYxaxCS6ud11qBmX1B7qa 5rNNSHzn4bPagDPdEysNe+S51qgb1OvASRpg7NGKrKWWTmL+6O2dFemtudZeyvrnsuvX 0LjQesFI/2UMO/CTUcCA5D/tROkpjSJEUNn63WqXzLqrtajZiQRe1/p8HwCERkKvNff8 4A0pJht6sBQX88ZNskPJVtaDjXFYQCChm9aRnU2vze0O+Yq/lS508S9z/2l9TDNhUYC+ Pgcg== X-Gm-Message-State: AC+VfDySNjKTs5v8zjNjSV9WHr20CPgmSAzaR0tlg09yyHraxhIxAVgb RplUfDQ2Ug7Uaxh+x9IHF24= X-Google-Smtp-Source: ACHHUZ4M4c2cW0Og7OtrUmhEcGHh/2HMj0K3FXRek1686jTNfghXqx9PTSMDfkOdyqFy9kyuiH4SEQ== X-Received: by 2002:a05:600c:2304:b0:3f4:ffaf:a862 with SMTP id 4-20020a05600c230400b003f4ffafa862mr4155453wmo.12.1685186967730; Sat, 27 May 2023 04:29:27 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:27 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 11/13] leds: trigger: netdev: expose netdev trigger modes in linux include Date: Sat, 27 May 2023 13:28:52 +0200 Message-Id: <20230527112854.2366-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Expose netdev trigger modes to make them accessible by LED driver that will support netdev trigger for hw control. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 9 --------- include/linux/leds.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index b0cab2b84ce2..8fbca94edfce 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -54,15 +54,6 @@ struct led_netdev_data { bool hw_control; }; -enum led_trigger_netdev_modes { - TRIGGER_NETDEV_LINK = 0, - TRIGGER_NETDEV_TX, - TRIGGER_NETDEV_RX, - - /* Keep last */ - __TRIGGER_NETDEV_MAX, -}; - static void set_baseline_state(struct led_netdev_data *trigger_data) { int current_brightness; diff --git a/include/linux/leds.h b/include/linux/leds.h index 3268b4e789d6..8af62ff431f0 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -552,6 +552,16 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) #endif /* CONFIG_LEDS_TRIGGERS */ +/* Trigger specific enum */ +enum led_trigger_netdev_modes { + TRIGGER_NETDEV_LINK = 0, + TRIGGER_NETDEV_TX, + TRIGGER_NETDEV_RX, + + /* Keep last */ + __TRIGGER_NETDEV_MAX, +}; + /* Trigger specific functions */ #ifdef CONFIG_LEDS_TRIGGER_DISK void ledtrig_disk_activity(bool write); From patchwork Sat May 27 11:28:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686587 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04036C77B7E for ; Sat, 27 May 2023 11:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232641AbjE0LaC (ORCPT ); Sat, 27 May 2023 07:30:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231806AbjE0L3e (ORCPT ); Sat, 27 May 2023 07:29:34 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB65219D; Sat, 27 May 2023 04:29:30 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f61530506aso17404315e9.1; Sat, 27 May 2023 04:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186969; x=1687778969; 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=GnV/8Q85nSdt4bY7Mc+wPerU54KxDdRii/0bQKKOJsU=; b=Cvry0QwO/7FtlBntWYzJ+RNBOP+bZSHRxMAwp9KlNvxM53sQsjVafOkk837ZEjPTzF 1BlhbKzj0sID078z3sFSQy7/qW+HIHsYakYeJQdYfrlhw+Dd1GoHh/+mooix+j1yybOW xxxx5eehHQUrfD0ZDvJIiSajYg+2it6VGHmJsRnRV58j6XnpHXRWVuy90ZyuvhBdGHu/ ea7EKy+Zg3qeoIh4PY3xg85mqRFBUj0GOXN45B3xpMQXkrJVgV8iHtS7CKxJ8zF/LP9H RvP33zLZZrZ3wgbMNQzYb2WsTcFNwLmsY89/zpc+vMqQOQdAKvhSiJs8C3c0zzFOpat0 Xf4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186969; x=1687778969; 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=GnV/8Q85nSdt4bY7Mc+wPerU54KxDdRii/0bQKKOJsU=; b=IVGVf5aOUyr1x5pOvqjg99eEXZOYRqdXM/c+xscD5tqTNipR2e+QVx2y3+//9RKVQK Uev6hae4S98JQ2/jQmGFvmF17mEjTiBVrHsTqf5GZSAyumvGfVvwRJIcI4pAmY2YJxUs 3H8XUD3fv/T+CVwWbKR+9k2jcCeByFGVK6BDeCsip9XYJmcLe1SrwJo7M/wteHE6r+s/ nd8bYmozGKc/ddN2I8hHfmewPxdrPJAkPXhpfU8cPZAzmzd9heY61lxmS77HuRcSJY+p DgHQ+IuBBvaSIIKtsPv5/aIWM2RfIZcHlGlMIzb9W8vs3O0aWo7ANbFsnMGA/vcwHs7P EmUg== X-Gm-Message-State: AC+VfDzWEmeSjINH7q0Rx5O4BMCKzfDuJ+K/iCXRe3Onztr37iU3rfa8 ZZoAwYyaqp129twiP8p5RD4= X-Google-Smtp-Source: ACHHUZ4hswjD9cILRUip9nHXWfWl4eUGTxVYNWiek6bwGLt4YdkqCJ8x/+ojN2JXxCVXmL7RkuxRwg== X-Received: by 2002:a1c:ed0b:0:b0:3f4:2174:b29d with SMTP id l11-20020a1ced0b000000b003f42174b29dmr4146853wmh.1.1685186968963; Sat, 27 May 2023 04:29:28 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:28 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 12/13] net: dsa: qca8k: implement hw_control ops Date: Sat, 27 May 2023 13:28:53 +0200 Message-Id: <20230527112854.2366-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Implement hw_control ops to drive Switch LEDs based on hardware events. Netdev trigger is the declared supported trigger for hw control operation and supports the following mode: - tx - rx When hw_control_set is called, LEDs are set to follow the requested mode. Each LEDs will blink at 4Hz by default. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/net/dsa/qca/qca8k-leds.c | 154 +++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/drivers/net/dsa/qca/qca8k-leds.c b/drivers/net/dsa/qca/qca8k-leds.c index b883692b7d86..1e0c61726487 100644 --- a/drivers/net/dsa/qca/qca8k-leds.c +++ b/drivers/net/dsa/qca/qca8k-leds.c @@ -31,6 +31,43 @@ qca8k_get_enable_led_reg(int port_num, int led_num, struct qca8k_led_pattern_en return 0; } +static int +qca8k_get_control_led_reg(int port_num, int led_num, struct qca8k_led_pattern_en *reg_info) +{ + reg_info->reg = QCA8K_LED_CTRL_REG(led_num); + + /* 6 total control rule: + * 3 control rules for phy0-3 that applies to all their leds + * 3 control rules for phy4 + */ + if (port_num == 4) + reg_info->shift = QCA8K_LED_PHY4_CONTROL_RULE_SHIFT; + else + reg_info->shift = QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT; + + return 0; +} + +static int +qca8k_parse_netdev(unsigned long rules, u32 *offload_trigger) +{ + /* Parsing specific to netdev trigger */ + if (test_bit(TRIGGER_NETDEV_TX, &rules)) + *offload_trigger |= QCA8K_LED_TX_BLINK_MASK; + if (test_bit(TRIGGER_NETDEV_RX, &rules)) + *offload_trigger |= QCA8K_LED_RX_BLINK_MASK; + + if (rules && !*offload_trigger) + return -EOPNOTSUPP; + + /* Enable some default rule by default to the requested mode: + * - Blink at 4Hz by default + */ + *offload_trigger |= QCA8K_LED_BLINK_4HZ; + + return 0; +} + static int qca8k_led_brightness_set(struct qca8k_led *led, enum led_brightness brightness) @@ -164,6 +201,119 @@ qca8k_cled_blink_set(struct led_classdev *ldev, return 0; } +static int +qca8k_cled_trigger_offload(struct led_classdev *ldev, bool enable) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + u32 mask, val = QCA8K_LED_ALWAYS_OFF; + + qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); + + if (enable) + val = QCA8K_LED_RULE_CONTROLLED; + + if (led->port_num == 0 || led->port_num == 4) { + mask = QCA8K_LED_PATTERN_EN_MASK; + val <<= QCA8K_LED_PATTERN_EN_SHIFT; + } else { + mask = QCA8K_LED_PHY123_PATTERN_EN_MASK; + } + + return regmap_update_bits(priv->regmap, reg_info.reg, mask << reg_info.shift, + val << reg_info.shift); +} + +static bool +qca8k_cled_hw_control_status(struct led_classdev *ldev) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + u32 val; + + qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); + + regmap_read(priv->regmap, reg_info.reg, &val); + + val >>= reg_info.shift; + + if (led->port_num == 0 || led->port_num == 4) { + val &= QCA8K_LED_PATTERN_EN_MASK; + val >>= QCA8K_LED_PATTERN_EN_SHIFT; + } else { + val &= QCA8K_LED_PHY123_PATTERN_EN_MASK; + } + + return val == QCA8K_LED_RULE_CONTROLLED; +} + +static int +qca8k_cled_hw_control_is_supported(struct led_classdev *ldev, unsigned long rules) +{ + u32 offload_trigger = 0; + + return qca8k_parse_netdev(rules, &offload_trigger); +} + +static int +qca8k_cled_hw_control_set(struct led_classdev *ldev, unsigned long rules) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + u32 offload_trigger = 0; + int ret; + + ret = qca8k_parse_netdev(rules, &offload_trigger); + if (ret) + return ret; + + ret = qca8k_cled_trigger_offload(ldev, true); + if (ret) + return ret; + + qca8k_get_control_led_reg(led->port_num, led->led_num, ®_info); + + return regmap_update_bits(priv->regmap, reg_info.reg, + QCA8K_LED_RULE_MASK << reg_info.shift, + offload_trigger << reg_info.shift); +} + +static int +qca8k_cled_hw_control_get(struct led_classdev *ldev, unsigned long *rules) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + u32 val; + int ret; + + /* With hw control not active return err */ + if (!qca8k_cled_hw_control_status(ldev)) + return -EINVAL; + + qca8k_get_control_led_reg(led->port_num, led->led_num, ®_info); + + ret = regmap_read(priv->regmap, reg_info.reg, &val); + if (ret) + return ret; + + val >>= reg_info.shift; + val &= QCA8K_LED_RULE_MASK; + + /* Parsing specific to netdev trigger */ + if (val & QCA8K_LED_TX_BLINK_MASK) + set_bit(TRIGGER_NETDEV_TX, rules); + if (val & QCA8K_LED_RX_BLINK_MASK) + set_bit(TRIGGER_NETDEV_RX, rules); + + return 0; +} + static int qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int port_num) { @@ -224,6 +374,10 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p port_led->cdev.max_brightness = 1; port_led->cdev.brightness_set_blocking = qca8k_cled_brightness_set_blocking; port_led->cdev.blink_set = qca8k_cled_blink_set; + port_led->cdev.hw_control_is_supported = qca8k_cled_hw_control_is_supported; + port_led->cdev.hw_control_set = qca8k_cled_hw_control_set; + port_led->cdev.hw_control_get = qca8k_cled_hw_control_get; + port_led->cdev.hw_control_trigger = "netdev"; init_data.default_label = ":port"; init_data.fwnode = led; init_data.devname_mandatory = true; From patchwork Sat May 27 11:28:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687578 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4C65C77B7C for ; Sat, 27 May 2023 11:30:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232545AbjE0LaD (ORCPT ); Sat, 27 May 2023 07:30:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbjE0L36 (ORCPT ); Sat, 27 May 2023 07:29:58 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F04AE1A7; Sat, 27 May 2023 04:29:30 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f6d01d390bso17285435e9.2; Sat, 27 May 2023 04:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186970; x=1687778970; 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=2brWjtv6jnUkszMlshgHY3ZyYZyBqSw+5iV+JVswSb0=; b=L5KTMgIiO/9V/rW4UXd0/vNZfWmTYhjyXHCbvHtt0VKY+AKdbZ7oX40PlkENMWbE9g K66ZFmZTvYt/SquTaVZ9HtkkIo4f82yQtzES8UmCTXUGZna2RFLZ67Rf3pubApXWkN7E 1Pi7CWsneHZLN54rJYhapKyzLt/ysq14OejARHNd563g7qgaLVco+vklV9z+NwaoXEmf rCIrRCj5eArvytFoj1glHriVa4BU5zzJgU1fqKBNXEEar6fHbo0XjK/3VV2PuCMWs1wv 2/kdKhn0xJdGYhqYWS0wbogCQOBCT9iUgvd3mS+K2AlGRiT4y2vIbzKXB9CFlcxGsDUT JpYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186970; x=1687778970; 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=2brWjtv6jnUkszMlshgHY3ZyYZyBqSw+5iV+JVswSb0=; b=XukrCTKq4yhz4yAM44WeM2gMNG5vLtntJu7vLXZ52VzEC30CTc8EykzMxFDc+lYsGn 2WBHQOcpy9br6vI35OkN9R45jfYWa3DrpSA8EP2jTaGtU23KJUH76KaLsZ5O2+Ix7YQj clMHy7G/L5NialdVr9/60gpP5EW5xo66XOHzeXc3+KZkhuUh074CzNrE6+6YJkKb4mwl lZGutH/JPXOGVyG9Se+lzQ/9/45Dg/TSGcr8KjO35OS1vZHWJFWBGOyBG7UJMIngMnrd tnM7IYCyAZ16lgD4i6Bw4psnPpucFQmBiOaC5XYQAxHjujsJVJF81C/m3+zOwzhPirzx llCw== X-Gm-Message-State: AC+VfDy7jzTaaY6xiNOX6fLCgpCFBGidXMtbJ45UTmtHYiVwN2o9t5XL epBXNJFFBh17ciSiAN1n7ng= X-Google-Smtp-Source: ACHHUZ7J1/hGeRrCVmt7IjZL29fn2EaxyD79iKVAh1CqYUQqBhrwRLrnqK4MwhFnyEeWb1ULitFV/Q== X-Received: by 2002:a05:600c:b54:b0:3f4:2174:b28a with SMTP id k20-20020a05600c0b5400b003f42174b28amr4097003wmr.15.1685186970261; Sat, 27 May 2023 04:29:30 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:29 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 13/13] net: dsa: qca8k: add op to get ports netdev Date: Sat, 27 May 2023 13:28:54 +0200 Message-Id: <20230527112854.2366-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Andrew Lunn In order that the LED trigger can blink the switch MAC ports LED, it needs to know the netdev associated to the port. Add the callback to return the struct device of the netdev. Add an helper function qca8k_phy_to_port() to convert the phy back to dsa_port index, as we reference LED port based on the internal PHY index and needs to be converted back. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/net/dsa/qca/qca8k-leds.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/net/dsa/qca/qca8k-leds.c b/drivers/net/dsa/qca/qca8k-leds.c index 1e0c61726487..6f02029b454b 100644 --- a/drivers/net/dsa/qca/qca8k-leds.c +++ b/drivers/net/dsa/qca/qca8k-leds.c @@ -5,6 +5,18 @@ #include "qca8k.h" #include "qca8k_leds.h" +static u32 qca8k_phy_to_port(int phy) +{ + /* Internal PHY 0 has port at index 1. + * Internal PHY 1 has port at index 2. + * Internal PHY 2 has port at index 3. + * Internal PHY 3 has port at index 4. + * Internal PHY 4 has port at index 5. + */ + + return phy + 1; +} + static int qca8k_get_enable_led_reg(int port_num, int led_num, struct qca8k_led_pattern_en *reg_info) { @@ -314,6 +326,20 @@ qca8k_cled_hw_control_get(struct led_classdev *ldev, unsigned long *rules) return 0; } +static struct device *qca8k_cled_hw_control_get_device(struct led_classdev *ldev) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + struct qca8k_priv *priv = led->priv; + struct dsa_port *dp; + + dp = dsa_to_port(priv->ds, qca8k_phy_to_port(led->port_num)); + if (!dp) + return NULL; + if (dp->slave) + return &dp->slave->dev; + return NULL; +} + static int qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int port_num) { @@ -377,6 +403,7 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p port_led->cdev.hw_control_is_supported = qca8k_cled_hw_control_is_supported; port_led->cdev.hw_control_set = qca8k_cled_hw_control_set; port_led->cdev.hw_control_get = qca8k_cled_hw_control_get; + port_led->cdev.hw_control_get_device = qca8k_cled_hw_control_get_device; port_led->cdev.hw_control_trigger = "netdev"; init_data.default_label = ":port"; init_data.fwnode = led;