From patchwork Thu May 25 14:53:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 685769 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 281E7C7EE29 for ; Thu, 25 May 2023 14:54:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241666AbjEYOy4 (ORCPT ); Thu, 25 May 2023 10:54:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241428AbjEYOyz (ORCPT ); Thu, 25 May 2023 10:54:55 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9226D19A; Thu, 25 May 2023 07:54:53 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-309d3e8777cso851758f8f.0; Thu, 25 May 2023 07:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026492; x=1687618492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cKIEgFgmjScZJvZv6lwQPPIWSzDEZLIyZZgdXEW7tPM=; b=bEpsUQez/S+BHTLLATX9nnqT+iAwWcmnFR/F5Zrz+j9NgVCyzD/nbmVJR8gSou9Uu/ R5fG3EH/BRx0T1NwikoNCjAoehM82y1mDUiP8Rb9GLsfEtSiqQJNDkxuDvV9Rb5We5fa x9qZR7MkCnf5a8Z0fyaI5HsevZ21YMq30yLr7QBspRcsTK77bn+NK6YIu9vzzMpbJbSC kSq3n0gclNrP0eotH/usPYVQ37ZP6rbbdfYYta9v6SgQMKToesvNHaE+3y/02uxCkVmk VpkpkTmyNMD5e2peNEvVOpJYKzKtqAFLXF2lDywEA9U8K8B/0YpR5fo0pyRXRoRVk1Ef AhtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026492; x=1687618492; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cKIEgFgmjScZJvZv6lwQPPIWSzDEZLIyZZgdXEW7tPM=; b=bO+SvyPQzjVEZNbaobBZti7PSFUlUND6ETfztUlCVwYM8/ucF+IFRdcKDZwRxLs2Pk Nx56b9MuYcbbPomq407iTxTV9irb5dXYDcXHYYzfa4OK55DMr1uh3edo9owXp15DutDH amzoSwW98VLDax6mOjfLRqCCoV2vQtIWFHjFxVVCma3VZVLxV3VNGtNk9xGh/20zhF3U Su7RZX7T+RUnCPOaeJUmIj8T9qNMEobn98Hk/IsvSPa9aGVJMHtgrVYjn4scJy7uGoIM dHRa9zC6jj2y7Y4m2X8WJLrAbhorZsDF1D3LaX18pT9pVxRzoyxVIB5saAly/RnU4owC CNLg== X-Gm-Message-State: AC+VfDytL3JwxuxRjgDjw/Vw2bkbqDfcmS9r34dwUmFK7gy6t1I+ryRH aDuHW0faViW1WvAjfQYXkao= X-Google-Smtp-Source: ACHHUZ5nP5jh06kC6rateL9FNiX9agRpIylAkfx0EYikYnq9vnhtH8p81SosuYRCxtGgECF7+k0XZQ== X-Received: by 2002:a5d:51c7:0:b0:309:596f:e5a8 with SMTP id n7-20020a5d51c7000000b00309596fe5a8mr2326033wrv.4.1685026491665; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54: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 v2 01/13] leds: add APIs for LEDs hw control Date: Thu, 25 May 2023 16:53:49 +0200 Message-Id: <20230525145401.27007-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add an option to permit LED driver to declare support for a specific trigger to use hw control and setup the LED to blink based on specific provided modes. Add APIs for LEDs hw control. These functions will be used to activate hardware control where a LED will use the provided flags, from an unique defined supported trigger, to setup the LED to be driven by hardware. Add hw_control_is_supported() to ask the LED driver if the requested mode by the trigger are supported and the LED can be setup to follow the requested modes. Deactivate hardware blink control by setting brightness to LED_OFF via the brightness_set() callback. Signed-off-by: Christian Marangi --- include/linux/leds.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index c39bbf17a25b..4caf559b1922 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -183,6 +183,43 @@ struct led_classdev { /* LEDs that have private triggers have this set */ struct led_hw_trigger_type *trigger_type; + + /* Unique trigger name supported by LED set in hw control mode */ + const char *hw_control_trigger; + /* + * Check if the LED driver supports the requested mode provided by the + * defined supported trigger to setup the LED to hw control mode. + * + * Return 0 on success. Return -EOPNOTSUPP when the passed flags are not + * supported and software fallback needs to be used. + * Return a negative error number on any other case for check fail due + * to various reason like device not ready or timeouts. + */ + int (*hw_control_is_supported)(struct led_classdev *led_cdev, + unsigned long flags); + /* + * Activate hardware control, LED driver will use the provided flags + * from the supported trigger and setup the LED to be driven by hardware + * following the requested mode from the trigger flags. + * Deactivate hardware blink control by setting brightness to LED_OFF via + * the brightness_set() callback. + * + * Return 0 on success, a negative error number on flags apply fail. + */ + int (*hw_control_set)(struct led_classdev *led_cdev, + unsigned long flags); + /* + * Get from the LED driver the current mode that the LED is set in hw + * control mode and put them in flags. + * Trigger can use this to get the initial state of a LED already set in + * hardware blink control. + * + * Return 0 on success, a negative error number on failing parsing the + * initial mode. Error from this function is NOT FATAL as the device + * may be in a not supported initial state by the attached LED trigger. + */ + int (*hw_control_get)(struct led_classdev *led_cdev, + unsigned long *flags); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED From patchwork Thu May 25 14:53:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686600 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 E58DDC7EE2F for ; Thu, 25 May 2023 14:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241645AbjEYOy5 (ORCPT ); Thu, 25 May 2023 10:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241670AbjEYOy4 (ORCPT ); Thu, 25 May 2023 10:54:56 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEB53189; Thu, 25 May 2023 07:54:54 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3093a7b71fbso2169366f8f.2; Thu, 25 May 2023 07:54:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026493; x=1687618493; 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=C35jgQvYw4Dhhjlq99GXGkWM9YbjFEYiiw9LfV1Tp1x6yoEIDZnO3hkXa6LWtJe3IU By2/VVkms0uR6f+WLhqc3CRLPXSq4XIWO+FHMsMIDPkaDxdWrdQSHlvRcgJOw3XwCutc BX/lVhXxlPIExBREDcetGXhrHXetoYkHgb/hSeMInbMRbDpvcbRe7vYOHkAq0B7lwHpM UY3/QqC81e1vj85hb7k3fQLKHLTKNIf+8mZpm00ZvGZEaE6a/bvJ9BlEiAWNiVuu4BpO Ag47CGEEDZ3+x5DfFVgccLmvEnfGiR8fHulRMnDP2G9CHkBOeiEbNojYoHrO0P3/b2s7 lB3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026493; x=1687618493; 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=HwoKe6sY4ER4NXUAC1cE0Yl12Vu1GSX9fo80dOri/RM+S3fRyuaVKR47zNBQVzj6KS +CjniBx5GnC8kR7owMgd+8ioJanS8hOTZgA/eU/V2bFm+kheba6vvt8UdVyDRrQKM2PO nPs/ppR2qW1eyWDEV/HnTa/NXUoaIsRjxq5HtQNbCeWgwfXeqc5ogWYuB2F9fvUdLq/M I4tW42i3muS6XdC0xsLLiPANWTWNOHwM4Trzm70vQGWvETqgTM0M/L4bXqbdJdq2/z9O MDAeOg08gNnGsfjA1dqwQeWH2o6uvS9N/12Mxt5vM5Rs7dQNAuiRpnCsv9EQ9wCD9seL rIGA== X-Gm-Message-State: AC+VfDxqZxH84ISX6u2sqBT5cR2lel9Jo0QI5G2ZvtE0is6VdilOsrZD 0wP7tvPgAgSAfwz1eAJF2/o= X-Google-Smtp-Source: ACHHUZ4yim//MQYKl+ciB5nU+SaUj6ChGYSycH1ljm+IfjlbfZGvhl9UUJDQN5vgUEGbhB9wl0gn/A== X-Received: by 2002:a5d:574d:0:b0:309:54b6:33b0 with SMTP id q13-20020a5d574d000000b0030954b633b0mr2822027wrw.44.1685026492884; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54: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 v2 02/13] leds: add API to get attached device for LED hw control Date: Thu, 25 May 2023 16:53:50 +0200 Message-Id: <20230525145401.27007-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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 Thu May 25 14:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686599 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 CBD51C7EE29 for ; Thu, 25 May 2023 14:54:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241428AbjEYOy7 (ORCPT ); Thu, 25 May 2023 10:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241494AbjEYOy5 (ORCPT ); Thu, 25 May 2023 10:54:57 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D67E19A; Thu, 25 May 2023 07:54:56 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-309553c5417so2182781f8f.2; Thu, 25 May 2023 07:54:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026494; x=1687618494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=MgugxQZ+bMvGGxcEF4OyoNgsowC99irm6wJEB6lkhic=; b=jwrCSAKy7iZ9UPxpT/b8WHG4OXncdijOovtoR+94BKAZHN8hcwBZfnmvWeyC1bq10X eMsavHmidOJozl7XbGDg480/ueANtV+5WVCJt7sX+ZIIVJsEeqvu7k318JypjUSGRfyi 63gmG6Sc1QmoByGFZ7vv8lPOEFU6nvx/0NvJO9HeLd1gfZZCldEPBIKtFdLVW8dbqoy8 TjBOfnewvFV322koPdoIwRCw4tB6RySI/cUKPLV3uOi9bNsI64Ax8viC1NLz9EVcGSEk o1AfhZzUzL/jU8jUXH1w+QQbMiYKz1N05QafNGy1HEFQzJkmlynlXobDYNwt7XOfF953 fsyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026494; x=1687618494; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MgugxQZ+bMvGGxcEF4OyoNgsowC99irm6wJEB6lkhic=; b=L9uiy+FFaBUWOOYWNCu+LxIBPELVx7wQxegJ9ktv7a6shBwBQP25tXH1NA0+zZM151 Pdw8I7X2FvNdfpnvsN5c5eFLq5IFHwsfeNF7TX2nH8r1BsdfRaEL3ZlwTGhgu7Z/Aq20 u5+eG4MGbIPRmjh7vGomXgax9V6/kP23LposalQbM744cfL/7BbKKsE7BfhnezGB8fTo nIKlDs+K6AW1R2krWwGb1XDB0cnDuAOWKmylVl+T/fshSedEpqSx4viLUJ/xHaiKtA9b WyAUmqRljISXBbrSg7NGpVrH0HT7hSNcUOLtBGkLJshs5RPseBOgTTz+NuKwxvUse+Z6 1mbg== X-Gm-Message-State: AC+VfDxNGEzttim01VAVQFVlX8Ml5aGF6fFyueAE2vvzSdA4XkMnBJLk Jjduu1RB24Q6KWDdR6zWM50= X-Google-Smtp-Source: ACHHUZ6S1LeC8p+a6GWwe9ZYi5apUgvlxyfjWWX+Ppr6VGCV7UW60L4rPYI+7OGs8FOV2CLUJTgfCA== X-Received: by 2002:adf:f2ca:0:b0:306:36b5:8ada with SMTP id d10-20020adff2ca000000b0030636b58adamr2761281wrp.29.1685026494299; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54: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 v2 03/13] Documentation: leds: leds-class: Document new Hardware driven LEDs APIs Date: Thu, 25 May 2023 16:53:51 +0200 Message-Id: <20230525145401.27007-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Document new Hardware driven LEDs APIs. Some LEDs can be programmed to be driven by hardware. This is not limited to blink but also to turn off or on autonomously. To support this feature, a LED needs to implement various additional ops and needs to declare specific support for the supported triggers. Add documentation for each required value and API to make hw control possible and implementable by both LEDs and triggers. Signed-off-by: Christian Marangi --- Documentation/leds/leds-class.rst | 80 +++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index cd155ead8703..3d7874c18982 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -169,6 +169,86 @@ Setting the brightness to zero with brightness_set() callback function should completely turn off the LED and cancel the previously programmed hardware blinking function, if any. +Hardware driven LEDs +==================== + +Some LEDs can be programmed to be driven by hardware. This is not +limited to blink but also to turn off or on autonomously. +To support this feature, a LED needs to implement various additional +ops and needs to declare specific support for the supported triggers. + +With hw control we refer to the LED driven by hardware. + +LED driver must define the following value to support hw control: + + - hw_control_trigger: + unique trigger name supported by the LED in hw control + mode. + +LED driver must implement the following API to support hw control: + - hw_control_is_supported: + check if the flags passed by the supported trigger can + be parsed and activate hw control on the LED. + + Return 0 if the passed flags mask is supported and + can be set with hw_control_set(). + + If the passed flags mask is not supported -EOPNOTSUPP + must be returned, the LED trigger will use software + fallback in this case. + + Return a negative error in case of any other error like + device not ready or timeouts. + + - hw_control_set: + activate hw control. LED driver will use the provided + flags passed from the supported trigger, parse them to + a set of mode and setup the LED to be driven by hardware + following the requested modes. + + Set LED_OFF via the brightness_set to deactivate hw control. + + Return 0 on success, a negative error number on flags apply + fail. + + - hw_control_get: + get active modes from a LED already in hw control, parse + them and set in flags the current active flags for the + supported trigger. + + Return 0 on success, a negative error number on failing + parsing the initial mode. + Error from this function is NOT FATAL as the device may + be in a not supported initial state by the attached LED + trigger. + + - hw_control_get_device: + return the device associated with the LED driver in + hw control. A trigger might use this to match the + returned device from this function with a configured + device for the trigger as the source for blinking + events and correctly enable hw control. + (example a netdev trigger configured to blink for a + particular dev match the returned dev from get_device + to set hw control) + + Return a device or NULL if nothing is currently attached. + +LED driver can activate additional modes by default to workaround the +impossibility of supporting each different mode on the supported trigger. +Example are hardcoding the blink speed to a set interval, enable special +feature like bypassing blink if some requirements are not met. + +A trigger should first check if the hw control API are supported by the LED +driver and check if the trigger is supported to verify if hw control is possible, +use hw_control_is_supported to check if the flags are supported and only at +the end use hw_control_set to activate hw control. + +A trigger can use hw_control_get to check if a LED is already in hw control +and init their flags. + +When the LED is in hw control, no software blink is possible and doing so +will effectively disable hw control. Known Issues ============ From patchwork Thu May 25 14:53:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 685767 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 6A638C7EE2F for ; Thu, 25 May 2023 14:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241339AbjEYOzA (ORCPT ); Thu, 25 May 2023 10:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241656AbjEYOy6 (ORCPT ); Thu, 25 May 2023 10:54:58 -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 3BF9E191; Thu, 25 May 2023 07:54:57 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-30957dd7640so1529671f8f.3; Thu, 25 May 2023 07:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026495; x=1687618495; 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=H34FDSVCIspH1Do577D6zCt7FtKHMAv2UsgzeDJKAdeZAyyNF9t1/NLIf8QQOgyKVP b1dOlR5RxVdICgHMYXHy20Xbr9goCUK5hdHKZvZhu5n1AJuzV4HzAKtUoinCUX9cWTWE jdCm9hcEmurRBxgQSQszcXvsB3iYn0K7H5ZETBFz5Dp6MMW++g5YdrJ0216qY7eRa+ik RvoX3gmcz8RBSMgb/PsKOWKW5iprEtIEwZJo/epYDS1P0U4ManTd4iwQYc2NfUg4Uzl5 yMijsKe+1xHlb7UyIYD/1ovq9zqgd/BYz9aHem7adqs5jNB1Jd+sCQOWlCKugQho9XcS Dyzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026495; x=1687618495; 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=J7ghjT6G7UqrACyy6mTk2+/0FeNRpgnfmXHkSVaS6ygFfFsemq/MFPRk5iYHsrdQYM +Im3tEHFSYPJosM0dxEqgCgcbRYb+WxCCcw5X3F3bL5gpcvWJ4bMm8fAzJFYAE8SNfpV DsUqkYRisYTkM92N+1+eryZa8x7nm/g7EhJtrvNcp4fyJVTDrMdh0KM3UcIZ+cvdMbmw 1EDS8cMKTt2dgQBg/iUhiSNdKRgY45bMyBEKhCsH5hLKta7dLEQPbddEYBSvmpKVPxPI Yy8rLe6jP8tpyL+jLuXkG6y+qKGwManIWdk4JeOfk2szKWcQSzzzR+M7ad0Oj2MxtdfO i5Bw== X-Gm-Message-State: AC+VfDyM0FVeBX4z07TZW7sVF2yrbvPdB21ZsRU3fiV8F8ALpILA5wTS ynRwJucCyvzmjjZgGWDiVSU= X-Google-Smtp-Source: ACHHUZ6SWRun1ObfcRGxN6jIRjnc3y61W8wJm7tifqFEKq1XQAGGqenFcqMzMjD4FHiXWhs54gboMg== X-Received: by 2002:adf:f1c7:0:b0:306:2c39:5d52 with SMTP id z7-20020adff1c7000000b003062c395d52mr2560573wro.57.1685026495381; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54: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 v2 04/13] leds: trigger: netdev: refactor code setting device name Date: Thu, 25 May 2023 16:53:52 +0200 Message-Id: <20230525145401.27007-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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 Thu May 25 14:53:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686598 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 150F0C77B7A for ; Thu, 25 May 2023 14:55:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241699AbjEYOzV (ORCPT ); Thu, 25 May 2023 10:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241689AbjEYOzF (ORCPT ); Thu, 25 May 2023 10:55:05 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF351A2; Thu, 25 May 2023 07:54:58 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-30950eecc1eso2201946f8f.0; Thu, 25 May 2023 07:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026497; x=1687618497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=DnUn0MEBWwXZf1tNVwC84UFbfwX24B+J30/BoHmbFJQ=; b=L9qwhIRWPN7xyd6AokoG8VTDGdDWR0L7KqH3rLfrbc5v1iJ0RyI/+ZbyjyaqdQ+IMw oZIZ9fDJb9afTTL9au7yZ3fBpDKj0ReZdoE3UaKYjdCOpNlxFwkUiYBomJXTRuz2L1R3 Rjo3HG6I/yuzEEWkB5xdQhOhodUR0HGbRrhRZPpD/GxBSrm1sv3Bj9I406qKDXE7O/HN cRFg3c0VULqJWe/x7KIKX0vQul/HDrrz9zzIJnQRwtrneYu7BbZnqZ9qhDQyoJ/IXGGh DHk4wWtlfzCix5OLsnSuswYeuKSbpmvIkjL4RLffO/sHMK4kLOJz2xqnHtLN+XXTqq8o SjBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026497; x=1687618497; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DnUn0MEBWwXZf1tNVwC84UFbfwX24B+J30/BoHmbFJQ=; b=CqauxSNpFBzgy1mo/jo5q9XWJhX/iE2avJFxwsyagHaHuD1lCRWB1Vi9qyUBsusfIA X+GeYiFbDHdzPrmiAaFUTxlGwiNZ5tmGDAriU07xLgqevflaNX1oaca+xNw4aZyVt8Iu PEVjFXMJtWM8O/lzwWyYMe4d41TmHbpi0I5+3TDTqQwnaazzw4FgyefwajMXwO3iN59D r2jSIU/lUrd+PxjTCQzwoG/mZ9OfwRUBjBysSMm3F2zKdqgdQHBRJRoSIo/0WWzkyJbA 0IN/7lrzHHhYpwfA5I4hSo6GkEVvsypsiYsjoVpNM79qq4UrFvWwBiWkdpKoxCxS9Lnb Iu4g== X-Gm-Message-State: AC+VfDxfBkX1Z/mu0xZSyJUFYckRfGtvAfCoRXAuMs5ClOvM0hc9N7Ca gNBf7gCXUCvYc41vZ5VLkhM= X-Google-Smtp-Source: ACHHUZ5CVkcObPO9Hg/AfVvSZBzuvp2/TDjypLE6kc/nI7adGWqjTwT6zmI91cCpLsiTNe1cCLlROQ== X-Received: by 2002:adf:e889:0:b0:307:8b3e:285a with SMTP id d9-20020adfe889000000b003078b3e285amr2532887wrm.67.1685026496547; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54:56 -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 v2 05/13] leds: trigger: netdev: introduce check for possible hw control Date: Thu, 25 May 2023 16:53:53 +0200 Message-Id: <20230525145401.27007-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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 --- 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 Thu May 25 14:53:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686597 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 78BE6C7EE2D for ; Thu, 25 May 2023 14:55:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241725AbjEYOzX (ORCPT ); Thu, 25 May 2023 10:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241621AbjEYOzU (ORCPT ); Thu, 25 May 2023 10:55:20 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CF6519C; Thu, 25 May 2023 07:54:59 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-30a8c4afa46so851286f8f.1; Thu, 25 May 2023 07:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026498; x=1687618498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9HiOL7lEFVgjMaEJrcmVlJpY1uQMDGELzriKpZXWbcM=; b=WR6lGEYzaUQzezgwM1Zx2/XWcpf6TwAB5cAfMIg5d3BUkNWNZZlNkUsS9Ob3L6F/V/ ss/4WJXw9NaWnh+eDyFR9NdyN+Dpg92W3uqAGVHkES27O+lwIA38SLXAGWzi4ot7+4Yu 2NZHsC1SXt6vWZteYEyUWspwCVVx3yRnYvbaSYzpwGP6z5ZOqGXt7Bv5kO2oIeMIVAXQ GLfIVUF+Q+EmS7PfTuw2yWBKe/biuDMZPuVxUQXjgWkgaK8bGgs/xBd5HGgFctI5uhTa dzlCeyZEFXXigGojH6ijXLLknJQbFZ7UNzK3dWlaof9B8U1b9JJzd9KcbIBEXT822HbF ckXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026498; x=1687618498; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9HiOL7lEFVgjMaEJrcmVlJpY1uQMDGELzriKpZXWbcM=; b=OEgcA1PvADnbqv5woX2nXCGIGyI5dCE2NiTR7RTaQOd1BEy1M2kZCfwr5cUOTvyR1Y B1cr5IHctJ6V3AxJyJk7fumEDdlqGzAypExSAX92A8x+6HsiuItI4tnJ7ERGIQBi7EqA TxGlij8XsFLTmXh82PvD6KWoSstlDMa5iC1XJaKUUpkGJ2GxkDB9katb9o8gpF7P322w 4GMRokgQ6qvyzA3tmpj9ez7Hzx4BCgeUFWgrwUHCJxZS75o71I+9rXnQZ8bAd7/bcbXh UTzcojoHbNrR5Q/RpSw8/n2AGXPndd0ImZltEUtzHuw4gq9D7n1Aptcm9OQv8jm+VpES 5rjA== X-Gm-Message-State: AC+VfDwp9aGUNL4sYMRMWlpmK3aqe/siIu0LaDu0cLPthiGli08ifSTE t9SpyqRLJ/liJdAIxEILfYwrWkiXv4k= X-Google-Smtp-Source: ACHHUZ4ekmf2x7kEuvrJ5ydkFNVMlIkPJmj5XvRmgqhLQB57SdEaUX5AkBoPGKYjbOTehz1qLhRpow== X-Received: by 2002:adf:eb8a:0:b0:307:f75:f581 with SMTP id t10-20020adfeb8a000000b003070f75f581mr2268693wrn.18.1685026497648; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54:57 -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 v2 06/13] leds: trigger: netdev: add basic check for hw control support Date: Thu, 25 May 2023 16:53:54 +0200 Message-Id: <20230525145401.27007-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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 --- 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 Thu May 25 14:53:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 685766 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 35C72C7EE29 for ; Thu, 25 May 2023 14:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241717AbjEYOzW (ORCPT ); Thu, 25 May 2023 10:55:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240727AbjEYOzN (ORCPT ); Thu, 25 May 2023 10:55:13 -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 7014C18D; Thu, 25 May 2023 07:55:00 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f6094cb2ebso5432995e9.3; Thu, 25 May 2023 07:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026499; x=1687618499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AMFIVEMdnhDK+r9aZC4DEh7b5Mu4DnfdJk/ks7MSEOs=; b=mI+0fiQQqtsQBJm7KXX3R4+bCHCa6vTlfiZxJzVyGrbn+lOUAtQxwBBtnySJM5xy9D +Zv8ScZK4SPcxkwKCs7rWGCZUTn9efzMQg6oRD4KNXb1BBESjr/5f3lOgPoKFcwBLEwE Hnu98WF/YCSgGbQJnXUrgHwlHyy6H+ASPU6j0FfrtHGdih/2e9C+j6ExZhF0NflasIjb f2xFNPJjQGCsDQ0kQIKvoibtozpN4UCkNbYwtxwtTSRbmeytq/I+XBF7neWW+WVrjdCZ 9Jwa9MHJQ+z1TRudrebUkgO8QbB3xuUBY/uQuVpHH16Mi5ivQb9856OMrbRjgBeMjfJg eTVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026499; x=1687618499; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AMFIVEMdnhDK+r9aZC4DEh7b5Mu4DnfdJk/ks7MSEOs=; b=cZvOAmfKgdfvaUIT9peiDelbPtl8ukOiYdg4E4PN8pdY03+qioZytB1F9IVCJQa9CY mFgm6fML/ryQ/PXuOA7jP48dSOSKNBd7MzWxKwut6wbR8TqmRW7XypKDpsjbzvevox1c PQozKvFm0MrVyInGWlmSVzJL4W7wSUvirXTzxVpikN2lHnrOsSdKGusvzVMbXcXikKF9 3+s1PggY7SiaN8RmFnkz+rVBa1V9k+d1cXLBa/U+QwjZr5dKYO8jbDT0P9BdR3u3Ad6G OEuGqAXTdkNAgDCXnyh7lq1XDjve3bxdDVuRB9/Om1uW7FgzCPdVeZcvAdRvTPOfoDJH ODZQ== X-Gm-Message-State: AC+VfDzDMvZ9/SjXD8GWebrwsV1ynaMUPphtegvtvTv5C6FlLCigcCH6 G+g6A3r1A1idfg2auAfFIIc= X-Google-Smtp-Source: ACHHUZ7IQ0Cpd1ZyXrl5/2lcJ/959rFbvu2cNfFqg4oEeT1iov7cZBG8Kn+l271onXjvdg+sEwD7Mg== X-Received: by 2002:adf:eb8d:0:b0:30a:a440:46ec with SMTP id t13-20020adfeb8d000000b0030aa44046ecmr2876693wrn.8.1685026498759; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54:58 -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 v2 07/13] leds: trigger: netdev: reject interval store for hw_control Date: Thu, 25 May 2023 16:53:55 +0200 Message-Id: <20230525145401.27007-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Reject interval store with hw_control enabled. It's are currently not supported and MUST be set to the default value with hw control enabled. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 2101cbbda707..cb2ec33abc4e 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -265,6 +265,9 @@ static ssize_t interval_store(struct device *dev, unsigned long value; int ret; + if (trigger_data->hw_control) + return -EINVAL; + ret = kstrtoul(buf, 0, &value); if (ret) return ret; From patchwork Thu May 25 14:53:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 685765 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 25C02C7EE33 for ; Thu, 25 May 2023 14:55:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241729AbjEYOzX (ORCPT ); Thu, 25 May 2023 10:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241691AbjEYOzU (ORCPT ); Thu, 25 May 2023 10:55:20 -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 DDFE91AC; Thu, 25 May 2023 07:55:01 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3094910b150so2177604f8f.0; Thu, 25 May 2023 07:55:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026500; x=1687618500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=duk7D4T1VAqrdSK3J+2RtTub/SxkfwJR2fWIQ5D7Ni0=; b=L4RmAw3XRXnmmRpYDcP8hy1SU0hm5E0T2muMkL0ByGYoY8SHDyIfOLB+Au7OBORQJr 3Z4zb7bIbJvLZuk4ChKWLOd/szhiTwiAMAYDcopAepffd7L6lesv/jSHhL20IlGC0CO7 vliPhSZLxQy0CiaNwXDbWIidJ+z5fSAQ5WKxOl58KX/d2cgt0r7Kni0AmBIGyoU9Mpnd DRxmRLlsoF0zQvFAuMuqv2G+i9PWl4NNbnkvJFomq85mvr6h5sLlXRa+wN3KKlExP2NS mIajra2wE0vTaxSEjr4GiR/qbABuvoxuACJnhPdR5S28umVt3qGduQ5dlPypfjL9FRAw ZVkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026500; x=1687618500; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=duk7D4T1VAqrdSK3J+2RtTub/SxkfwJR2fWIQ5D7Ni0=; b=hTR32unKk6UyJD+SR6KGsv+L7L8VK1APrOVssVDJUBTYpeVnfRjCphxlOMoAd45/qO UliAl4adjGOgHRVHdD1L8Oq0BXYJLniA+6au3h4d5qVh4Qcu+8CE6aamE636+sGRZ1+N 62DTwKfSM0ZkgDAh02US/OsHNJSzOrsgLgb2P48A4x8RCj0CsQHth+K0DZP7LRq4HdW3 IWea1q19XQQUgjAaAAi6vuC+LNCvKwvqAr34EaqDSaQ28/MfaDsas29lWqGGoxRe80Ux 54BXPkfcV1F3r0yKwk9S198DEb3Ua9EZMBn2hygrIcQ+F2O6fxUBQe62oEPGYcNvIwq5 aNNQ== X-Gm-Message-State: AC+VfDzo8ncaNws9qAp0jU9Muo8pcN4Mqvjap1n9l5Rn3rJhh/faEe6t hyW0aSK8/ivfgN6i2SwgSAc= X-Google-Smtp-Source: ACHHUZ63aC3p/Y9apeYCYpX+JXDoCoMpXpET+sAt7Kk9dDl7t0U8Erz0Z3Itk3eq6QnvoMYpGnMVXA== X-Received: by 2002:a5d:4952:0:b0:307:8126:5e30 with SMTP id r18-20020a5d4952000000b0030781265e30mr2428897wrs.38.1685026499900; Thu, 25 May 2023 07:54: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:54:59 -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 v2 08/13] leds: trigger: netdev: add support for LED hw control Date: Thu, 25 May 2023 16:53:56 +0200 Message-Id: <20230525145401.27007-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add support for LED hw control for the netdev trigger. The trigger on calling set_baseline_state to configure a new mode, will do various check to verify if hw control can be used for the requested mode in can_hw_control() function. It will first check if the LED driver supports hw control for the netdev trigger, then will use hw_control_is_supported() and finally will call hw_control_set() to apply the requested mode. To use such mode, interval MUST be set to the default value and net_dev MUST be set. If one of these 2 value are not valid, hw control will never be used and normal software fallback is used. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 39 ++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index cb2ec33abc4e..8d6381415208 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -68,6 +68,13 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) int current_brightness; struct led_classdev *led_cdev = trigger_data->led_cdev; + /* Already validated, hw control is possible with the requested mode */ + if (trigger_data->hw_control) { + led_cdev->hw_control_set(led_cdev, trigger_data->mode); + + return; + } + current_brightness = led_cdev->brightness; if (current_brightness) led_cdev->blink_brightness = current_brightness; @@ -103,12 +110,42 @@ static bool supports_hw_control(struct led_classdev *led_cdev) static bool can_hw_control(struct led_netdev_data *trigger_data) { + unsigned int interval = atomic_read(&trigger_data->interval); struct led_classdev *led_cdev = trigger_data->led_cdev; + unsigned long default_interval = msecs_to_jiffies(50); + int ret; if (!supports_hw_control(led_cdev)) return false; - return false; + /* + * Interval must be set to the default + * value. Any different value is rejected if in hw + * control. + */ + if (interval != default_interval) + return false; + + /* + * net_dev must be set with hw control, otherwise no + * blinking can be happening and there is nothing to + * offloaded. + */ + if (!trigger_data->net_dev) + return false; + + /* Check if the requested mode is supported */ + ret = led_cdev->hw_control_is_supported(led_cdev, trigger_data->mode); + /* Fall back to software blinking if not supported */ + if (ret == -EOPNOTSUPP) + return false; + if (ret) { + dev_warn(led_cdev->dev, + "Current mode check failed with error %d\n", ret); + return false; + } + + return true; } static ssize_t device_name_show(struct device *dev, From patchwork Thu May 25 14:53:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686596 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 45E08C7EE37 for ; Thu, 25 May 2023 14:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241736AbjEYOzY (ORCPT ); Thu, 25 May 2023 10:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241708AbjEYOzV (ORCPT ); Thu, 25 May 2023 10:55:21 -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 1C37F1B6; Thu, 25 May 2023 07:55:03 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-309382efe13so1560142f8f.2; Thu, 25 May 2023 07:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026501; x=1687618501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bzjSHLcSLKuyYbnB5oKrxVcxoSmgJOggg+ZfYlmNaGM=; b=lPP6ejuyGdUqbdV05DpRufEgFHgzuJGeS64NKLHMuExx8FvbX8ruFT3fTkY41QZeby KkXRgU0ApGNMzqxQRCmArJyv4/Mun+oDG6we+ubfPm1p0Tkk27KMjxpQuIFxWpKBZpvn L5b7YcVy0FAreEqDA0YJ2Od5NrK3v4DNmGu9pHOfxovHja5WiQxvspAruwrGk+l5Tx/s VfT8JQLTrRmicfLSog13cloS+8x3rTx1BgG+m1ohLP7v/+n4yno8zv0029uoAJzunmOT L9CCxNZm4ogSyd0i0l0/yaMHHDSTrgTYpVFFs6MnXF4lRhh4OsGmWV/D8knbsHzjj/UN iHog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026501; x=1687618501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bzjSHLcSLKuyYbnB5oKrxVcxoSmgJOggg+ZfYlmNaGM=; b=CFfvkST6F1Eno5aKsnPfPIHOXob7b9JrYUlEDnLlIYeOzKO3EE+xDcWEhFreZnF4SB SO+J/m76zDpy9uYIwyT/09flJ2quw5wpmVpV6+gl8Lu7m2B7Str9NEatL+Oqqcy/VSUF pywC0UMt/qRfcIgUpP4gy59DyS8cetOKMAu4moJpTdpKT7FjCeNV+cJraZYxmUw0ksqJ BeKlCVm3yCoJa/Qn99yzOgi6wu770rBnlVHRY5ORWT5n8Z3cc9JEySaAHGReARBW4EFL nAImYkLCs18OH7kNstwGLtZAjLE8KUNsGZ4SxSC6YobSSOiX5x8CkpTYfl2iPVrANUp+ r0qg== X-Gm-Message-State: AC+VfDyX43eq8kXicpA63V36S2efVJteURjQKC6jR0guF3xNC8vx93RO +QJGbuo2dJgyAHh9Bob2RhxLHq0Y5H4= X-Google-Smtp-Source: ACHHUZ5C8g7q++jNTKBD8izlwn3KaW2UultwaDuld2Mh5yH1lo+swsqkySFSUo38JGoGOI/+EddZkQ== X-Received: by 2002:a5d:5607:0:b0:309:4289:91ca with SMTP id l7-20020a5d5607000000b00309428991camr2621768wrv.61.1685026500942; Thu, 25 May 2023 07:55: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:55:00 -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 v2 09/13] leds: trigger: netdev: validate configured netdev Date: Thu, 25 May 2023 16:53:57 +0200 Message-Id: <20230525145401.27007-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org From: Andrew Lunn The netdev which the LED should blink for is configurable in /sys/class/led/foo/device_name. Ensure when offloading that the configured netdev is the same as the netdev the LED is associated with. If it is not, only perform software blinking. Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 8d6381415208..5b59441fc415 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -108,6 +108,24 @@ static bool supports_hw_control(struct led_classdev *led_cdev) return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name); } +/* + * Validate the configured netdev is the same as the one associated with + * the LED driver in hw control. + */ +static bool validate_net_dev(struct led_classdev *led_cdev, + struct net_device *net_dev) +{ + struct device *dev = led_cdev->hw_control_get_device(led_cdev); + struct net_device *ndev; + + if (!dev) + return false; + + ndev = to_net_dev(dev); + + return ndev == net_dev; +} + static bool can_hw_control(struct led_netdev_data *trigger_data) { unsigned int interval = atomic_read(&trigger_data->interval); @@ -129,9 +147,11 @@ static bool can_hw_control(struct led_netdev_data *trigger_data) /* * net_dev must be set with hw control, otherwise no * blinking can be happening and there is nothing to - * offloaded. + * offloaded. Additionally, for hw control to be + * valid, the configured netdev must be the same as + * netdev associated to the LED. */ - if (!trigger_data->net_dev) + if (!validate_net_dev(led_cdev, trigger_data->net_dev)) return false; /* Check if the requested mode is supported */ From patchwork Thu May 25 14:53:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 685764 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 04F22C7EE2D for ; Thu, 25 May 2023 14:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241740AbjEYOz2 (ORCPT ); Thu, 25 May 2023 10:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241494AbjEYOzW (ORCPT ); Thu, 25 May 2023 10:55:22 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBF97E41; Thu, 25 May 2023 07:55:03 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-30950eecc1eso2202038f8f.0; Thu, 25 May 2023 07:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026502; x=1687618502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=t032UqrKs2qK0Tmykkb/w0e10wBacVTlNSbQa7zNqmM=; b=lk+LPQzKeEhjejpM7t5dj1Id8x9o3Kde6+5yRdFfD8o17qYlM53Rc1EQO2MZDE6GCK xZxoq7ef6Qb4sEt3lRvgzzADsWYuqR+Yum4tz1uOgIj2aDl32mdWDE0bnRPaQsQh95OA fg0tzv/UMNn1+kmKlKPLuPHmkrndmBkA6xdZypAAyKudtHEEijLGAWdGTCRLm4REcVbd NsSwKrslT2xT1f+o8rf0rasPaqWHBs7UYz9uI9+U56V2rWOdJ5+daTtzy88LXuEAy84t 9FCBnLuUeoglXeqE3XxjvBIUKZxiN0PmyZ/ztBv0KqOGLB25MNzlJtiasPmGC112QAJx IEzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026502; x=1687618502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t032UqrKs2qK0Tmykkb/w0e10wBacVTlNSbQa7zNqmM=; b=CLsnXgV6VisrRKqayVln5HvMb1PV7q0yyF56o06Fi0Ypmu82BvKcsDxAfmGV+Vuqxa OXULMZDNBHOWLpUW2SpbPAX+1rvTmLKYg36IVJbFfDHhhMa+CC5VZA8yTMrR0uojE5Kq HluO7qGWij8EdvAhAQCsencZ5x+AsqV4AeArdUYt4NcshqeuEp+F93J/35/0Im23C6j6 QwEI4BF+ZlJd+oXw3ctFJjuuc06jfkyQVcNkGvu26c1jgtdf9JqHbQW7eYduS23B/yKp gjJu5JqO9DOKogbPtyDcxa8H3ajvsVFrAqRfqho9zU4bVhdcBiMX/IncKj1PSfg7hVrg zrrw== X-Gm-Message-State: AC+VfDzQ+TBTs+PFWVVQsRl7M9fSbFxGYsC7ibIGbzWJi4pqB0QucPxi 3K1B7Wi4ZdvJkiY8/cakV5HexziaRNk= X-Google-Smtp-Source: ACHHUZ7uYjwK0LlEOlSsD0tHabtZUW+f31t2nJZASWhMK5V5HmzdsVKNmt8iZo6KsmAxmNfh0Zz5vA== X-Received: by 2002:a5d:670f:0:b0:306:3817:4a80 with SMTP id o15-20020a5d670f000000b0030638174a80mr2968518wru.0.1685026502084; Thu, 25 May 2023 07:55: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:55:01 -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 v2 10/13] leds: trigger: netdev: init mode if hw control already active Date: Thu, 25 May 2023 16:53:58 +0200 Message-Id: <20230525145401.27007-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org On netdev trigger activation, hw control may be already active by default. If this is the case and a device is actually provided by hw_control_get_device(), init the already active mode and set the bool to hw_control bool to true to reflect the already set mode in the trigger_data. Co-developed-by: Andrew Lunn Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 5b59441fc415..b0cab2b84ce2 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -452,6 +452,8 @@ static void netdev_trig_work(struct work_struct *work) static int netdev_trig_activate(struct led_classdev *led_cdev) { struct led_netdev_data *trigger_data; + unsigned long mode; + struct device *dev; int rc; trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); @@ -473,6 +475,21 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); trigger_data->last_activity = 0; + /* Check if hw control is active by default on the LED. + * Init already enabled mode in hw control. + */ + if (supports_hw_control(led_cdev) && + !led_cdev->hw_control_get(led_cdev, &mode)) { + dev = led_cdev->hw_control_get_device(led_cdev); + if (dev) { + const char *name = dev_name(dev); + + set_device_name(trigger_data, name, strlen(name)); + trigger_data->hw_control = true; + trigger_data->mode = mode; + } + } + led_set_trigger_data(led_cdev, trigger_data); rc = register_netdevice_notifier(&trigger_data->notifier); From patchwork Thu May 25 14:53:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686594 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 11CD7C7EE32 for ; Thu, 25 May 2023 14:55:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241483AbjEYOzi (ORCPT ); Thu, 25 May 2023 10:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241721AbjEYOzX (ORCPT ); Thu, 25 May 2023 10:55:23 -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 6B7F5E4F; Thu, 25 May 2023 07:55:05 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f6042d605dso5344265e9.2; Thu, 25 May 2023 07:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026504; x=1687618504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KxSZPUywOkLEyYIsTb69Uiy6IYUweaN3dPoh9bCN08U=; b=gbDuAeAounTF7FAEjlshh/hIMWkWCmhJabp/xwtY206Lc+GTbH/8lthE+qx+E6b1vz l9kSa4irHdr+JbZCfx+OEWmfBIVcEOYiSeb0nD9M7ti56XPIPyRHtPI0fafvSkRNejS+ CabEkgo4/kvnublJ6Gknq2T4FlfbHBSOTwL/XPWKkT2e/V3O5UXj7RbNliDQ/iZX6TY6 +KqkyBfCLd+MGt7ysR+dnLSmGcu/WHKryBUjtuOrJsHlYc0YsOc6dc13B6ZJoitAioLW x6ZU8l0Mggd1ciZp/u83qepmQco91QdWHYz8E4MsVOzHEMibxmM4l/+2gWvwivlzb9in kGIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026504; x=1687618504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KxSZPUywOkLEyYIsTb69Uiy6IYUweaN3dPoh9bCN08U=; b=h79XPZh7Ub9CsfzvuIaiXKuCedgizzuEcs/brK6tnRUdkyZj0JCfD0+BI5zPVuamvB CcpG06aP8o1SaRsnco6e9wn70ALNbWP8hf2fOJwFjz08krfh/Bf0ls+RwslsRTRAII1+ z3SRDowwfqVK4MlWX9ggWjlIsZGB70ZvV56JCdsKlJgo/iPmye+BW3Eyn/Fefqeqq3CM eOYwN3xYMQo7DL0QXTw7PHCYtuYbc9ywfwI8ZiRU2lJlLJFqyX/yb0LjzgWWAgG485tA EUWDaOnNeFbqhrQt16PVY7mdYPk5PEn1gupsH69PYwLldxFMnrBJ58jt7G4MR+ZoddZb 0wNQ== X-Gm-Message-State: AC+VfDxKHZG/XF9M6Tm2OCVy0TXXAejuenEUoz4cR/iGO0w+3lfv/LeS TiXQcdgYp+YgwWheqxLNuSs= X-Google-Smtp-Source: ACHHUZ77bqRckmaPsw145x7H7sVy/IGAsadgOLDj1wInpboGicuy+OTGdAqe1zsgJN3gJiG4LWwCuA== X-Received: by 2002:a7b:ce94:0:b0:3f4:2492:a91f with SMTP id q20-20020a7bce94000000b003f42492a91fmr2716489wmj.27.1685026503262; Thu, 25 May 2023 07:55: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:55:02 -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 v2 11/13] leds: trigger: netdev: expose netdev trigger modes in linux include Date: Thu, 25 May 2023 16:53:59 +0200 Message-Id: <20230525145401.27007-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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 b0cab2b84ce2..8fbca94edfce 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -54,15 +54,6 @@ struct led_netdev_data { bool hw_control; }; -enum led_trigger_netdev_modes { - TRIGGER_NETDEV_LINK = 0, - TRIGGER_NETDEV_TX, - TRIGGER_NETDEV_RX, - - /* Keep last */ - __TRIGGER_NETDEV_MAX, -}; - static void set_baseline_state(struct led_netdev_data *trigger_data) { int current_brightness; diff --git a/include/linux/leds.h b/include/linux/leds.h index 3268b4e789d6..8af62ff431f0 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -552,6 +552,16 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) #endif /* CONFIG_LEDS_TRIGGERS */ +/* Trigger specific enum */ +enum led_trigger_netdev_modes { + TRIGGER_NETDEV_LINK = 0, + TRIGGER_NETDEV_TX, + TRIGGER_NETDEV_RX, + + /* Keep last */ + __TRIGGER_NETDEV_MAX, +}; + /* Trigger specific functions */ #ifdef CONFIG_LEDS_TRIGGER_DISK void ledtrig_disk_activity(bool write); From patchwork Thu May 25 14:54:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 686595 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 A3BD9C7EE2D for ; Thu, 25 May 2023 14:55:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241727AbjEYOze (ORCPT ); Thu, 25 May 2023 10:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241728AbjEYOzX (ORCPT ); Thu, 25 May 2023 10:55:23 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E1B2E56; Thu, 25 May 2023 07:55:06 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f6cbdf16d2so5450095e9.2; Thu, 25 May 2023 07:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026504; x=1687618504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=GnV/8Q85nSdt4bY7Mc+wPerU54KxDdRii/0bQKKOJsU=; b=CJJdkLdEFc3sFcCBBP5eXRD3ko53nizmQAFNbRTh6kR2lADzlBuH1TkoAuM7dFYGO4 xRdntZkgPOyisaJ5A8celJXUWPeHOJzDr3bfxqHG1+uxtxgxfSQ367ZHparNkg3Fm6Ft op1mbDUBhMqy6hLdjHjRxGgK8kwul+BKkegJQeJ7yVAnXDjQOyCaKTxdqtfok1LIPmYS 8KaXA6wD2kzxmN3YNK+SZXzVuxpl8oUgaoHAyRdcWcfA5eZhDkq8CcDRHaX8qO8dX5zb xNB3aHRkH+wjzXVqWZPsSaXYZB29LECXh0Cmaj9tRXrFydb4epoYPEV1c2moDaqMdmKW IXOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026504; x=1687618504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GnV/8Q85nSdt4bY7Mc+wPerU54KxDdRii/0bQKKOJsU=; b=CDacvTULdpa0/7aYXEx09xKoN3B0pEBcrQghRjCNgt7HV7wmJhM7Hm0Jg/1EY3wSRl Q8EO80/kLlryRRf/BfPIljRyXw9nW7TKSKcYukGq6jqgPu/KEWrQQYedjvsV/F/np7US 40+aaKgMW9EwZRVJFFcB/lrwoOP08wgG3kdBVGP0TickhUGQTUN4qhQ0BWSd005pn+9I +py7HNFsDt2KcAfLyAi0LtwS8nWy7oK/kSFETo72newjJMKKm2/4kTihJ6QNagS0hvxy 4s960YRZhhVnFZRt1FE5rj9GL9/XKCOWuYkrMEELuBfbld80Gtg01dQpZVtkEH61yHic UqBg== X-Gm-Message-State: AC+VfDzgCNJ79EBgshoMpQ/wfews8jHwQluGl7DlimbDGLj6oWZZirkw RUaz7cod4YRmcas9CAqRM+8= X-Google-Smtp-Source: ACHHUZ4Ir5r2GwXXw9BaAK5dGsqpB8TzEMc3VcyElXhA6TrqcHCLFr4J8+NJEORTC6sWxyYSC+ebSw== X-Received: by 2002:a7b:ca4e:0:b0:3f4:2452:966a with SMTP id m14-20020a7bca4e000000b003f42452966amr2590742wml.27.1685026504461; Thu, 25 May 2023 07:55: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:55:04 -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 v2 12/13] net: dsa: qca8k: implement hw_control ops Date: Thu, 25 May 2023 16:54:00 +0200 Message-Id: <20230525145401.27007-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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 | 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 Thu May 25 14:54:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 685763 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 100AEC7EE2F for ; Thu, 25 May 2023 14:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241724AbjEYOzf (ORCPT ); Thu, 25 May 2023 10:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241730AbjEYOzX (ORCPT ); Thu, 25 May 2023 10:55:23 -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 9AF68E5B; Thu, 25 May 2023 07:55:07 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30abe551605so571687f8f.0; Thu, 25 May 2023 07:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685026506; x=1687618506; 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=ATW5FjSkc8+LeJen8N96L64Cv/XuM3/+5piHXR5L9DCEwvhve894Mj3u9Lq4qXpl/R Escdv7P9zeYiO0rcIcXpExtAXBYESfM5e4Nrn8bVIfkLBX4A9EAfeP1gfWR1qnxW70jz uVpJeJ/eT05fcOzj2TYh3g77krIItZfH1omqVZy84vdbA9YDOPsdcUlwpYSpx/G5qZpE LHKrB3Sc+sogLi69zxFail268I2eanBEQLm6yf3/4yVicFoYFnLcXsFqKiOQFwfoS1pF ZskHcC6tob4Cn9xsAsFVDSepvUMDBB+X4ocpU27Vf+d7c4tEPDXO1KhzRG7NxgKR3Scb VMBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685026506; x=1687618506; 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=Yjud0isSa43NSAnxfdi2Csdz2XfUT4o6nMmmrdQwaoNG/ZlxzyEnrcPat4ngw4E5V1 OT0s2bmx7SXykaMgFgM6UPP0tEeaA7XEsVIxULSLxoHC+r12C9jq3bIkguwDK/Ej5PZe G7lekALOtxpDHdwnjGsRAPejx3495jK7A0ljk37dZsmwUf4JNul13/ov4qUB/Ek6he3/ Hy4GFDTrESsb6SLjkUpdzR1eCbQIfvNqx6HIwyA/ZZiu8BJvH8yAP+FlwiSaGEw4uYoS h43w0dAOJc94iODSdrAayoC4XSXZYhFFGDYEdy9lS4R1oRu9/FbddKnkqMcwSxKucwHm /J9A== X-Gm-Message-State: AC+VfDwu9D/Bxq19PIf6UV6sBKhrgTh5p2QrB4kIeUDtnTSErxn/4FVD csSpGuEUAjTnKg8HJDqhXlg= X-Google-Smtp-Source: ACHHUZ58P0U9MxDchr+fThvUXgeeJk51K21NM20v427978A+OBHbHJ9eKQ3aZ9NHaULcDORs4dHUYQ== X-Received: by 2002:a5d:550e:0:b0:30a:8999:3b9 with SMTP id b14-20020a5d550e000000b0030a899903b9mr2375180wrv.28.1685026505540; Thu, 25 May 2023 07:55: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 t11-20020a5d49cb000000b0030732d6e104sm2048043wrs.105.2023.05.25.07.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 May 2023 07:55:05 -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 v2 13/13] net: dsa: qca8k: add op to get ports netdev Date: Thu, 25 May 2023 16:54:01 +0200 Message-Id: <20230525145401.27007-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230525145401.27007-1-ansuelsmth@gmail.com> References: <20230525145401.27007-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;