From patchwork Mon May 29 16:32: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: 686806 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 0877AC7EE2E for ; Mon, 29 May 2023 16:34:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229564AbjE2Qer (ORCPT ); Mon, 29 May 2023 12:34:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjE2Qeq (ORCPT ); Mon, 29 May 2023 12:34:46 -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 E04D3AD; Mon, 29 May 2023 09:34:44 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30a1fdde3d6so3391953f8f.0; Mon, 29 May 2023 09:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378083; x=1687970083; 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=XhNwz9KNlnd7qmSmx8SMut95dFfRtkNAM+nFVwtGeVc=; b=aF5gOIbQR8eYb5W0wqKsv1ikCS4wv3mF3U88FiFDe9rJIMVDznTMSY8q75zN+/eigj Uuzwq4x7FdgaeaPIsFHyDT17bu5C3Gwq6pfof26pEfxxGzMTbmzw73rQCCPx4xhpX3S2 nMLd+VlbLPrjEz2pbXobRwZQSjm0nCph0zTX85ydgYbppRwTkhd27dmVZQd0CzHNvCVP 4UuS7g839K7nYgBv8kgmy0Ycg9cTyYYmtAmtH5qcTuyWxbW6JZcgWl5w2T42KW1oxmgT BchhictIKZl244mzBZVvJ2dWChjmzMWtlDSTyzCWnDaTUw7SikZ+ukh/fgWkPW8oOwHT CIlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378083; x=1687970083; 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=XhNwz9KNlnd7qmSmx8SMut95dFfRtkNAM+nFVwtGeVc=; b=l/e3GoCfTYHIW2n/UNDQeV139xOPv644UAVE2pTnfXed7akn03G2M8YwMOHCYlR7DE 8zzHjaojl7tlb/fRotCRsShfabBzrVKxhGxdgbQlXHAw9j3HWeje5IL7jeIKblC4zuZx cS5u+0D+VTTDdXcnfK5eGl8LO7q648LbdKwEs2fnikO7RCXet5L/JZKcWh9mmvhwhDWw iPy0iSNhgcLqlDHAtDSu2i0xS+rVRNFZFNoHjiQ+XbcFossGHu0HXp0T0NMUATvS9zZ4 Z6H7msuLj5nU8OI+0zUUwqOsBsVF6P1RCt+fZThWUEbqZ417QFSPJlUq9wvbMzf3Qezu 8YOA== X-Gm-Message-State: AC+VfDwOd0XtKX5iWAdV7py5C+dxek2SUoyK58E8y+b5IUXGeBsrB/ni gPVD3y3shw1IUU/3TQTIXs9q5Ty9+go= X-Google-Smtp-Source: ACHHUZ5QghcrT/T+J6Tc//RJ0COllzktPSYbY/p2zzoYVTcwQ/t7ZnG8UmuuFAyu8qjKU8IiQZIz3Q== X-Received: by 2002:adf:df12:0:b0:2fe:851c:672f with SMTP id y18-20020adfdf12000000b002fe851c672fmr7961772wrl.8.1685378083010; Mon, 29 May 2023 09:34:43 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:42 -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 v4 01/13] leds: add APIs for LEDs hw control Date: Mon, 29 May 2023 18:32:31 +0200 Message-Id: <20230529163243.9555-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Reviewed-by: Andrew Lunn --- 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 Mon May 29 16:32: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: 687577 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 4569EC7EE2F for ; Mon, 29 May 2023 16:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbjE2Qes (ORCPT ); Mon, 29 May 2023 12:34:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbjE2Qer (ORCPT ); Mon, 29 May 2023 12:34:47 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3FA9B0; Mon, 29 May 2023 09:34:45 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-30ae141785bso2470133f8f.3; Mon, 29 May 2023 09:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378084; x=1687970084; 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=HFWU7xPpyF1Sqf3McJK/3jtP3yLRKr9Epc1ZFFCzerp8QaSCiJ1VPp7nOlqZWFnfZ8 /Babpv/epN5qcfjtfS+Usb8n61gT0plcNkYcWGUWeJ6xc2V3lctdXonyf/zkXjXE2ga5 qi2JghkkKM/vbCyoxP5dTe0E9+X/NuzAg1LmBK+6kpYdutor58I4+K6iXjkPbK6JbRJZ Yr9l+P5sIQxDQ4j0w7+SucXVFUwfUqfQBJeHe2iHDNS6G1Ta8JDB9PRF02QLHBmTtxO+ hgSrPeMSgRZ9Gsjjjtl4K86lhFzOLrJ7irGBV7i/jSME7OIu92NpmjLUg+lDMn+ag/I2 JRkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378084; x=1687970084; 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=ZfyuYhVJfqNQmF48EQrFAw2T2aYdLLVARtK/slp9YZGULN2r99h3mB6icw6mVXwaaX FXKgUXyRLFVm9hyvMMKvtFyC7UqAn7dcjiea0HwP1sz1DPMZrwooNw35j6HuEqZlCtMQ SJN4UbGHhRoYex21iF9iEQjS+1jJWehschcAeHM3qtaAKtSg/NYv1I978v9fhvjhOtFy vNnDoxnkgRfkADJK7n2huGpII2qkLFWbfmGTe05+V5CG96b8w+0fNcmou6KWh8MHWb5S yfewBYpFVt1ef2ZMrOrS2e6dI7WeU/xkpfAp6+GZ1nYcyeQ/QgLySTC+dzFd2Ar728nR yEhQ== X-Gm-Message-State: AC+VfDx1ZIkw+Ca58zrbsaQhvAdVslGf0rwPGFZpe3+oRK72ZxnGUjVX NaDI/CLM+OfG24Idv+QHsU4= X-Google-Smtp-Source: ACHHUZ4vlx4sCUPTm2NGLOnreG+bh6hw9QNazuM8T8EqONcv36VhSp+Ff8VFNpcFnNpzRzdN3iVu6A== X-Received: by 2002:adf:ff8d:0:b0:30a:e954:fde2 with SMTP id j13-20020adfff8d000000b0030ae954fde2mr4160062wrr.53.1685378084233; Mon, 29 May 2023 09:34:44 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:43 -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 v4 02/13] leds: add API to get attached device for LED hw control Date: Mon, 29 May 2023 18:32:32 +0200 Message-Id: <20230529163243.9555-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Mon May 29 16:32: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: 687576 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 26A46C7EE37 for ; Mon, 29 May 2023 16:34:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbjE2Qet (ORCPT ); Mon, 29 May 2023 12:34:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjE2Qes (ORCPT ); Mon, 29 May 2023 12:34:48 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B43A3; Mon, 29 May 2023 09:34:47 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30aea656e36so779533f8f.1; Mon, 29 May 2023 09:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378085; x=1687970085; 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=bow2IlphqQcOV86ezGAfOnUZcJRsC4hY+XSIuwAMdVw=; b=TCNNwKXObS/dWdO1Q1TJ9Uwu5/jmmaVfR96PuYXGr/hq86PhgUbTDRf8mJBJMt1psh ISbW0tAZT6OkzpSWUWlWN2g+asUpzy+xk8vJC56K5F7bI9rooUacXcpIXoKsojKGdQoT 6jp+6PJ4rENUtJ1lRvbBdL7iDHVSYPkQjYAupUXWMUp2NzdfCPNb7p1DoMK9MZFefKQP 1KegwsFQUoTnEr7e/BhQP2fcFRF7c+mRn4YmpnORXgNsBSeDt/6w6eGQJu8l5PJiaWwT CKtpW4sUYC3+6IuVFMV2upSrO8or+uuGEbs+a5YoPE6g8B1mUoslQ345hsl21d1PQYh8 g79w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378085; x=1687970085; 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=bow2IlphqQcOV86ezGAfOnUZcJRsC4hY+XSIuwAMdVw=; b=H8aCZhY0siSb7o/AV/bXgvzNMuB9uFM0rcqI5QY2Q939iNncRtnKtj0nIrMt36xBgH 8XdH6AYhhVJaCTBsq6iYLKhA044blMg8BFFd9t8HzVXlIY1Wf/5WqNIgPxNQJK1w1vQX H2zh9Irm82poyi0dvEDPvLrIGiJGCPkkhHWDcJrF8TRvcsJhJmPj3V3xDA1RBQUE3r// qx0adzF4eBu1pOuY9jy7PHTjyQKmr7M7XebLUOz7SNrObwRgQHp+CGkBpKamwFIzZpTD SMetl8aRQIbH8oVhKcyVvzNo82XbdH6dwcBFFX47MnX7CW3h5peOsgUP6lGIBXBFgwHQ QVdA== X-Gm-Message-State: AC+VfDwVp7eN5M00Akjl8gHCX5Xj9KeywDdyFa/KW5Kh2VcUayw+1Q/D E7Bgar06UpE1SLx+IXO9xT8= X-Google-Smtp-Source: ACHHUZ56tanRPzl8lORtX38biVRycR+UuWloQM8mJIJUTmppZGM4bDoqMm4v63Bli1a5jC6JhqFT9Q== X-Received: by 2002:a05:6000:1b0a:b0:309:4ba8:86a0 with SMTP id f10-20020a0560001b0a00b003094ba886a0mr8417977wrz.17.1685378085402; Mon, 29 May 2023 09:34:45 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:44 -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 v4 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Date: Mon, 29 May 2023 18:32:33 +0200 Message-Id: <20230529163243.9555-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index cd155ead8703..5db620ed27aa 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -169,6 +169,87 @@ 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 failing to + apply flags. + + - 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) + + Returns a pointer to a struct 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. +Examples 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 Mon May 29 16:32: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: 686805 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 3E8D7C77B7A for ; Mon, 29 May 2023 16:34:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjE2Qeu (ORCPT ); Mon, 29 May 2023 12:34:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjE2Qet (ORCPT ); Mon, 29 May 2023 12:34:49 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6A9AD; Mon, 29 May 2023 09:34:48 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-30addbb1b14so1753872f8f.2; Mon, 29 May 2023 09:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378086; x=1687970086; 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=AGsYyhVI5kNmN5PnHbyAXfKvH5U3q97ntL9KrHbuSjhfLQY8cpbNEdjVyTw7hqsTpn lvxaldiA3oamz7vZBmwo+MWN9rLMHR7wILiIC/Hfh2rgw3YIdhAKTkq9ZxS5ml21id8P eDPsvJRMGePqXg2dFvbK4VWRIng/L892IN0Pa9oWyenjnmagENGaz1zYzgcKGDZGNR8B zRWfJSgT74T26+Hwz2v4/hleOyEW3lKQmVY/RwGlcF8PFwp5Ih+IPP8+329xPfO3zrGX KnZxGQF7A6KNLQk1a8JJESnbJsRMvMRBS+b3GFHqwEkjwdYQJyNsb9RABVdqRr0FpWSv RZJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378086; x=1687970086; 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=GK4sYtpp0esVw83PNJZySPV2G5+TfeJFdoZW8YiWsJfou6hXN0BjpHOn40IutNCw79 dKIr3lQYPRWfpokw5qGkaVLjyzep4g5wi9EpFxBWuRqqRBoGCUc8e8mep4jS74D9f1fk oro78TdnAkfq/lXa9pAner1CHGDuHCdeeJTM95mZM9XQ8BPIc2MVlq0wVYRgG6vFJjw8 h6S8eturMUCLP1DHK2Bym7zXfzmr5PIEmyCCWE2pXehQ5XitFxGo47JYSSN4Zysl6hqV naEKUdrp8h75Y0mThXN6jOeMq7bELPDEqYhfARBxp94vK01H1dKDNZqnunr1lL5fafJY fdhA== X-Gm-Message-State: AC+VfDxhLUOrJDckY90osPm93yqjl3qjW/ma3vMsn5v52aEVKtGAbH4V 96wJkHO7vOfCIZ2dMuoelsw= X-Google-Smtp-Source: ACHHUZ7EQ27ufb9yRv07KB/RaaMNYy3yoCBZn/kDDSMKdcDvOKtbZzfr6rT4CKjth5yKt5FwoYaVZg== X-Received: by 2002:adf:e792:0:b0:306:340c:4737 with SMTP id n18-20020adfe792000000b00306340c4737mr8892359wrm.67.1685378086515; Mon, 29 May 2023 09:34:46 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:46 -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 v4 04/13] leds: trigger: netdev: refactor code setting device name Date: Mon, 29 May 2023 18:32:34 +0200 Message-Id: <20230529163243.9555-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Mon May 29 16:32: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: 686804 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 18650C77B7E for ; Mon, 29 May 2023 16:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbjE2Qe7 (ORCPT ); Mon, 29 May 2023 12:34:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229578AbjE2Qeu (ORCPT ); Mon, 29 May 2023 12:34:50 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B60DA3; Mon, 29 May 2023 09:34:49 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-30ae967ef74so839283f8f.0; Mon, 29 May 2023 09:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378088; x=1687970088; 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=Gfvrz5G3XlnZ2Vf1vClzhgeEjYoUMrP7las42y0bA9Q=; b=Etqzt3m1D0bdS7EJCaFaYCnfOToBbs2idvHlXP9DUF0SI74sS/sQvkccvcvNwVNp9V QhkpbtiTro0KWvvvTgDn/avcEwI7wi6o4O2U31SsGtyeNsXzj7Aey3HEIdZiQPoh2wt0 PZjIJezCeUcKrF++EI9kwmjIKeCdbYyhJsktPfkz91TrS/npaOzImsDK/icmwXhnkRbx vz4oRECuV71wONKIhbwI1X86Xxl/I7nH043o7//5Z87LWaXbUYIkEplaa6WTSGsjr+Bk o+4VVUvyOPYqsVw6HpAQEWkXIFc4vrRB5he1VLoaQh8y4PAKjDnYMGH6Bj1sYcZTQKVM wfUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378088; x=1687970088; 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=Gfvrz5G3XlnZ2Vf1vClzhgeEjYoUMrP7las42y0bA9Q=; b=TpInGGrfD6QUXuspxtC0yCS5XF5rb5Fwr4ZDZGeu5/vbhbE3KskFHP3EscJpVx1MQs RbmIZgb2Nex3XL2cQa3syPxGy3bpeTY+fJRJnVruBmKfY5k6wGnwddZ7QtO3tkQYHrOE XEjZtZa6pur9FLhBXsslbCrme5Qpjm8k5CRtulLXqyzqUaBGXsvPMzmo/lM32oGnmABS /E8PyH/U8+rtsvUxXR5L7XUZzEua/heIgNIRIofV5Homo+YQIh1+9p1c7LS0SN+A5k6l vPbKrBnQe1KB2pErDj20iL1XXjJR2Su9hcaaEhZf5MwCYH0RtBfbpVLj3pnkAzGxqSTO +G8g== X-Gm-Message-State: AC+VfDw6GdbgTtm0abQU/CELwgaJbnVHTFdPAEd3prx9doNRAfkFo01T TlfSx3C4WoZCAJEFVBANeoM= X-Google-Smtp-Source: ACHHUZ7+larGJmqw2AZBA7u9cay97RHZujQ31A+rcyfXytbbFvHbHQe/P/4ZHvEqu4ZrI8xBA4ZUPg== X-Received: by 2002:adf:fc50:0:b0:30a:bdfd:5c3c with SMTP id e16-20020adffc50000000b0030abdfd5c3cmr10863252wrs.17.1685378087601; Mon, 29 May 2023 09:34:47 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:47 -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 v4 05/13] leds: trigger: netdev: introduce check for possible hw control Date: Mon, 29 May 2023 18:32:35 +0200 Message-Id: <20230529163243.9555-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Mon May 29 16:32: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: 686803 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 9BC4FC77B7E for ; Mon, 29 May 2023 16:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbjE2QfC (ORCPT ); Mon, 29 May 2023 12:35:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjE2Qev (ORCPT ); Mon, 29 May 2023 12:34:51 -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 3B055B2; Mon, 29 May 2023 09:34:50 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3f6d3f83d0cso36417315e9.2; Mon, 29 May 2023 09:34:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378089; x=1687970089; 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=IlQrvGRD4ZHltBpv2SQtNiv0lfrM6U3jabiv2fdlEjA=; b=DtHAc0glKUPrO98buFtsgCTz1Ie8aLDtveoXlqHpy4/v/pzDmV6NkXceOfvN2VkKJO Mzlc6eKDDreLC9/+0Klduzktr30qbdTdYjpLA6b/rpcTluYntiEhyO0pX8otblRuioJK e39c9hD4rORHrGO4IhsWDGn4p1+bGbOzmtiBfxnuywI9eUiZkKO80S5gleEdSnt+qmED Xd/o8iF/f8TgMtkhdnG/s5eFksnFMGOPHBlG9y3SEdgP9Kfug33ktmKDKIGN+0zhowYZ E1g2czs++O2e+XgfIG6G1bFZ+QZpOvRgZ/9oEC0pdwJxPftpAIIaR6KRzJujsufgu0bX DyIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378089; x=1687970089; 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=IlQrvGRD4ZHltBpv2SQtNiv0lfrM6U3jabiv2fdlEjA=; b=MWzqKmbOiWFBaA14h1wNDITl/ZiMp+082HMNCEU7rCnHbxjKvo8uvDdAU8ZkcOuFhF BBmTieuoLAuPibM8sWCqeO5jrpRxoNOstSrIS8ijYR+PwcZPXG2IU3XLtn2t+J9LARzj +ian8QOnHkannScAtSoPMOSdp9Dl6/Kxs27XEOY0kflqJUR0maz3k7Dm3OX6FVDnEKdM QTrz7FS+pAhhP0ad+mUXvRJcRu4G0vw2/7fUFMzKNSLzmC+T4Jp5uZxly9LGDVVfYvzF ZzGtCdnYY4tzu8FX5BZypp4eo5UJc3iCqPy8ZPBsvMfdneyi0VYc2mKlebj3wHl9DBZ4 IVvw== X-Gm-Message-State: AC+VfDwRawo7OFOA+mjjrs9SPHYaNvsSCoao2eiBR/jIrszuMRfWHqTT NvDNl5OinFpCoKCBWqGHeUc= X-Google-Smtp-Source: ACHHUZ641zKVt+dvxchLwmAXeTl3o99OfbAJcCRE4+hN+GQzUQzNx2B0Z3gWlYjxdlQlll5hmeYOkA== X-Received: by 2002:a05:600c:d5:b0:3f5:ce2:9c82 with SMTP id u21-20020a05600c00d500b003f50ce29c82mr10531066wmm.32.1685378088594; Mon, 29 May 2023 09:34:48 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:48 -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 v4 06/13] leds: trigger: netdev: add basic check for hw control support Date: Mon, 29 May 2023 18:32:36 +0200 Message-Id: <20230529163243.9555-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Mon May 29 16:32: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: 687574 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 BEC7CC7EE2E for ; Mon, 29 May 2023 16:35:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbjE2QfB (ORCPT ); Mon, 29 May 2023 12:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjE2Qew (ORCPT ); Mon, 29 May 2023 12:34:52 -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 553CFBE; Mon, 29 May 2023 09:34:51 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-307d20548adso2072948f8f.0; Mon, 29 May 2023 09:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378090; x=1687970090; 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=qJiU1ASrfZmceZZC4eiSm3WS0QnApUvAsP7UJRGu7Co=; b=UjQM7+YVLYGHnFZmtl/O4wixpGGuV4XHFoBoRyt/AzXo7TB3AlLZllQ3lAmg5vvdjM lP9O4FSGU01rRKZoJKXVm35XZ3a2J0SLckVlrn0OkM2Lkgbt/n5uo5irMbeTzxs9N0S9 Naxwttn4fMCd/Ae6hajUXEoTW0T+D78DTz6Vv9b6RpzqahwaR7qfi/uShNcqeoqLY5pv P2R3LtbpwGk2cPjAhf1hU8aLHJn9X/aNpmurRFPVzWP8ENs4N7UsFjUa/qoH2wC+uhST 9LjWLupMmeXsqO5THE9xJKhxvO7H1TzVZ/sM3qCHWmiucMJAh8BR0i4e8YEmgFvKNWrQ ZNUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378090; x=1687970090; 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=qJiU1ASrfZmceZZC4eiSm3WS0QnApUvAsP7UJRGu7Co=; b=TkMDyD1MYDLAxcUFx/suj9sAWsmfBe41bptt+B58/JDHyyMWyO3THAWTb+cvu6NBlQ 9hdvyxw4bAhXDuXJdTMoZhhFWTOvhQQWtj8yxrghaCZIYMRo9VgpzLK5mQfrdXUJ7hZv GQW0HHm9SUf9I7AAvngF0IEb744QgQ3ZiG0RGChoabylFfFsvMfVibAdzNxsPdz+GQsN i9UvG6X6GPjwNWXTojTurnd/RzgcyqIUJfnOQWbJVLCWVm0Ik1rkUO4f7TlcjlaWKgTo 2Ct4X65rerm9i++FZvMSpl5bnUMHxOWHuOjgRxtqmxwXUssCwYpFg+ksGYrEdIWVKYqR oMdQ== X-Gm-Message-State: AC+VfDzMLRMRxiuIok7TQInFXog34Ea+hKloQ/ioRc5x27ZKGybIfq63 Mzm9MwS9enHaOSmAuNSOH6E= X-Google-Smtp-Source: ACHHUZ6LmavkNiuiaw1OkB4/vaYueucZlXesPwBKXihMiuOc7iNu5z7Z2kZWXDxxwCB+REryY4N+AQ== X-Received: by 2002:adf:df12:0:b0:306:2f8e:d259 with SMTP id y18-20020adfdf12000000b003062f8ed259mr7569897wrl.57.1685378089652; Mon, 29 May 2023 09:34:49 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:49 -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 v4 07/13] leds: trigger: netdev: reject interval store for hw_control Date: Mon, 29 May 2023 18:32:37 +0200 Message-Id: <20230529163243.9555-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Reviewed-by: Andrew Lunn --- 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 Mon May 29 16:32: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: 687575 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 7BB63C7EE2F for ; Mon, 29 May 2023 16:35:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229773AbjE2Qe6 (ORCPT ); Mon, 29 May 2023 12:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbjE2Qex (ORCPT ); Mon, 29 May 2023 12:34:53 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A762C4; Mon, 29 May 2023 09:34:51 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-30ae967ef74so839322f8f.0; Mon, 29 May 2023 09:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378091; x=1687970091; 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=k9zDcLuDmRuulvW9kwOBJYpZilY8B3eQJR6LQKF7+iY=; b=kinBxrFz77HNF/XtwhSWtBAd7mEOLCK2AR+m8MZp8Xz1PtERhfYwYGVqVUy0zWFs5B UkEj84uzwX29FDEmRbDKRxaQulRPxBealoaP4La97X4BbD8rW3XX90z6A2Koauo9dTB0 IvaO2BFZKQtNdjH6/sHzBlVvtEVhNe2opzvRhAQZ+wpAKUC9d6rTCmZsvvvaKIToNtau QQzNTGZLYplb9MuJnsueJJF6xQahBxj28X/mVCwtCB05FzGJ1EmOLE84pfFXji6a4bth Ptui/zARqnladVkb6rFSatzmeNUGplecshb5Jr8WUr2l5UHj0ejo5EQK1ZA5+2yh46Ou lW2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378091; x=1687970091; 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=k9zDcLuDmRuulvW9kwOBJYpZilY8B3eQJR6LQKF7+iY=; b=crkMC9DKft+Do4RePPEMY2nX+NbyIlQRvMtcg0o+FPYsHvM4DNy3NNZsXPunZ7hnZZ 3hVYj0Zkf1vLk0zGHjViUZ5ushZ6b74ZbKonkSRnzooBfDgeWgpOcLRzVlCBgvZeYyH7 StJn8ggzinY1LcYKxc47gyvQnnEbWgatd0JXufLAroYAr4bwBYPLAgQgNX7OTuXaK3R0 syObZVKJglT6Q1NdGDWKAO6bdG2L/Fsf7C3MybbH8yXb6ZRphW0osuPx9i9I3uZ4h5Cb 05Ptsy2TNP3wCmtBGjKF+vxo6ztWKA1BA1Ya+Zdv0x/ChvX/Ui6asVSiYbTtXvgOU2Hp +8jw== X-Gm-Message-State: AC+VfDzpVgjf0KJpKWb8o72P5K/YPryvedWcmXBvrYOKjzSSoyttNXdw rciQxnSHuhTBJ6Hzjqx4QXI= X-Google-Smtp-Source: ACHHUZ7GqW3WwEMsm/Vm1s+I7dlZGDtsqkt/s+aTLIWNJ214HF6QA7zx9Syi/U/kWZgar2002rOwEA== X-Received: by 2002:a5d:43c3:0:b0:309:1c89:c61b with SMTP id v3-20020a5d43c3000000b003091c89c61bmr11510309wrr.29.1685378090774; Mon, 29 May 2023 09:34:50 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:50 -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 v4 08/13] leds: trigger: netdev: add support for LED hw control Date: Mon, 29 May 2023 18:32:38 +0200 Message-Id: <20230529163243.9555-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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. The default interval value is moved to a define to make sure they are always synced. Signed-off-by: Christian Marangi Reviewed-by: Andrew Lunn --- drivers/leds/trigger/ledtrig-netdev.c | 43 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index cb2ec33abc4e..8f592a77cbef 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -24,6 +24,8 @@ #include #include "../leds.h" +#define NETDEV_LED_DEFAULT_INTERVAL 50 + /* * Configurable sysfs attributes: * @@ -68,6 +70,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 +112,42 @@ static bool supports_hw_control(struct led_classdev *led_cdev) static bool can_hw_control(struct led_netdev_data *trigger_data) { + unsigned long default_interval = msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL); + unsigned int interval = atomic_read(&trigger_data->interval); struct led_classdev *led_cdev = trigger_data->led_cdev; + 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, @@ -413,7 +452,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) trigger_data->device_name[0] = 0; trigger_data->mode = 0; - atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); + atomic_set(&trigger_data->interval, msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL)); trigger_data->last_activity = 0; led_set_trigger_data(led_cdev, trigger_data); From patchwork Mon May 29 16:32: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: 687573 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 EBBE0C77B7A for ; Mon, 29 May 2023 16:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbjE2QfD (ORCPT ); Mon, 29 May 2023 12:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjE2Qez (ORCPT ); Mon, 29 May 2023 12:34:55 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45C3E4; Mon, 29 May 2023 09:34:53 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f6a6b9c079so22898335e9.1; Mon, 29 May 2023 09:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378092; x=1687970092; 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=oXdnCyspEAq8AAhyVqhCs6kBBPc1hkVJYJIy6Md5CI4=; b=lkOnQVzBPdRH8/Nv2j5AFDxm8M4Adtic9A52/87JrFWw4lb3jSVuFUfQwO0DUjEuM0 vgeuHA2KtHfXxjKdbz+WgWPFSKBsR28f1ydXaUm22KrCT+xI7u1rTwBmic+fuJj9WuUG kMWXW5U1R3dJtGVgaaJnSJMuePK3lreYxTd7/CWWAcSf2l6Bw/4e7y0vg5aSWBYUHe2B AoTIt6EmFblw3xkxb3o6BRoRGD5dHuspKMLxmdf5DApF/8y8bFko1RNjNquOSuK2jXKM agNh9ScnILi4enQpYNQviO40o2ZfGKO3TfdNPKeNFkEgpO0x4Ja94oLD/xuvkEXFY6um jHRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378092; x=1687970092; 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=oXdnCyspEAq8AAhyVqhCs6kBBPc1hkVJYJIy6Md5CI4=; b=lEbNPYU5etMY4M1HMKSpDosCS8NXF0PF2QYCQbexLUt8atthoe+Jmgpfljt5w3zO2N +R/5aZIiwnOrDsEYOdpWePesf7fpTy+brcmceMBsCGF4N6heV0zWQ4QN4tkAaxuBjmSy n2kN1TraJpWfQq5xyUb8Y/nM4x8U6vm3gjgAlqW/f1SoGTyATbTc+qe7XxYwV/GQpKp5 jFDav3SA/stm33gtrbv8IHY1mMk+EBSLPtXL+6GfDCf9BAkVeSPC5SQ684HRthD+YCKC kTX54NqQLLyyPM+xUfY0vqgPIg39W1gVgz/Muo2h+DfaBX4De/JIH6tyc4Vv561A+pv4 VgcQ== X-Gm-Message-State: AC+VfDzdIxR5cq+Y/U534cgA6iIXVA2Kk6gjHboMWlEmwwJ0ekR4fcgS xvF2DdsV9u4z6Niv0paL1GQ= X-Google-Smtp-Source: ACHHUZ46PXEr+fp6kcMm5T7lr5uu8Qi5+YIdKuudLNN1ssmWGLZUc7rEucyhIi2gPF0cMsxa0o4lCg== X-Received: by 2002:a05:600c:2316:b0:3f6:15c:96fc with SMTP id 22-20020a05600c231600b003f6015c96fcmr10069687wmo.17.1685378091818; Mon, 29 May 2023 09:34:51 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:51 -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 v4 09/13] leds: trigger: netdev: validate configured netdev Date: Mon, 29 May 2023 18:32:39 +0200 Message-Id: <20230529163243.9555-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 8f592a77cbef..0f3c2ace408d 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -110,6 +110,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 long default_interval = msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL); @@ -131,9 +149,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 Mon May 29 16:32: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: 686802 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 3F98BC7EE2C for ; Mon, 29 May 2023 16:35:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbjE2QfE (ORCPT ); Mon, 29 May 2023 12:35:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjE2Qe4 (ORCPT ); Mon, 29 May 2023 12:34:56 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 931DCF4; Mon, 29 May 2023 09:34:54 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3078a3f3b5fso3337238f8f.0; Mon, 29 May 2023 09:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378093; x=1687970093; 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=3JDhahJlRGp7rscxnWQW6zc0g/o81yCtHKEr1htw2Rg=; b=KzdaH2TttVBr8inSEozDQhuGSO031dUpGVf67TCRs3zHpF/QMJwT3VB23kwyK6YbUg 9fLCU1rVE/5jjGXoSKzSl21kSL/sZXLSCtqCKzt/sByrB7TXjC2YGOi2ba5wPXtLozgh 45b/hHPOGdcoSqqsIcqIi6jyqJuVU7lHePaQ/Uzj+2ZZKZMrMwjShPvpLl1UiRp+74c8 w5oPCzmfJ6CnloJHxNLUc+J2BMy1brwH3b+uypeb5JO14Po1+rd14Mr9t31XNG9HpWiU BUkaf1Y8r6jL3AHNgfjRy809kgFumnyB1FLBDrQ11ARb9PeSVk6ncb2+ax/6EuPZ6rk2 0Waw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378093; x=1687970093; 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=3JDhahJlRGp7rscxnWQW6zc0g/o81yCtHKEr1htw2Rg=; b=ZgQavdh3HoV+qFl1lmoRfjojm1YV1o/yeNAZ8nd2FYzQzVnNTrIYcWiSHt8G5HTwar rtCQWcnV47PckU4o+a5QkiEoU42oMPKfC87AiZPqyvquRiYJ+PqpmzdEcPW0uP0zHC2m D/q9ssBLr8PMpLFRXLTY/p/WSDkkEgLdBtGTI6ahWvjkyVj6KL7zIzK8rtAbyGZUKP/0 6ieR6XpQPRi+wZ7nVrOU/zNSYahM+uZiYvvN2a0mikluYsxqANoMt5JZtaWJbgI+ZyNM AUHhsPhKJKSEw3mKBmSvtEnt5IPOkEiyrbUnSzZ99zuAQ2x6E7WMtg1evYbFJBSc758I 5PQQ== X-Gm-Message-State: AC+VfDwJc9V+lq41UrXgRnMWePqE7h4ltcUhW2vS5/vCThZNu3eG1tUm a7GHTFN0ZQTMLugXmmwvx8Y= X-Google-Smtp-Source: ACHHUZ6fGxEY1P7QMULGLZn52wj9CCAtmBza94acxyhmpj8OJlgtvrRWcXaMb4gV98J+X6jY/Ifnsw== X-Received: by 2002:a5d:54c4:0:b0:307:9194:9a94 with SMTP id x4-20020a5d54c4000000b0030791949a94mr8543087wrv.17.1685378092847; Mon, 29 May 2023 09:34:52 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:52 -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 v4 10/13] leds: trigger: netdev: init mode if hw control already active Date: Mon, 29 May 2023 18:32:40 +0200 Message-Id: <20230529163243.9555-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 0f3c2ace408d..e8bb9d0f85c0 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -454,6 +454,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); @@ -475,6 +477,21 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) atomic_set(&trigger_data->interval, msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL)); 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 Mon May 29 16:32: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: 687571 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 3F162C77B7E for ; Mon, 29 May 2023 16:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbjE2Qgw (ORCPT ); Mon, 29 May 2023 12:36:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjE2Qe5 (ORCPT ); Mon, 29 May 2023 12:34:57 -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 CDD58B0; Mon, 29 May 2023 09:34:55 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f6a6b9c079so22898505e9.1; Mon, 29 May 2023 09:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378094; x=1687970094; 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=Dc67GAn2fJGstQiSCO2huhEWgnflOmkWInsUSV0fyQU=; b=HtD8ukpkJm7ageW0ELl1AjOj0plsNq59OVhG4gSvsUopOWZMMAEX6sHSiTW3SfAK9r BC05rFDRldcvf+O5rSCJDV+KIGZW/Mc+1GIy4RmBXCswoW3u/sRl47JxSlfNXze17e// xNH2yN5lkjqgWNVqXU4evOBQoj8YgisymN4YPn1UgUqMtnccfFSk+GCvWvrk7EYsIK5I diegWn76BFsZRBCGCzERkczc3rT2CyrJ6Y363/mPiyV92NG7/erVpCJlm3YdwAF9AkOn /Fghu+OAgwdTZ/SuZCBW2dwGL9cFW7TJby2Te0RIFMaMqytFpEE09/3sEJbclh62tlT6 5QXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378094; x=1687970094; 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=Dc67GAn2fJGstQiSCO2huhEWgnflOmkWInsUSV0fyQU=; b=KdwFK5HCjIoyv9+yENfCz4qmIJtm/cZbdkELGgZ8Xri0THB3d+cexGjA4AhKvDOKvU 3/Sm1gBkhLCwe8B5STVh6hU0jP7KKCJVMlgY7tPN5FrSysTRT++ccELF3nurrHUZFzZf ua9Z9mII7E1elbaHvS8TIA5nYsSCwhCkzuiNd1U8hkS6O4w0HDQIr4SCH2qjK128GlRU 5C6zDpVMa/js5seWDxMC9GB0XOyJ5zPCGb08doDYR4RQYe0RlcR1SXKkL5wu8MckUZ/8 7wWmmWBwdZ+rVeEmCh1qWzlsevLNiEliDT2hsDQDF45PgcKg2ypF0MC+KqBn/X28jEia xhEw== X-Gm-Message-State: AC+VfDzekLoKX/SX4d5vls8uj9IoOg/L+L7sUKGQ/SrbRJJ4OvhB3q4P zD+pe9bG/nTrn71IvlmyGSM= X-Google-Smtp-Source: ACHHUZ5vIWhmzR24SFs1pnI0binXdaFcvbL+XPYCEoHFZokd79N85S56OtjbUcAuRkUyfOOVgYLcKQ== X-Received: by 2002:a5d:4089:0:b0:306:28f4:963c with SMTP id o9-20020a5d4089000000b0030628f4963cmr9487862wrp.23.1685378093966; Mon, 29 May 2023 09:34:53 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:53 -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 v4 11/13] leds: trigger: netdev: expose netdev trigger modes in linux include Date: Mon, 29 May 2023 18:32:41 +0200 Message-Id: <20230529163243.9555-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 e8bb9d0f85c0..b0a6f2749552 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -56,15 +56,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 Mon May 29 16:32: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: 687572 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 BF9BAC77B7E for ; Mon, 29 May 2023 16:35:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjE2QfF (ORCPT ); Mon, 29 May 2023 12:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjE2Qe6 (ORCPT ); Mon, 29 May 2023 12:34:58 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AABEDDC; Mon, 29 May 2023 09:34:56 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f6ffc2b314so9186395e9.0; Mon, 29 May 2023 09:34:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378095; x=1687970095; 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=I5iBEigDDB2ulS45WuE7DITMi8SCugzHw1a9vqnyc1o=; b=FZYHv7Exy1MX6pppkpTEcoFCQEN2UctNc7I1aVUjGuWekSOAeWprVWMatUys1Yhxbm /TtmaY3Mb67/MbYmm+lqu0Tj1OOI2aUEy6gnvBNGwG+XEaQVzMv0yUGliGPVfeRKDDH2 7wJwRc7hIRH377mPduNZVw5EI1BT4Q0nQOopWFNQ6A3IBHKB1UfNOJOms70I8T+ypbke JqtFtFyHYDqqsTnxtgaIiiO57s5cv5B6gx5fA9pRr+Dmwga66AVHPMDYtaYVJz3s+N4B UUmuI2irTCDnUB9nQWY6hFQIS8Z3jGJll3l8JTmiow7KpcM27T2p6EfEPB8EruGRoOVz bjbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378095; x=1687970095; 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=I5iBEigDDB2ulS45WuE7DITMi8SCugzHw1a9vqnyc1o=; b=G0/OKG9U10nFlYO9lbOLuhNjNPV2UCCWlIMd9Osom610JEZrlCasaG+476Eq29ajx9 3e8bFs8kAjOWr7u2JRU6AqWlkEuFxr4p4zk1PIwmWbTJRepmZxDhQ2TolKNDJXSF6FFa WzM76idGqOPaPwESpIV3UTNVXZRmhh6gF9D5AYiO3nYID/zF9yToBauHHrpqTBVDE2RD vNK86gAHXlhNZ32l7iNFrK98wSCqULNCnWPm5rWnhD3kpyp71RusBrcTM8QzMs0ke3Io eqPGW35j/SspJBx+S9vsQbq5Po3noM9/AL9dM5e7sRV+TCmaVWo7EbLGeRLNXwLo7KFO SEdw== X-Gm-Message-State: AC+VfDzl6kpomwzFTU1LNDC13KQxRlBkg34xPg227omWE01B/ycFREUq hiizAjEPRealCr7Y6++3EWM= X-Google-Smtp-Source: ACHHUZ5sVrwaqI1JIJvaGZpaYuR2sG0MppecZ+yiXUqHKOSgPHFT7MWAIQihj0G3yH1wwSOsAjMLhA== X-Received: by 2002:a5d:494f:0:b0:30a:d944:b765 with SMTP id r15-20020a5d494f000000b0030ad944b765mr2544200wrs.15.1685378095045; Mon, 29 May 2023 09:34: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 h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:54 -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 v4 12/13] net: dsa: qca8k: implement hw_control ops Date: Mon, 29 May 2023 18:32:42 +0200 Message-Id: <20230529163243.9555-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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 Mon May 29 16:32: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: 686801 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 EC6FBC7EE2E for ; Mon, 29 May 2023 16:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjE2QfG (ORCPT ); Mon, 29 May 2023 12:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbjE2QfC (ORCPT ); Mon, 29 May 2023 12:35:02 -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 D6CABA3; Mon, 29 May 2023 09:34:57 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-30ae95c4e75so1398747f8f.2; Mon, 29 May 2023 09:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685378096; x=1687970096; 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=PjaUxclvYxLTW+lF+DMGV+Jv8MEZNZ48mOXSHw8P4awEet1eXJ5A0YPEO3/8Eqevmw blDshi3XLKUYNdwRqfPDn8d7ahZMcI40Hg/lvp17xkG6LsKo7J1shlFx7IstEZoOL/Pt 3sq86mz8+BFxA5kx1vZnOALKb/NdvyChZ/I9eP6LArMu4kfTVoEWyr0/U0UOHvLuXlr1 a9bGeCMGf3Urc/0+PRvtBsi6U8ozhpcGAAWUuEGuAkBak6qHWyqXWzr1iOs+2LWHZn8/ QpEEDgdT6U2YMbkHq2YHi4oh5zqjrQSoo5lYDLqgKiIpvNc+GTBYuEAumwZ7Zqjmnkc6 KxTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685378096; x=1687970096; 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=Aa6LMu7OYe3pPHNLLjMu48zja1sa2LWeas5uozPU7R5Wafw4EzSwqVC2dR1Ksjndwu cNJElt7aTc62ndA8MBXtqSamMh1DTxadhNif57caU08bdsxO194JCWtn9hwxq/NECUlZ VfivfGIaQvmsOsFXaGA1V0Eodnh+TR5RoL34x82tz/RCLo6vXLD0hwMw6oHqGHh3sGjl O5MHcwnRxZom9P6QCS75CUNxKN154vpAkM4DTeovDnVPby/TxFp1jLiN5GGk8EKqOGdJ kC2ydiW3lQJ+8WI7XDGTtOh5PEhTj9oxeN4IUqS3jqgIFK0QEMrvxu/iXib083eS8iWN BPSA== X-Gm-Message-State: AC+VfDytNtnzUCpbi8bI8gevQMI551CxRHsM8OxkZXZ2sgVUu5M4dwg1 9+Q7eKbLzjNuIsJUMx/dfB8= X-Google-Smtp-Source: ACHHUZ6RL7TiSPhTjCPyiPugSHdtdBflwvIkfNfQqsCcVJduqysNI6L2eRQsrRql66UqpTpkmKCiiQ== X-Received: by 2002:a5d:6e53:0:b0:2f8:2d4:74ef with SMTP id j19-20020a5d6e53000000b002f802d474efmr9368337wrz.43.1685378096172; Mon, 29 May 2023 09:34: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 h14-20020a5d6e0e000000b002ff2c39d072sm417513wrz.104.2023.05.29.09.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 09:34:55 -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 v4 13/13] net: dsa: qca8k: add op to get ports netdev Date: Mon, 29 May 2023 18:32:43 +0200 Message-Id: <20230529163243.9555-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529163243.9555-1-ansuelsmth@gmail.com> References: <20230529163243.9555-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;