From patchwork Thu Apr 27 00:15:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 677635 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 A53CCC7618E for ; Thu, 27 Apr 2023 00:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242701AbjD0AS6 (ORCPT ); Wed, 26 Apr 2023 20:18:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239857AbjD0AS5 (ORCPT ); Wed, 26 Apr 2023 20:18:57 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2716810FC; Wed, 26 Apr 2023 17:18:56 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-2f7db354092so4887581f8f.2; Wed, 26 Apr 2023 17:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554734; x=1685146734; 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=SdiVbjZmufCfYZGTqSBv0vnzLEDigQlcPetMQEagMHI=; b=PP9Yp8ldCRrEWyqntxAeBH9dpX3Pm4XfjetIoe70tuK2lyz6wiUi6/S161gErESXgZ K8KJyV0Lkl7+UniI46zqKn+4gTUXH0eTPy5b2faqOcUInObEddcSilK+3kyev4DrxF4F bmVzOE3YHeRQRx2wEDnCRr5CB+5wqfjKOVHhoFfHaHkLsLa0wb1KFEg4I3zk1pzwA5MB FTGkmg9XPPP9msyPOzDSeBP5+gnJ67cchmYtQAZMm0m99AenFD3ESRwiUAuJ9VCcqHCm dz8B2uzTR+TfnrQpPEA+sHeFD0pCCnW45SpgNdnPEOQKrravxll3wfJ6DtlaWoxmk/mz Baow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554734; x=1685146734; 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=SdiVbjZmufCfYZGTqSBv0vnzLEDigQlcPetMQEagMHI=; b=ACFgr02jYglA5UMEP7/v6wOZ8opBjr6CCH3KwVYraDx5PG3dkS/8Ksbn9gIRAZgU+x Y1r+q0+s/Jm5HR8nKNbCIky8I7v2SZspQt7UkP943tDldIv7fK6L6a4/H5eoq2thTLGs KmFNofeYjXZJf3irapaU0wkAb2OcIrJw+LRRwFdWNdxvyoVXE8QwPKpgKoZtYB0fAfDY hZvRh+3vl9xHm+fVxz4HGuwXl81uUkzyu+01WhTmu7o8Al2OA4wkHS+4pPeBkFFZpdwr n+zf7eKtSLtiSJZuNqRfySo0M/qHI3OVQU8Y5q5n/q5BLw+T/8YRq7U1ip8zUCxaLE8P 1Vcg== X-Gm-Message-State: AAQBX9dq4l5lITrsey7zWdOEwDOSJ9u09rURy21nXctvrjoAJTtL56R5 Cgs3yvoYyE3hKMXzWJgd1eA= X-Google-Smtp-Source: AKy350arhA0yvQiwvx7ByKHU6VdBMqIKBIQcHSqsWw97PkcQJxYOTeEljpCViBCCtOWzwp1u4e+dww== X-Received: by 2002:adf:dfc3:0:b0:2ef:b3ef:9e82 with SMTP id q3-20020adfdfc3000000b002efb3ef9e82mr15571484wrn.57.1682554734179; Wed, 26 Apr 2023 17:18:54 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:18:53 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 01/11] leds: add binding for LEDs hw control Date: Thu, 27 Apr 2023 02:15:31 +0200 Message-Id: <20230427001541.18704-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-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 binding 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. Deactivate hardware blink control by setting brightness to LED_OFF via the brightness_set() callback. Signed-off-by: Christian Marangi --- include/linux/leds.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index ba4861ec73d3..b3bd1cc8ace8 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -154,6 +154,26 @@ 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; + /* + * 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. + */ + 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. + */ + int (*hw_control_get)(struct led_classdev *led_cdev, + unsigned long *flags); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED From patchwork Thu Apr 27 00:15:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 678279 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 08091C7EE23 for ; Thu, 27 Apr 2023 00:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242790AbjD0AS7 (ORCPT ); Wed, 26 Apr 2023 20:18:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242695AbjD0AS6 (ORCPT ); Wed, 26 Apr 2023 20:18:58 -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 DAC281FF2; Wed, 26 Apr 2023 17:18:56 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f19afc4fbfso56907385e9.2; Wed, 26 Apr 2023 17:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554735; x=1685146735; 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=JQLN6Kj8zf+yGWqAeSf/98ml910O+iserPB9frhTCgU=; b=ZxmP0RZFi4wMigwJWtc/nxrVk03RlZrZUK6UxenwjvgVKTjL8VtwM/ogBugNWIpEof +HTu40HqRdzq9cFXPdFhH3ZaKi5Jt17Mueer0n0IfvriF5JxMajyh1YC+5Ol9wST+5X1 RNMNxZQreigdZHUJmG1SXPJXyj+GDu6+9yTF8wpJ5XojuY4GeHbDVRJDjjVRwJkrlfGy DJNaaMgnDa9pr3JPRibdqcTBgCVoJhRpub/uMt8X1NcgSG1lTt5S07hwpY+EeG2Ef/0q PzaP8F3OJzSF2pzE/96eben9nfCchHQiOFRVS4tEA5eOhX3MfqpkMM/EkG2ACQP/d4jB J2gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554735; x=1685146735; 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=JQLN6Kj8zf+yGWqAeSf/98ml910O+iserPB9frhTCgU=; b=F35+3Tg733LvU++9BWafCxa/tYI893LPAafR46t4tf+g4/6hwbKdNrTtsMKwHKnVHf O0fWQOF0FjrShpRwCvdLWyPXoccdFo58yYiLVg5zMLwUo7RlY5M51HufuQEnrLn82TC6 PYE9G5oK36jIMpMTaYldWTIq5TJ9A1XUrlwgQXozPPxm5POhE6lPqY9z+CETWEYI+6nZ 1Q2akJLPLZYMc9BNvwlBKvAfsEl+CcPAs1jxL58Al6hGGK9cW3MOBOCBE/qiW2NWDlRt a+rDyjeAD8nmnWJRQIsXIct7VR7PdphRz01t3Ra4hHSODRZAKbY+jAXzJhW1V5bbRTTc 9brg== X-Gm-Message-State: AAQBX9f+RF8pA9XGKJgj6zVRt7qV+jtTFSZ3KBeAvyfv68X8R1v1win9 9KLFpoPVXmUAbBrmhNXhiyI= X-Google-Smtp-Source: AKy350Zwg/vVucdRJNBBseuh/duo9cKFNzZMJasEMQZW40wYwmJ6JygbjRhM5FoG4SfYgrloarMe1A== X-Received: by 2002:a5d:670e:0:b0:2de:e7c3:166f with SMTP id o14-20020a5d670e000000b002dee7c3166fmr15117006wru.62.1682554735382; Wed, 26 Apr 2023 17:18:55 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:18:54 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 02/11] leds: add binding to check support for LED hw control Date: Thu, 27 Apr 2023 02:15:32 +0200 Message-Id: <20230427001541.18704-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add 2 binding to facilitate checking support for LED hw control. Add a mask for the LED driver to declare support for specific modes of the defined hw control trigger. 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. Signed-off-by: Christian Marangi --- include/linux/leds.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index b3bd1cc8ace8..06a67c62ed6e 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -157,6 +157,8 @@ struct led_classdev { /* Unique trigger name supported by LED set in hw control mode */ const char *hw_control_trigger; + /* Mask of the different supported trigger mode in hw control mode */ + unsigned long trigger_supported_flags_mask; /* * Activate hardware control, LED driver will use the provided flags * from the supported trigger and setup the LED to be driven by hardware @@ -174,6 +176,12 @@ struct led_classdev { */ int (*hw_control_get)(struct led_classdev *led_cdev, unsigned long *flags); + /* + * Check if the LED driver supports the requested mode provided by the + * defined supported trigger to setup the LED to hw control mode. + */ + int (*hw_control_is_supported)(struct led_classdev *led_cdev, + unsigned long flags); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED From patchwork Thu Apr 27 00:15:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 677634 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 90B77C7EE25 for ; Thu, 27 Apr 2023 00:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242816AbjD0ATB (ORCPT ); Wed, 26 Apr 2023 20:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242677AbjD0AS7 (ORCPT ); Wed, 26 Apr 2023 20:18:59 -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 3B26410FC; Wed, 26 Apr 2023 17:18:58 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f182d745deso77781325e9.0; Wed, 26 Apr 2023 17:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554736; x=1685146736; 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=6nCO0bAV1fl1UMAb2NU6tG7bDtFqxmTJnKdetZK7lbg=; b=XeDD7IELGyQlMswgdeBLKCzRuckgJrekb3X9gp2H0BY+aAMuRtMUxYKxjrgbspI88p 0r/KrE8wX6wMWz27KUzQKCKVPkQJEN28w0Ap182fB7OqpOcdOiFD2zzdr3hIPqnbsZxP nvjHANtjPoqFOm0+tX2dRijCKWwf459l5AeH+GeQD+WNPfvxgndyWq63j9DejVj7O8Eq BF9/OLmMktpRbsmX0Kez0ozmbuJhgdS5Y0nKq+6DUxYeq8NSEWDArOG+AAynVuWt3WuS wFySdLWvZMsrb8D6TX9xz2NtNPtgyJ0hH9mXRtIzpqqS46IgwNz9zS6I9LGCsECzzmVF CRow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554736; x=1685146736; 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=6nCO0bAV1fl1UMAb2NU6tG7bDtFqxmTJnKdetZK7lbg=; b=jt1+cAkqv/68TpkAea3tpiCy78neL42G1JLno9isbUvrwHKvh1DJloSIMdIBq6ajtp 9XQuSHjOQQP0fuJgBBFPkpQRxMTZOWxaBhIFmVxU1wJ0NTzb+76a0eds8JaCHQSYQOac mC+7x5109C0G8ZsP8PC9PXaMJPrdXd3Dv1lX+7HJ/kCAXxLqTKZgdUR6GY+na9fg+b5F 8y729Z3W/ZQiFYmRLPAOuf01pqCfC9vsI349+3UXPdeUkMQU4i3Xbxx/LYIwKP36k0oh HbpMIZ92IehXUX+rcXCwnRF1ulNX+ReVY3hQpaczousrXzaKusx8BDHHQbpAkTj1UirC oN6Q== X-Gm-Message-State: AAQBX9dNt9Z+zyDAawFxHuxZsUiVPdudSKyaDD/3BVQkQV5bLWrIKx/k WmpXFpo6c46tdXWHdALWFUE= X-Google-Smtp-Source: AKy350Y3aQuv6BQ2YZjrckCx9etJKg4rHfc/tTYUbFUfH0Er4GmlaRqBspc0TDYvShtx1kVpIXkRFQ== X-Received: by 2002:a1c:4b1a:0:b0:3f0:9f44:c7ce with SMTP id y26-20020a1c4b1a000000b003f09f44c7cemr15091924wma.22.1682554736466; Wed, 26 Apr 2023 17:18:56 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:18:56 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 03/11] leds: add helper function to use trigger in hw blink mode Date: Thu, 27 Apr 2023 02:15:33 +0200 Message-Id: <20230427001541.18704-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add helper function to use trigger in hw blink mode. Add function led_trigger_can_hw_control() that will check if hw_control ops are defined and if the current trigger match the one supported for hw_control. Signed-off-by: Christian Marangi --- include/linux/leds.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index 06a67c62ed6e..b9152bff3a96 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -425,6 +425,14 @@ void led_trigger_blink_oneshot(struct led_trigger *trigger, void led_trigger_set_default(struct led_classdev *led_cdev); int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger); void led_trigger_remove(struct led_classdev *led_cdev); +static inline bool led_trigger_can_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 inline void led_set_trigger_data(struct led_classdev *led_cdev, void *trigger_data) From patchwork Thu Apr 27 00:15:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 678278 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 E69CDC77B7C for ; Thu, 27 Apr 2023 00:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242873AbjD0ATJ (ORCPT ); Wed, 26 Apr 2023 20:19:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239435AbjD0ATB (ORCPT ); Wed, 26 Apr 2023 20:19:01 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D991FF2; Wed, 26 Apr 2023 17:18:59 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f315712406so4551005e9.0; Wed, 26 Apr 2023 17:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554738; x=1685146738; 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=P3YTYYS21+pNeT0fpIDxBpeIvQtUm9X7UHJe+LvhUmc=; b=WqZHvtwy44nCqhuHOJeT+uRbCZ40ThRmY6HFy6dTe00EZT3Tf5Wa5ZWzTAGWYFjN9k tPhfKZ5Ngo3XCiUaE19Qd87GSdxbuj/5K7i6F3gZpXp7J4swNovpAyRZCc33wiqEgGhv sfy766e55PAApIT2+TweD4dKOLrZTCtEW7vWZ5MORchJPfvk1jXWYU3kKr+MYzcCdHFh OZM8Hc95UNdQaUgTAl7BH60dHXMfAjdkGZ2RRC9UxyfE2mGjaglS+9684PHIDf5uoaFj 5pPy6FJcgSyuO+PQ8euOAEtXc7XWzRbHxbhPtv+6cRrKOjGnFjhdgBmQbvUKe5wq+55c CQuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554738; x=1685146738; 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=P3YTYYS21+pNeT0fpIDxBpeIvQtUm9X7UHJe+LvhUmc=; b=iJFkpUXGYRURRJ0LqxYVoXqh2HjlauDKKckq/sFxNs1LbIb3AMCVVd6yd7yPze7oOe uaUEoOjDfgKNwLceseWIcvtCSymRL/Zr4JwbvzdwhgB0qsY4cPA1F643mkypNLcpmU0k kNF0Zutqh0Z3XSSz23AoNlCI7rXIa3N90zcDG3IWgreaGNX2cXra9/tRTgj9tDtbbdYm 8rqMRmt7GL0fv36T8JLZRz5htmNlcX21wetiyj8xJ36LMFQjdbf6tMX8q6iwSseAnEYH LwI2MKRErFOc9T2c++r9Q3pRtlAyfG3nL+7rTC0vdmL+/YVHdsLEPniqSdH5LVdheAem E3dQ== X-Gm-Message-State: AC+VfDxoLJWxi6fsTH8sucWLCs8Qi/2q/STU6AEA7UXXyIAXqf+oRszc 7Q5sYIywdqWQCWXIgDcTvDIvx2Pg8tA= X-Google-Smtp-Source: ACHHUZ6BWlCi67VAlpbuLSwmnBVGf+3J4jUSYkXOOC2bNcAQ2FHXi87rgktltjONam28hEQAga0fmg== X-Received: by 2002:a05:600c:1c22:b0:3f1:7a31:2c86 with SMTP id j34-20020a05600c1c2200b003f17a312c86mr2980252wms.16.1682554737558; Wed, 26 Apr 2023 17:18:57 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:18:57 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 04/11] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Date: Thu, 27 Apr 2023 02:15:34 +0200 Message-Id: <20230427001541.18704-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-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 entirely driven by hw. 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 | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index cd155ead8703..a7bc31e9b919 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -169,6 +169,62 @@ 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 entirely driven by hw. 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. + + - trigger_supported_flags_mask: + mask of the different supported trigger mode for the + defined trigger in hw control mode. + +LED driver must implement the following API to support hw control: + + - 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. + + - hw_control_get: + get from a LED already in hw control, the active modes, + parse them and set in flags the current active flags for + the supported trigger. + + - hw_control_is_supported: + check if the flags passed by the supported trigger can + be parsed and activate hw control on the LED. + +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 helper led_trigger_can_hw_control() is provided to check if the LED +can actually run in hw control. + +A trigger should first use such helper 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 Thu Apr 27 00:15:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 677633 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 CB313C7EE23 for ; Thu, 27 Apr 2023 00:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242895AbjD0ATK (ORCPT ); Wed, 26 Apr 2023 20:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242838AbjD0ATB (ORCPT ); Wed, 26 Apr 2023 20:19:01 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 704D33AA4; Wed, 26 Apr 2023 17:19:00 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-304935cc79bso2319355f8f.2; Wed, 26 Apr 2023 17:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554739; x=1685146739; 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=OIYgyKuwJ81AtZBMq4tmKJvwseDK3tdRGQbYOLsgLaU=; b=FNrRHJ0CJc/JgCz6dzu63p8tEJuFeVraat6eKkWBCSpEn+CoNPs8GwOh7FEnXrz6O+ IFr/z44PHwDIcubxHV8A33yhPHrLrCrE+DM1OeTspj5frHImfD9d2Ql5hI9qI92O9XtR lYuaxiK3Wix7uw9GIzRzhJNvzgO3j8AdWkYl1U+DYpx+2dfWSaMnWFWMpWnfon8P8N5o +8a4D6EgxHufaMOEcA9h0ZggMZ9sIYuldb002HUfvc7MBU9SDZzXYfrJtTQaBObF5Tw2 6d6JqvfpJVFDvrGN9VSBNiwIcAiqq2apsQuDQqe05B35ao8OIUhZ1kcbDUUz4Q8j+rHn Y86g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554739; x=1685146739; 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=OIYgyKuwJ81AtZBMq4tmKJvwseDK3tdRGQbYOLsgLaU=; b=RSC1Nxde7Ab9zYICq4p65Jj6KhOwC/ESLEK1609b1Y1eFRMO6xa1jVwc1DXTPLbRN0 +eY5WG1Rl6yEmQ4si+9lMu1B1h0ZSjXA921nfEZtipGtB+AuLG8VuZRg2+TkINT5p8sV PySLNG33clMpOmLEmhvxromII7YHWbUUebIjzCYLSdt7pZsjCWbwQ5VmH9pz8AZpoxQG c41GteY5aT7uMPud4F6Zsr7QCeNJEr/+9kZVzw+jrcJose0rxgg/xvKLNpKZW5fNekL7 n665lSrY7dntc1g6jyS6iqwy9ml9nMzYPj3ss/nzPzBPmg8FPsUcO6BKIli5wrj0Bsso bRhQ== X-Gm-Message-State: AAQBX9fs+UUbOaeWOS1hCyO+/U5pGjDaJXEbAH2fXvWEesNVqOwvZEJ3 YgUO6zonEqUdyR4EC4XHAgCtEnlhar4= X-Google-Smtp-Source: AKy350YguoO64iuBT7gwcB9I2x9HOcGE8lI0Yxmk1eIsZ6Z8JsEtzxCo55nMUg5XkeXSk9FSKiEGNQ== X-Received: by 2002:adf:dd8b:0:b0:2fe:605e:c77a with SMTP id x11-20020adfdd8b000000b002fe605ec77amr18006477wrl.52.1682554738696; Wed, 26 Apr 2023 17:18:58 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:18:58 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 05/11] leds: trigger: netdev: introduce validating requested mode Date: Thu, 27 Apr 2023 02:15:35 +0200 Message-Id: <20230427001541.18704-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Introduce function to validate the requested mode in preparation for hw control support. Currently everything is handled in software so every mode is validated and accepted. Requested mode are always validated before making any change, to follow this rework the attr_store function to set the mode to a temp variable and then apply the new mode only if accepted and validated. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 115f2bae9eee..81e0b0083f2f 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -91,6 +91,12 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) } } +static int validate_requested_mode(struct led_netdev_data *trigger_data, + unsigned long mode) +{ + return 0; +} + static ssize_t device_name_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -168,7 +174,7 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, size_t size, enum led_trigger_netdev_modes attr) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); - unsigned long state; + unsigned long state, new_mode = trigger_data->mode; int ret; int bit; @@ -186,12 +192,18 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, return -EINVAL; } - cancel_delayed_work_sync(&trigger_data->work); - if (state) - set_bit(bit, &trigger_data->mode); + set_bit(bit, &new_mode); else - clear_bit(bit, &trigger_data->mode); + clear_bit(bit, &new_mode); + + ret = validate_requested_mode(trigger_data, new_mode); + if (ret) + return ret; + + cancel_delayed_work_sync(&trigger_data->work); + + trigger_data->mode = new_mode; set_baseline_state(trigger_data); From patchwork Thu Apr 27 00:15:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 677632 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 2B6E1C7EE2C for ; Thu, 27 Apr 2023 00:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242937AbjD0ATL (ORCPT ); Wed, 26 Apr 2023 20:19:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242865AbjD0ATI (ORCPT ); Wed, 26 Apr 2023 20:19:08 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD55240CC; Wed, 26 Apr 2023 17:19:01 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-2f3fe12de15so4802692f8f.3; Wed, 26 Apr 2023 17:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554740; x=1685146740; 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=3erF+RQHrb/sgzGgqnLNu3kV+pj1N6QGpP0Z+KGtn1g=; b=SYVBeBp7NgMvzIAh/sYvJ6Rk62fQC2Fj2uzxY+gzSmug1Aab6+SdQ+9kr6EmkUTAhK 5V0NjtjXr/pW49+Yx5CUQ2LrSKChq+0fjECw9IX+n3huTXjlONH7LLbMJZ7JUiQIwGj/ 2m3lFxfSTtK8lo307xZFq3wRR3wi8EqMGk562z0FhI9WN7Py7M1gajeqgTN4+dJUh2Bv T8Q1sIKij6vZWmoo8luvLxxuy75qkMDye5HFgbVNdHQv2sNY0qaZvjrEt/6NhA/jEbfI pLAzHULAKQxfnIZFou/+eUnDglveHUSPsGsj0IaPREKYELbDvOsz5QGxQvTPgNvbClSk 3xSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554740; x=1685146740; 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=3erF+RQHrb/sgzGgqnLNu3kV+pj1N6QGpP0Z+KGtn1g=; b=bK5Xf4lVezLPKurzJXkJ5AoNV+ClFvYTyhBhuu0CPK4QiYA6k7TM9kBjy1vA42ocUL mucR86nDRZO7cBKBHjW/bYLWF+3RWTemNnSbw4TD0CvwGa7WldOanF/TTOdiPDZHDBJ1 4A4UxFL9xsAWvdCCook8Dah992h30q0mlA4oAEoFT3Iscpt2+lI/cPULMIe0w3u8Gk3l muRKO8aSz43FgPPzCTeTtpXzv0cCysuUSDMF1XcEoZp6rsqJtumEMNtV24qi8nSLSAL0 FLp36jwRx365g6BO5OrkMsUM0++gfO/lAq+x25Yf7b1IVwRlWD7Cxyyu28ZwVIRArihy Airg== X-Gm-Message-State: AAQBX9ftGUDXFGX0kbR0zeL1ylbICnkN17lJGzBKdXMQKIWaZ8Si7NH+ IysbB2xukqrUOEl7wBS1S9g= X-Google-Smtp-Source: AKy350YktU7STFc0Y2dEuiSm9vuhvdVHXM3Fegegp+iHh9zvYWYs2B0O5eTaEvmfBLBteG9nlJ15og== X-Received: by 2002:adf:ec46:0:b0:2ce:9fb8:b560 with SMTP id w6-20020adfec46000000b002ce9fb8b560mr16167448wrn.8.1682554739808; Wed, 26 Apr 2023 17:18:59 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:18:59 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 06/11] leds: trigger: netdev: add knob to set hw control possible Date: Thu, 27 Apr 2023 02:15:36 +0200 Message-Id: <20230427001541.18704-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 --- drivers/leds/trigger/ledtrig-netdev.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 81e0b0083f2f..28c4465a2584 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 { @@ -92,7 +93,7 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) } static int validate_requested_mode(struct led_netdev_data *trigger_data, - unsigned long mode) + unsigned long mode, bool *can_use_hw_control) { return 0; } @@ -175,6 +176,7 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); unsigned long state, new_mode = trigger_data->mode; + bool can_use_hw_control = false; int ret; int bit; @@ -197,13 +199,15 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, else clear_bit(bit, &new_mode); - ret = validate_requested_mode(trigger_data, new_mode); + ret = validate_requested_mode(trigger_data, new_mode, + &can_use_hw_control); if (ret) return ret; cancel_delayed_work_sync(&trigger_data->work); trigger_data->mode = new_mode; + trigger_data->hw_control = can_use_hw_control; set_baseline_state(trigger_data); From patchwork Thu Apr 27 00:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 678277 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 D9704C7618E for ; Thu, 27 Apr 2023 00:19:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242955AbjD0ATM (ORCPT ); Wed, 26 Apr 2023 20:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242885AbjD0ATJ (ORCPT ); Wed, 26 Apr 2023 20:19:09 -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 BC13940E1; Wed, 26 Apr 2023 17:19:02 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f09b4a1584so53770885e9.2; Wed, 26 Apr 2023 17:19:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554741; x=1685146741; 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=usUz5vlQbTcVSoDq5iitXuZZP0qB/F/micaPhHdJRQ4=; b=rhvFV/yg6ZRaZnKZM7MPdqK+NrxfCdyeyryRM0A0ga6PbXhRGUD14cj4SnxxqK1dLy WlA4KbDfzX855D+EMp5fm2efW7yc+9KjH7dl2xSQIhQjAFYYvFvhsLfzYzD4zM5fllxm nN2wF8v6y+76FnCxN6gMf+XTs+mySyY/7M6A7M6DHHjfxjHGR8q28wXOInmqSWca2fIV 8WBHIfTkIMJMwwts3Ovwo7ovCuP68dQWbkjtvYnvgdlbRGJ/Rhqicps9Ffe7mEYAGm0w Fq++HwDl810G+1UEwMcvzgOW88V3F33dXokgIIgt0zcISLmEe9symdxMj6JoatDiDW+I ywkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554741; x=1685146741; 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=usUz5vlQbTcVSoDq5iitXuZZP0qB/F/micaPhHdJRQ4=; b=eAYmMZg44czM4U1bLEB8X8FXpqHDnHoU3XfREVfC8Lbo83qSyW4Jj59uzGuhQ6/hm0 2qxLtYA3v4cnvz4vDDvihqGczTFRgciZQqqBmxQ816rorIt/azUZ53nN9CzpU1pKD6Fb K1ViYVN1+0QnggbT9w2ReefBx+C5/Nn1raSeuNkQpWy97TxRFfeZ7vHzK5EhpBwrP44t TPGZYUmLISvZsZuslGyMEgXbD39sDmI/LJKcq7E4utb9upKUYa6iJar8XMCHFztqV8q1 Wiy3830o/3jguGMcRYFEJQ4GouJpJitVE/vqjAIushtMjs4gtnR1STGXzCbLIhVAQ9zY 2uaA== X-Gm-Message-State: AAQBX9eb3Lmc93IvmrXHZmR64M6WTRoKGhGr6tF/EQfJziPE0dP+pV8q mS1KYV8cXH7eHd91DmZaO4g= X-Google-Smtp-Source: AKy350bhRhJTpCjZ0jujDv77toVWCpdHbxLyDIW42UiZwgRtJb1aZu/bMxDwMRrVvGZQ0tUzK2RKhg== X-Received: by 2002:a7b:c408:0:b0:3f0:9c6c:54a0 with SMTP id k8-20020a7bc408000000b003f09c6c54a0mr14138139wmi.2.1682554740926; Wed, 26 Apr 2023 17:19:00 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:19:00 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 07/11] leds: trigger: netdev: reject interval and device store for hw_control Date: Thu, 27 Apr 2023 02:15:37 +0200 Message-Id: <20230427001541.18704-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Reject interval and device store with hw_control enabled. They are currently not supported and MUST be empty with hw_control enabled. 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 28c4465a2584..8cd876647a27 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -124,6 +124,11 @@ static ssize_t device_name_store(struct device *dev, mutex_lock(&trigger_data->lock); + if (trigger_data->hw_control) { + size = -EINVAL; + goto out; + } + if (trigger_data->net_dev) { dev_put(trigger_data->net_dev); trigger_data->net_dev = NULL; @@ -145,6 +150,8 @@ static ssize_t device_name_store(struct device *dev, trigger_data->last_activity = 0; set_baseline_state(trigger_data); + +out: mutex_unlock(&trigger_data->lock); return size; @@ -248,6 +255,13 @@ static ssize_t interval_store(struct device *dev, unsigned long value; int ret; + mutex_lock(&trigger_data->lock); + + if (trigger_data->hw_control) { + size = -EINVAL; + goto out; + } + ret = kstrtoul(buf, 0, &value); if (ret) return ret; @@ -260,6 +274,9 @@ static ssize_t interval_store(struct device *dev, set_baseline_state(trigger_data); /* resets timer */ } +out: + mutex_unlock(&trigger_data->lock); + return size; } From patchwork Thu Apr 27 00:15:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 678276 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 4CE77C7EE23 for ; Thu, 27 Apr 2023 00:19:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242959AbjD0ATN (ORCPT ); Wed, 26 Apr 2023 20:19:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242890AbjD0ATJ (ORCPT ); Wed, 26 Apr 2023 20:19:09 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC573C01; Wed, 26 Apr 2023 17:19:03 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3023a56048bso6821559f8f.3; Wed, 26 Apr 2023 17:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554742; x=1685146742; 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=vq88sr+XdxkhlGzkSzosGS5fqAIxTv3rcg/Ss2wQpM8=; b=Gl6zqJNxxAydZzsM1MzmRQVBjvXY5Wpc110QWDhnADqo8D3jVd6nym40fagFiKjy6n 5HWf5ggNKOMPzY5KDRKHBzJLs8UaQUzJDY2qDzRZklCo/uBsjdppE9zIcBrXp+gP4U1C uhmLjcaDrPVVfgZZ4lfviphde3zL3Pja4J+mjPVczSk0OYvh4yzHQkA2yoOMkBd8DaRO 0s0O9/Y3aUxs4llrwX/JU/JRaTJGeuHaAHgifB8Cx4tgTTKW9BaFw64g4rbm00cRYfvV p1kG5rH9V0F0c3x0Y3bSaBqEw0RUHXt88W+EzRrY8TIr2o+C/rSa82T08f1PJqgbl3Ps wIMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554742; x=1685146742; 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=vq88sr+XdxkhlGzkSzosGS5fqAIxTv3rcg/Ss2wQpM8=; b=EKj3YuuM8kmbT514uH1Halgct5lmPZIllOQy8kIX4Ihdq8PtdkopenFd0XUbaIPlBu Wu/0wGmH6iUtTUb9rs0b0yp8ATFDHnf8NRCu4WzC/O0c8zVVRO7BeZcGLrsqEZgdQY5K jmIpTJVrXn1iWaY1Lax9TntN/EFCBXTqLcc4uLFbi3x50ReX1zlIRB80TESeHKcAr0qu lCK4ZIceo3pr4tuA+KU7fQm/W88CYgSnJS4WNLBEP8UuA1igalnm18M2MPG/dGKd9t1D Rnxe0rjGQ7YnfKJZFTmypeIj0TPfuIsDZdJ0MIgtUqYLB7K6Mf1B+QAOU5rU4C8ywhO8 pfIA== X-Gm-Message-State: AAQBX9eoR27Kx0LofkaOdlmtYH0h/Z4trXPIlcKqlUf34KuGulnExXng YAO9r6jeF+oQIeQc3xNe3ro= X-Google-Smtp-Source: AKy350akYVShwTgrlmnU7iXi5WHu+nOlGJsQhgLmGlzKB7rexb2/mFBOMoIsTFP7zratCNPqLfLUcw== X-Received: by 2002:adf:e9d0:0:b0:2ff:6906:7169 with SMTP id l16-20020adfe9d0000000b002ff69067169mr15018930wrn.68.1682554742144; Wed, 26 Apr 2023 17:19:02 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.19.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:19:01 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 08/11] leds: trigger: netdev: add support for LED hw control Date: Thu, 27 Apr 2023 02:15:38 +0200 Message-Id: <20230427001541.18704-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-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 the validate_requested_mode() function. It will first check if the LED driver supports hw control for the netdev trigger, then will check if the requested mode are in the trigger mode mask 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 empty. 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 --- drivers/leds/trigger/ledtrig-netdev.c | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 8cd876647a27..61bc19fd0c7a 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; @@ -95,6 +102,51 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) static int validate_requested_mode(struct led_netdev_data *trigger_data, unsigned long mode, bool *can_use_hw_control) { + unsigned int interval = atomic_read(&trigger_data->interval); + unsigned long hw_supported_mode, hw_mode = 0, sw_mode = 0; + struct led_classdev *led_cdev = trigger_data->led_cdev; + unsigned long default_interval = msecs_to_jiffies(50); + bool force_sw = false; + int i, ret; + + hw_supported_mode = led_cdev->trigger_supported_flags_mask; + + /* Check if trigger can use hw control */ + if (!led_trigger_can_hw_control(led_cdev)) + force_sw = true; + + /* Compose a list of mode that can run in hw or sw */ + for (i = 0; i < __TRIGGER_NETDEV_MAX; i++) { + /* Skip checking mode not active */ + if (!test_bit(i, &mode)) + continue; + + /* net_dev is not supported and must be empty for hw control. + * interval must be set to the default value. Any different + * value is rejected if in hw control. + */ + if (interval == default_interval && !trigger_data->net_dev && + !force_sw && test_bit(i, &hw_supported_mode)) + set_bit(i, &hw_mode); + else + set_bit(i, &sw_mode); + } + + /* We can't run modes handled by both sw and hw */ + if (sw_mode && hw_mode) + return -EINVAL; + + /* Exit early if we are using software fallback */ + if (sw_mode) + return 0; + + /* Check if the requested mode is supported */ + ret = led_cdev->hw_control_is_supported(led_cdev, hw_mode); + if (ret) + return ret; + + *can_use_hw_control = true; + return 0; } From patchwork Thu Apr 27 00:15: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: 677631 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 708B2C7EE2A for ; Thu, 27 Apr 2023 00:19:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242965AbjD0ATP (ORCPT ); Wed, 26 Apr 2023 20:19:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242889AbjD0ATJ (ORCPT ); Wed, 26 Apr 2023 20:19:09 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 072F93C25; Wed, 26 Apr 2023 17:19:04 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f315712406so4552385e9.0; Wed, 26 Apr 2023 17:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554743; x=1685146743; 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=iogxZrwR7jS1339aenDmYf0QuXCUsrtwcvqfdOp9YTo=; b=VvUZgyjloOwBQWEwDCk9HROKQf7018Fx3k0+8aWr0YvHw6rfL9iawxkTyqDRRL0MAI vj8IIo6dctAy+dPSR0E1Nvb5vtAdE7jzFiq9pjzpbjh9liT+po4HZivFduykxiieWX0h eUKt/lOK+HcrPtBkoMo5zOO/Svu0to2KyxJYIJiDCawvyr1mnwWYqgLHbJLP4Ocniogu HD/y6i0R3dSvNYA1k7wwGLFiKi9MZW+wdv26OAPXjB5u9ft1JsFMBXisOrvSNmPNqd9l 0RXm/pT4DXyuq9ttgcbu7QjOuZ7hEPFgmiHm31l+QioTvL5hkZoEEDXMMPfBn2gFzmYI nunw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554743; x=1685146743; 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=iogxZrwR7jS1339aenDmYf0QuXCUsrtwcvqfdOp9YTo=; b=PomFfTE6wX6T93MEQwDxWCe7Fc2nbIaUhTT0J3mlwuCcdBoHDV39e7LjowzewNneaZ ARCIJTL5DG0HjJYQ3HcXdeHZrM4jZAvF5z0aCqYQ2BWFCqMTQ7FFdRPeaxiM7A0Jtj/Q TG5/VZugbNgKK5KpBuJVOZT0jGJ0zTV2V2FGyN9PFIYD3nGWxd4hjfTHIAeLOXyZ1q27 qPsKnLAtwdnBkhYyXSHe1BhRwP4GtiEe5R+Q30FsY6o7SmwsWlrVwCfm3HGHud+G/+V3 x/jiweXupVH6jY5VA8/8sIvD7397/RogdYrZW0MhCkAeELPeRLBCHXlFGNqTQ0GlKBeq zNVg== X-Gm-Message-State: AC+VfDyAQbLtcusITqzGT2pVJLuDe4H0g1CZBQF0R3vIMz4p0rvY/tWE LB5bUCW8wRv4GeEpU1rGzcyD9wFnuiA= X-Google-Smtp-Source: ACHHUZ6pDKpk7ugYsov0sXthhW3RglYjLlnYtLTtwloTM0RBpFG31uF/2n6o/JAMzixOk7Pn2hxRmw== X-Received: by 2002:a1c:ed0e:0:b0:3f1:6ead:e396 with SMTP id l14-20020a1ced0e000000b003f16eade396mr44681wmh.17.1682554743205; Wed, 26 Apr 2023 17:19:03 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.19.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:19:02 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 09/11] leds: trigger: netdev: init mode if hw control already active Date: Thu, 27 Apr 2023 02:15:39 +0200 Message-Id: <20230427001541.18704-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-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, 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. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 61bc19fd0c7a..27df24e6d559 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -465,6 +465,13 @@ 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 (led_trigger_can_hw_control(led_cdev) && + !led_cdev->hw_control_get(led_cdev, &trigger_data->mode)) + trigger_data->hw_control = true; + led_set_trigger_data(led_cdev, trigger_data); rc = register_netdevice_notifier(&trigger_data->notifier); From patchwork Thu Apr 27 00:15:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 678275 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 91F53C77B7F for ; Thu, 27 Apr 2023 00:19:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243002AbjD0ATZ (ORCPT ); Wed, 26 Apr 2023 20:19:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242939AbjD0ATL (ORCPT ); Wed, 26 Apr 2023 20:19:11 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B0E44211; Wed, 26 Apr 2023 17:19:05 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f178da21b2so79931105e9.1; Wed, 26 Apr 2023 17:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554744; x=1685146744; 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=aBKN5zR+bZsVZZXVBwIaaiTdBOy/v9Tih4PGMa1audw=; b=EDqy/JeBOr/vK/v8belVS70yp7rvvpGs2gxe/1EMwcub9XE5s+UzATQRzT2lSWBVJQ Row5FvTI7FSxTPa41huW1g6wkxr+aBqpKZxSrzQ0Fpw1o82aNNVwobRf/f1ZFfBBZVaP /NTafu8FovHH8k3/FfZzmHAc/BGJXn8gwM/5oZIWW6BgE4ZUBXYNIAW2aGtwtfT5iGW8 2V+TWmoAZmyZjbHEmzQ8JZyTW/sW7F1NzJGizx7EVEblt2I/wVcTq5+dQ7iWRHNsS0mK vdrpVsRionks8I40Egv+SfUbS6bezvR//KA2gRL4hTloL4rFkzlRvU5DFZeHHS8yCX/V yGKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554744; x=1685146744; 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=aBKN5zR+bZsVZZXVBwIaaiTdBOy/v9Tih4PGMa1audw=; b=LScA0NZQnmzmSgd2m7EPJZpFkLpHMFq7gvGKKq4AzFCCRWu+q3Qdkwwb6BrRiq64EH sbe9CbZpJxvEPMJiyfNv4U3qq9wbVEiI2pbYQeMln7I29wL6VCU+tcWE7JnC0UgxssWS FKv5sKoEREtiyY7dGMJFcDJlfMUbVbF+pou71JRWD1vveLALKovr396irzx0IROXiA45 2m0IafYflmkZ07NUWNbXMxBG24KDFMnpPQUiZI6eCHI66NkRy2BGU2Tyz5ktf5+AT5hN xPu4KmdEoibKAbp3Khxujk5eNi+p2JkexcpRszaJk5nVQD+1uCQgn6UyIEwgWD7yb6Ch 4KLA== X-Gm-Message-State: AAQBX9ffJLwjGs14lelkXiyqldwNO9O2rKkND/80q0TDTXOekCwNS/mC Ag/ZJ8pqAVnYKOdv/CsIyb3/6zAk7Uw= X-Google-Smtp-Source: AKy350bPjB8OcXmb5MG8wdbdCErgUpF7tDHlz0V4uyLt2MWIqiJaqjQWRJSETnxmMb14xDegy5SnGg== X-Received: by 2002:a5d:46c8:0:b0:2f9:8e93:d376 with SMTP id g8-20020a5d46c8000000b002f98e93d376mr16374599wrs.56.1682554744381; Wed, 26 Apr 2023 17:19:04 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:19:04 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 10/11] leds: trigger: netdev: expose netdev trigger modes in linux include Date: Thu, 27 Apr 2023 02:15:40 +0200 Message-Id: <20230427001541.18704-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-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 --- 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 27df24e6d559..7d01e8becb08 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 b9152bff3a96..a55f6c528dce 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -500,6 +500,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 Thu Apr 27 00:15:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 677630 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 E5DFCC7618E for ; Thu, 27 Apr 2023 00:20:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242869AbjD0AUO (ORCPT ); Wed, 26 Apr 2023 20:20:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242985AbjD0ATT (ORCPT ); Wed, 26 Apr 2023 20:19:19 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5423B448D; Wed, 26 Apr 2023 17:19:07 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-2f58125b957so7127692f8f.3; Wed, 26 Apr 2023 17:19:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682554746; x=1685146746; 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=fTXQkDrZZKZ9NP+ZntA7z4ey4eFFetW9y6L1uqW2c2o=; b=BdLd3Hpesr5MPJ+MQ55+Cy9vElb4yiFY1Ai/b1ACb5byzGZBsPTkhjw3IEJThFTTKk zL+Wxak75rupCNVj6ZHimUQoFPKCWzNdhzNBCS4okH1nyYndjp6GudCJLR0FTsyMtmKk yveLdKxoxSsMhj9FdEgb6h+sqKyobNagGAzENFIUib8u3S95cQM2Zz3KBAOITcogkhoZ /y77C8BCxB2m1sFMsrzQqYBordGzMTtgdCrbur3sBqVH4T7SISlN0XOA84f3bKuQ3b0I qXHSg26PEq67V8NML+Jkorv4QiuXb1CnYd3tim9/zEijLy+r67dAT9uxK6UZE5Q9CH0L h+Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682554746; x=1685146746; 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=fTXQkDrZZKZ9NP+ZntA7z4ey4eFFetW9y6L1uqW2c2o=; b=Kqz+4u7gfHQlCHcDGYjtWV+x0cpJg0KvJs4cOXTOwNd5+H5XvBU64PFPPIe5z3bxB8 M4uL+FodyCdJU8FruLnXZHA8n+KTuobS8knQjGZa5Ab31fwmgOTzNeVixMzRcMY+H+cE 0oXgFQCxGWn4l3iDFY4oDY7PYk1Hu85wmydOCSbhUDnSGsEm1kMr6vQpFauB2A2aEbfG 8E3cTbwQfYROu21xtL0zNo5fGzSxYvCpJFgAXLvx5JYja30+fQNZTXeAHDi0o0l0tI0C FDWl3et1Gn5IYP1y/mblKTa8mQYjUtgusfEdqZRqWawgD1sLXmeV415JTt8VA3f5yCDl B3HQ== X-Gm-Message-State: AAQBX9dUsMg8p/dIK+lsMzNEiqZQgey37ZphVq+prfssRZjD4FePdLWC kVte6Z2G2qp3t5PvLr77hI8= X-Google-Smtp-Source: AKy350Ysp+3nhBb0hxVO4QFQ94CQgUWZUGxe+lx0npA0tp1+RiBjF2kiSuLfZOpJ0MdhPauopmovtg== X-Received: by 2002:a5d:6585:0:b0:2f5:953a:4f59 with SMTP id q5-20020a5d6585000000b002f5953a4f59mr15096148wru.5.1682554745432; Wed, 26 Apr 2023 17:19:05 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id r3-20020adfda43000000b003047ae72b14sm8624916wrl.82.2023.04.26.17.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 17:19:05 -0700 (PDT) From: Christian Marangi To: Jonathan Corbet , Pavel Machek , Lee Jones , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 11/11] net: dsa: qca8k: implement hw_control ops Date: Thu, 27 Apr 2023 02:15:41 +0200 Message-Id: <20230427001541.18704-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230427001541.18704-1-ansuelsmth@gmail.com> References: <20230427001541.18704-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 --- drivers/net/dsa/qca/qca8k-leds.c | 156 +++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/drivers/net/dsa/qca/qca8k-leds.c b/drivers/net/dsa/qca/qca8k-leds.c index 1ecb29953600..54d3ff46e00a 100644 --- a/drivers/net/dsa/qca/qca8k-leds.c +++ b/drivers/net/dsa/qca/qca8k-leds.c @@ -30,6 +30,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) @@ -135,6 +172,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) { @@ -193,6 +343,12 @@ qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int p port_led->cdev.brightness_set_blocking = qca8k_cled_brightness_set_blocking; port_led->cdev.brightness_get = qca8k_cled_brightness_get; 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"; + port_led->cdev.trigger_supported_flags_mask = BIT(TRIGGER_NETDEV_TX) | + BIT(TRIGGER_NETDEV_RX); init_data.default_label = ":port"; init_data.devicename = "qca8k"; init_data.fwnode = led;