From patchwork Thu Feb 16 01:32:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654700 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 DA96FC636CC for ; Thu, 16 Feb 2023 01:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbjBPBgX (ORCPT ); Wed, 15 Feb 2023 20:36:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbjBPBgV (ORCPT ); Wed, 15 Feb 2023 20:36:21 -0500 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 F2F5642BE6; Wed, 15 Feb 2023 17:36:18 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id f47-20020a05600c492f00b003dc584a7b7eso3020841wmp.3; Wed, 15 Feb 2023 17:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MJbS4F2GHWn7NP0EYVJ0SuPaeB9gdcFW3nGUJZbjc3E=; b=CP0p05RaTpaY5SOGOF1sthHmNEY5jhqHm79driE5Tau6RpUMwK+Kl2ibY2elFPlDV6 TXljlQUsX2Ail0Wk42tQMVIcFEQC/j9cmJw9E8ixcjkcW5wSyY7V5YhAuUNUosWdPTSX B9COUUAbW9KRljLtm4+7juGH4zDeO3DbtBkYP7WjiFETqzFdgA+FgjgzDB9rxlnJd9Kt 49cvn9mI0PfhM3utS8q2oCDyES1hkLivHA4TE15T0OmWRnNwV9iN06XatT3e/UPFNqZc oVgx50AdAzfWQWcgfzlf3WU7rVxQIQ++8jnI7tlS9cUe0Sm0a2lH8eBsxdDpx2NMjiSm vlQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MJbS4F2GHWn7NP0EYVJ0SuPaeB9gdcFW3nGUJZbjc3E=; b=ZAEuj981OokGoJ/nKOQJq75Zr7+HLUzuxwBo0x7m1YvTtUW9vJGVHyllSlsZto+5F1 EjAYXuBy1J5uLnPtpASzSQgveio8p6uOK0rdeJEtSkMYvz6uDEzcN3L67OolBNZRn96L j7GHnH+cThAujmfs9Qz3mH0b9bh/LRbOWGDm2VkrlO8WFtMppBCLxZu2Vatv/tP3YSJm gcoT7Xe83PbWWeGfMxhuFfv6DH+pynVy+FNJ/GQpzlvLYv4+ID3G05r/t92IkSqtq336 RDDefxW27gJbYPgxiV4P13smtMxCOZi8TLLueIFIXlGo+BcehWkmUlMyf95sZTCKF+Pr Gdig== X-Gm-Message-State: AO0yUKXn0sCHjs2TuqJicqEjgfT2h4/7h1J2y9Fpe3AKkPy6Q/32N7mw M1nP9vR6P6wFsYofzM9YylI= X-Google-Smtp-Source: AK7set/y0ZEHteF/t3HK/blnPFM13dRmf+Lct65DmPlSUv/EbF2y/gkhi2KIUTk/AQ4461AxhAdbog== X-Received: by 2002:a05:600c:16c6:b0:3e2:9b3:3cb4 with SMTP id l6-20020a05600c16c600b003e209b33cb4mr820751wmn.5.1676511377314; Wed, 15 Feb 2023 17:36:17 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:17 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Cc: =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH v8 01/13] leds: add support for hardware driven LEDs Date: Thu, 16 Feb 2023 02:32:18 +0100 Message-Id: <20230216013230.22978-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Some LEDs can be driven by hardware (for example a LED connected to an ethernet PHY or an ethernet switch can be configured to blink on activity on the network, which in software is done by the netdev trigger). To do such offloading, LED driver must support this and a supported trigger must be used. LED driver should declare the correct blink_mode supported and should set the blink_mode parameter to one of LED_BLINK_HW_CONTROLLED or LED_BLINK_SWHW_CONTROLLED. The trigger will check this option and fail to activate if the blink_mode is not supported. By default if a LED driver doesn't declare blink_mode, LED_BLINK_SW_CONTROLLED is assumed. The LED must implement 3 main API: - hw_control_status(): This asks the LED driver if hardware mode is enabled or not. - hw_control_start(): This will simply enable the hardware mode for the LED. - hw_control_stop(): This will simply disable the hardware mode for the LED. It's advised to the driver to put the LED in the old state but this is not enforcerd and putting the LED off is also accepted. With LED_BLINK_HW_CONTROLLED blink_mode hw_control_status/start/stop is optional and any software only trigger will reject activation as the LED supports only hardware mode. An additional config CONFIG_LEDS_HARDWARE_CONTROL is added to add support for LEDs that can be controlled by hardware. Cc: Marek BehĂșn Signed-off-by: Christian Marangi --- Documentation/leds/leds-class.rst | 34 +++++++++++++++++++++++++++ drivers/leds/Kconfig | 11 +++++++++ drivers/leds/led-class.c | 27 +++++++++++++++++++++ drivers/leds/led-triggers.c | 38 ++++++++++++++++++++++++++++++ include/linux/leds.h | 39 ++++++++++++++++++++++++++++++- 5 files changed, 148 insertions(+), 1 deletion(-) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index cd155ead8703..984d73499d83 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -169,6 +169,40 @@ 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 driven by hardware (for example a LED connected to +an ethernet PHY or an ethernet switch can be configured to blink on activity on +the network, which in software is done by the netdev trigger). + +To do such offloading, LED driver must support this and a supported trigger must +be used. + +LED driver should declare the correct blink_mode supported and should set the +blink_mode parameter to one of LED_BLINK_HW_CONTROLLED or LED_BLINK_SWHW_CONTROLLED. +The trigger will check this option and fail to activate if the blink_mode is not +supported. +By default if a LED driver doesn't declare blink_mode, LED_BLINK_SW_CONTROLLED is +assumed. + +The LED must implement 3 main API: + +- hw_control_status(): + This asks the LED driver if hardware mode is enabled + or not. + +- hw_control_start(): + This will simply enable the hardware mode for the LED. + +- hw_control_stop(): + This will simply disable the hardware mode for the LED. + It's advised to the driver to put the LED in the old state + but this is not enforcerd and putting the LED off is also accepted. + +With LED_BLINK_HW_CONTROLLED blink_mode hw_control_status/start/stop is optional +and any software only trigger will reject activation as the LED supports only +hardware mode. Known Issues ============ diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 9dbce09eabac..019b4f344e01 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -49,6 +49,17 @@ config LEDS_BRIGHTNESS_HW_CHANGED See Documentation/ABI/testing/sysfs-class-led for details. +config LEDS_HARDWARE_CONTROL + bool "LED Hardware Control support" + help + This option enabled Hardware control support used by leds that + can be driven in hardware by using supported triggers. + + Hardware blink modes will be exposed by sysfs class in + /sys/class/leds based on the trigger currently active. + + If unsure, say Y. + comment "LED drivers" config LEDS_88PM860X diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index a6b3adcd044a..10408bff8e10 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -166,6 +166,27 @@ static void led_remove_brightness_hw_changed(struct led_classdev *led_cdev) } #endif +#ifdef CONFIG_LEDS_HARDWARE_CONTROL +static int led_classdev_check_blink_hw_mode_functions(struct led_classdev *led_cdev) +{ + int mode = led_cdev->blink_mode; + + if (mode == LED_BLINK_SWHW_CONTROLLED && + (!led_cdev->hw_control_status || + !led_cdev->hw_control_start || + !led_cdev->hw_control_stop)) + return -EINVAL; + + if (mode == LED_BLINK_SW_CONTROLLED && + (led_cdev->hw_control_status || + led_cdev->hw_control_start || + led_cdev->hw_control_stop)) + return -EINVAL; + + return 0; +} +#endif + /** * led_classdev_suspend - suspend an led_classdev. * @led_cdev: the led_classdev to suspend. @@ -466,6 +487,12 @@ int led_classdev_register_ext(struct device *parent, if (ret < 0) return ret; +#ifdef CONFIG_LEDS_HARDWARE_CONTROL + ret = led_classdev_check_blink_hw_mode_functions(led_cdev); + if (ret < 0) + return ret; +#endif + mutex_init(&led_cdev->led_access); mutex_lock(&led_cdev->led_access); led_cdev->dev = device_create_with_groups(leds_class, parent, 0, diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 072491d3e17b..00d9f6b06f5c 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -154,6 +154,38 @@ ssize_t led_trigger_read(struct file *filp, struct kobject *kobj, } EXPORT_SYMBOL_GPL(led_trigger_read); +static bool led_trigger_is_supported(struct led_classdev *led_cdev, + struct led_trigger *trigger) +{ + switch (led_cdev->blink_mode) { + case LED_BLINK_SW_CONTROLLED: + return trigger->supported_blink_modes != LED_TRIGGER_HW_ONLY; + + case LED_BLINK_HW_CONTROLLED: + return trigger->supported_blink_modes != LED_TRIGGER_SW_ONLY; + + case LED_BLINK_SWHW_CONTROLLED: + return true; + } + + return 1; +} + +static void led_trigger_hw_mode_stop(struct led_classdev *led_cdev) +{ + /* check if LED is in HW block mode */ + if (led_cdev->blink_mode == LED_BLINK_SW_CONTROLLED) + return; + + /* + * We can assume these function are always present as + * for LED support hw blink mode they MUST be provided or register + * fail. + */ + if (led_cdev->hw_control_status(led_cdev)) + led_cdev->hw_control_stop(led_cdev); +} + /* Caller must ensure led_cdev->trigger_lock held */ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) { @@ -179,6 +211,8 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) cancel_work_sync(&led_cdev->set_brightness_work); led_stop_software_blink(led_cdev); + /* Disable hardware mode on trigger change if supported */ + led_trigger_hw_mode_stop(led_cdev); if (led_cdev->trigger->deactivate) led_cdev->trigger->deactivate(led_cdev); device_remove_groups(led_cdev->dev, led_cdev->trigger->groups); @@ -188,6 +222,10 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig) led_set_brightness(led_cdev, LED_OFF); } if (trig) { + /* Make sure the trigger support the LED blink mode */ + if (!led_trigger_is_supported(led_cdev, trig)) + return -EINVAL; + spin_lock(&trig->leddev_list_lock); list_add_tail_rcu(&led_cdev->trig_list, &trig->led_cdevs); spin_unlock(&trig->leddev_list_lock); diff --git a/include/linux/leds.h b/include/linux/leds.h index d71201a968b6..5c360fba9ccf 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -88,6 +88,12 @@ struct led_hw_trigger_type { int dummy; }; +enum led_blink_modes { + LED_BLINK_SW_CONTROLLED = 0x0, + LED_BLINK_HW_CONTROLLED, + LED_BLINK_SWHW_CONTROLLED, +}; + struct led_classdev { const char *name; unsigned int brightness; @@ -175,6 +181,24 @@ struct led_classdev { /* LEDs that have private triggers have this set */ struct led_hw_trigger_type *trigger_type; + + /* This report the supported blink_mode. The driver should report the + * correct LED capabilities. + * With this set to LED_BLINK_HW_CONTROLLED, LED is always in offload + * mode and triggers can't be simulated by software. + * If the led is LED_BLINK_HW_CONTROLLED, status/start/stop function + * are optional. + * By default LED_BLINK_SW_CONTROLLED is set as blink_mode. + */ + enum led_blink_modes blink_mode; + /* Ask the LED driver if hardware mode is enabled or not */ + bool (*hw_control_status)(struct led_classdev *led_cdev); + /* Set LED in hardware mode */ + int (*hw_control_start)(struct led_classdev *led_cdev); + /* Disable hardware mode for LED. It's advised to the LED driver to put it to + * the old status but that is not mandatory and also putting it off is accepted. + */ + int (*hw_control_stop)(struct led_classdev *led_cdev); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED @@ -242,7 +266,6 @@ extern struct led_classdev *of_led_get(struct device_node *np, int index); extern void led_put(struct led_classdev *led_cdev); struct led_classdev *__must_check devm_of_led_get(struct device *dev, int index); - /** * led_blink_set - set blinking with software fallback * @led_cdev: the LED to start blinking @@ -377,12 +400,26 @@ static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev) #define TRIG_NAME_MAX 50 +enum led_trigger_blink_supported_modes { + LED_TRIGGER_SW_ONLY = LED_BLINK_SW_CONTROLLED, + LED_TRIGGER_HW_ONLY = LED_BLINK_HW_CONTROLLED, + LED_TRIGGER_SWHW = LED_BLINK_SWHW_CONTROLLED, +}; + struct led_trigger { /* Trigger Properties */ const char *name; int (*activate)(struct led_classdev *led_cdev); void (*deactivate)(struct led_classdev *led_cdev); + /* Declare if the Trigger supports hardware control to + * offload triggers or supports only software control. + * A trigger can also declare support for hardware control + * if its task is to only configure LED blink modes and expose + * them in sysfs. + */ + enum led_trigger_blink_supported_modes supported_blink_modes; + /* LED-private triggers have this set */ struct led_hw_trigger_type *trigger_type; From patchwork Thu Feb 16 01:32:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654302 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 8B4FBC636D4 for ; Thu, 16 Feb 2023 01:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbjBPBgl (ORCPT ); Wed, 15 Feb 2023 20:36:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbjBPBgW (ORCPT ); Wed, 15 Feb 2023 20:36:22 -0500 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 8BB2D442E4; Wed, 15 Feb 2023 17:36:20 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id z13so466043wmp.2; Wed, 15 Feb 2023 17:36:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=2zG2FPF2HCGhFA3A8x50o1BhWQSoAA49i+eyxanDZew=; b=L+bMCtbEgyGO9OyU2gUMYD6oXJIOZh7/f4h4mBtaGKN4V5p3nX1dkt/LWwvA3UXAiu 9ssexsSbHh66qgqPpRpW7AliysJyU6+HeNaMC+V3EXNUYjOOCVxJhtSwcW/1KH2cqq9u WWHedEj/Up3Mfr+BpeFGh4pWAyRt1cpIV4IFWee08JGEPgIaKHoE1geBBLZWNmy4Uaqu bfQQ87+I4yzW4/77PS0OTFtLlzwdPKjJt+7pKxt2LSUy7enTUNSxScX+Wr8RvtjP+ayB Lo/4u0141+BEJKKVj5zSRl1ana87BfX4Of0r2Z238Ar2nZuD9dmFgn+5c9rupxiEV6Rs hoKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=2zG2FPF2HCGhFA3A8x50o1BhWQSoAA49i+eyxanDZew=; b=S+VE8lFoDYjWAqkDDy5yRALtrm/AVtPmWU3Daz5dNLOqnkPLZSmu7p/cXvOcS4Wbgn nLvsnTvPekwxa7QyTzp+1qDt5/ogxr1yOoJBky2hhUpojOPu3OSVuTMZJnNjhUBgLmvT 2WD5c+xxnTK/Wf0XQrpKGAEp3axAgINMuG6elKKTl4c+QjhZ2Xbvf4LzuTZrJ0I5RX+r /mM9UDJfJuPVo5ASWJH8iSuqRPxK2iYcyqa/Q0RWd6pmNdrWPcwbag5rWkKUVurtImhB zePwklDSK2F98JDLu1BhvenGCrDEnrf8VqZHt51pdYZJxOhCUMYoVsl7bp5bwv9gihrL AYTA== X-Gm-Message-State: AO0yUKUHfEo2Qsf+T3sVPPqih4Bc8qYBuTM9lN/SxSNJ36V73YCtFc0m VqxUQlgB0KLjlgSM6qjZ3bw= X-Google-Smtp-Source: AK7set+4vZgcDlLPQ/VEq4HwYKKoG4VxRFS+f3SFohNr0eUk2UIf/RzUUwbPdSqVCp7zOFnS6KiHFw== X-Received: by 2002:a05:600c:492a:b0:3dc:42d2:aee4 with SMTP id f42-20020a05600c492a00b003dc42d2aee4mr3447006wmp.25.1676511378802; Wed, 15 Feb 2023 17:36:18 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:18 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 02/13] leds: add function to configure hardware controlled LED Date: Thu, 16 Feb 2023 02:32:19 +0100 Message-Id: <20230216013230.22978-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add hw_control_configure helper to configure how the LED should work in hardware mode. The function require to support the particular trigger and will use the passed flag to elaborate the data and apply the correct configuration. This function will then be used by the trigger to request and update hardware configuration. Signed-off-by: Christian Marangi --- Documentation/leds/leds-class.rst | 60 +++++++++++++++++++++++++++++++ include/linux/leds.h | 43 ++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/Documentation/leds/leds-class.rst b/Documentation/leds/leds-class.rst index 984d73499d83..8a23589e9fca 100644 --- a/Documentation/leds/leds-class.rst +++ b/Documentation/leds/leds-class.rst @@ -200,10 +200,70 @@ The LED must implement 3 main API: It's advised to the driver to put the LED in the old state but this is not enforcerd and putting the LED off is also accepted. +- hw_control_configure(): + This will be used to configure the various blink modes LED support + in hardware mode. + With LED_BLINK_HW_CONTROLLED blink_mode hw_control_status/start/stop is optional and any software only trigger will reject activation as the LED supports only hardware mode. +Where a trigger has support for hardware controlled blink modes, +hw_control_configure() will be used to check whether a particular blink mode +is supported and configure the blink mode using various specific command. + +hw_control_configure() takes 3 arguments: + +- struct led_classdev *led_cdev + +- unsigned long flag: + This can be used for multiple purpose based on passed command + in the 3rd argument of this function. + It may be NULL if the 3rd argument doesn't require them. + + The unsigned long flag is specific to the trigger and its meaning + change across different triggers. + For this exact reason LED driver needs to declare explicit support + for the trigger supporting hardware blink mode. + The driver should return -EOPNOTSUPP if asked to enter in hardware + blink mode with an unsupported trigger. + + The LED driver may also report -EOPNOTSUPP if the requested flag + are rejected and can't be handled in hw blink mode by the LED. + + Flag can both be a single blink mode or a set of multiple blink + mode. LED driver must be able to handle both cases. + +- enum led_blink_hw_cmd cmd: + This is used to request to the LED driver various operation. + + They may return -EOPNOTSUPP or -EINVAL based on the provided flags. + +hw_control_configure() supports the following cmd: + +- LED_BLINK_HW_ENABLE: + enable the blink mode requested in flag. Returns 0 or a negative + error. + +- LED_BLINK_HW_DISABLE: + disable the blink mode requested in flag. Returns 0 or a negative + error. + +- LED_BLINK_HW_STATUS: + read the status of the blink mode requested in flag. Return a mask + of the enabled blink mode requested in flag or a negative error. + +- LED_BLINK_HW_SUPPORTED: + ask the LED driver if the blink mode requested in flag is supported. + Return 1 if supported or a negative error in any other case. + +- LED_BLINK_HW_RESET: + reset any blink mode currently active. Value in flag are ignored. + Return 0 or a negative error. + + LED driver can set the blink mode to a default state or keep everything + disabled. + Known Issues ============ diff --git a/include/linux/leds.h b/include/linux/leds.h index 5c360fba9ccf..c25558ca5f85 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -94,6 +94,14 @@ enum led_blink_modes { LED_BLINK_SWHW_CONTROLLED, }; +enum led_blink_hw_cmd { + LED_BLINK_HW_ENABLE, /* Enable the hardware blink mode */ + LED_BLINK_HW_DISABLE, /* Disable the hardware blink mode */ + LED_BLINK_HW_STATUS, /* Read the status of the hardware blink mode */ + LED_BLINK_HW_SUPPORTED, /* Ask the driver if the hardware blink mode is supported */ + LED_BLINK_HW_RESET, /* Reset any hardware blink active */ +}; + struct led_classdev { const char *name; unsigned int brightness; @@ -199,6 +207,17 @@ struct led_classdev { * the old status but that is not mandatory and also putting it off is accepted. */ int (*hw_control_stop)(struct led_classdev *led_cdev); + /* This will be used to configure the various blink modes LED support in hardware + * mode. + * The LED driver require to support the active trigger and will elaborate the + * unsigned long flag and do the operation based on the provided cmd. + * Current operation are enable,disable,supported and status. + * A trigger will use this to enable or disable the asked blink mode, check the + * status of the blink mode or ask if the blink mode can run in hardware mode. + */ + int (*hw_control_configure)(struct led_classdev *led_cdev, + unsigned long flag, + enum led_blink_hw_cmd cmd); #endif #ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED @@ -473,6 +492,30 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) return led_cdev->trigger_data; } +#ifdef CONFIG_LEDS_HARDWARE_CONTROL +static inline bool led_trigger_blink_mode_is_supported(struct led_classdev *led_cdev, + unsigned long flag) +{ + int ret; + + /* Sanity check: make sure led support hw mode */ + if (led_cdev->blink_mode == LED_BLINK_SW_CONTROLLED) + return false; + + ret = led_cdev->hw_control_configure(led_cdev, flag, LED_BLINK_HW_SUPPORTED); + if (ret > 0) + return true; + + return false; +} +#else +static inline bool led_trigger_blink_mode_is_supported(struct led_classdev *led_cdev, + unsigned long flag) +{ + return false; +} +#endif + /** * led_trigger_rename_static - rename a trigger * @name: the new trigger name From patchwork Thu Feb 16 01:32:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654699 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 A1703C64ED6 for ; Thu, 16 Feb 2023 01:36:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbjBPBgm (ORCPT ); Wed, 15 Feb 2023 20:36:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjBPBgW (ORCPT ); Wed, 15 Feb 2023 20:36:22 -0500 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 BEC8942BE6; Wed, 15 Feb 2023 17:36:21 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id az4-20020a05600c600400b003dff767a1f1so452729wmb.2; Wed, 15 Feb 2023 17:36:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=ZLUjxnO2oij4OhBp9M0WGmuraYdVdBunDA6AnJELD5s=; b=YhbIoKaoSAQQg+5Y1FTs50x5i0/GhDoFVuxeGe9pdG5z9UuJdWe+98XHApZTFwBmfY n2FwhAcu8/WWmggdh1s5bzcv2J1YRr1C/iB8WwTEa6bSNhFQaclVEjRMr7o5n6lsWkI+ Q/VhWlNUMxJxih85NyDL/7MEi5trwz1xtJZ0WdtiX4pOe6UKUxYJ8DLR3nWGBQCxdKwC 1iYEeHb9l2U5kJrjIPJogdSahjVYgbo2ccMjQjlCpSqWM9KNy9gkEDkU0aZcl+dR/jPS yUYxWXN/+Krud81acrVRqYjJFO8g+RuKBK2MGeCMPwqCf6KvsGShcGkyO/hQaUssgVvy Tu1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ZLUjxnO2oij4OhBp9M0WGmuraYdVdBunDA6AnJELD5s=; b=CUvUhUkmF/xlQnebZtl1jEbM22xxa3/5DCIA9AdbFHg1mRE+XUcEPpEjqAQU5aUN7Q 4huoFi/60+qmev00RUYf1lnIWXuX5dPkFjkO3wBwQrhGuK8kSIaQdzIomrZ2lID8Reb+ ekZd6QSWL4r6GqkbTm0fpyN95KrimRu6b69b5VSUfBJ1nWpmEEy+HfEI2w7Gj7VSftdE GPyDy7u0IfYYPJxXre89plOM6HoZ5d++rJ5yxpk2Q7MZfw8Q08E0jcjnky/cwaaz1epz ndROuITANig87Bogs0uZ3KRRr1RuVCrc1kaR3F9MmM23jogNezVW09AgyDIoDTm+O9hY 3Hfg== X-Gm-Message-State: AO0yUKWsGJCsSripW8+J2eADu1w0V+ja0g9sE8UyzWN0rxyLqvZVHuRC 8U1cadBt4j5DBbtuwmThauk= X-Google-Smtp-Source: AK7set/4Fjk6MqFb6N4r+YOX2UAjCiFVDG+2NZKe2UiYikgb9571oK4N13I7/2PNQuJ52M+YqqaUlw== X-Received: by 2002:a05:600c:816:b0:3de:1d31:1043 with SMTP id k22-20020a05600c081600b003de1d311043mr3573991wmp.21.1676511380197; Wed, 15 Feb 2023 17:36:20 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:19 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 03/13] leds: trigger: netdev: drop NETDEV_LED_MODE_LINKUP from mode Date: Thu, 16 Feb 2023 02:32:20 +0100 Message-Id: <20230216013230.22978-4-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Drop NETDEV_LED_MODE_LINKUP from mode list and convert to a simple bool that will be true or false based on the carrier link. No functional change intended. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index d5e774d83021..66a81cc9b64d 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -50,10 +50,10 @@ struct led_netdev_data { unsigned int last_activity; unsigned long mode; + bool carrier_link_up; #define NETDEV_LED_LINK 0 #define NETDEV_LED_TX 1 #define NETDEV_LED_RX 2 -#define NETDEV_LED_MODE_LINKUP 3 }; enum netdev_led_attr { @@ -73,9 +73,9 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) if (!led_cdev->blink_brightness) led_cdev->blink_brightness = led_cdev->max_brightness; - if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode)) + if (!trigger_data->carrier_link_up) { led_set_brightness(led_cdev, LED_OFF); - else { + } else { if (test_bit(NETDEV_LED_LINK, &trigger_data->mode)) led_set_brightness(led_cdev, led_cdev->blink_brightness); @@ -131,10 +131,9 @@ static ssize_t device_name_store(struct device *dev, trigger_data->net_dev = dev_get_by_name(&init_net, trigger_data->device_name); - clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = false; if (trigger_data->net_dev != NULL) - if (netif_carrier_ok(trigger_data->net_dev)) - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev); trigger_data->last_activity = 0; @@ -315,7 +314,7 @@ static int netdev_trig_notify(struct notifier_block *nb, spin_lock_bh(&trigger_data->lock); - clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = false; switch (evt) { case NETDEV_CHANGENAME: case NETDEV_REGISTER: @@ -330,8 +329,7 @@ static int netdev_trig_notify(struct notifier_block *nb, break; case NETDEV_UP: case NETDEV_CHANGE: - if (netif_carrier_ok(dev)) - set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); + trigger_data->carrier_link_up = netif_carrier_ok(dev); break; } From patchwork Thu Feb 16 01:32:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654301 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 BB77DC678D5 for ; Thu, 16 Feb 2023 01:36:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbjBPBgn (ORCPT ); Wed, 15 Feb 2023 20:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbjBPBgY (ORCPT ); Wed, 15 Feb 2023 20:36:24 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F4645F59; Wed, 15 Feb 2023 17:36:22 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m16-20020a05600c3b1000b003dc4050c94aso433103wms.4; Wed, 15 Feb 2023 17:36:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=VsNctLKC2ZYWHMMx8Al2bXYZJ6p8YrBC+LD3cRvN9GI=; b=nENG8ceOVhAZUJewR/tmeUy+LmnLxGY1L0BllbpKxbI+XjlsmBil7tteYMAfW9r2Ux vgKKyX+j8PUNcvKa3F/CiKtdgHPahjhTRH86R3X3QWPxRg8w5tVOJRpeehhBd+PB1xi6 B2kCIG4NutlMmW7s4jpvbAJAoAF035fYX18TsmGHPeEwZPjDD4pq5V7ZRZCCgWwLZZIJ 3YDXbgQLabZCeEJK2z53Z012EmN8WhqqNYE+buIzgrVkYVN1MQj9oPQOE+N9TQzxY989 4KCD/D6zsdzEWhW6DeKFAuzMheUIQuS9In/W8fFm+kNvpl7bHrS2u9k8KEPpaODxycRk TfOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=VsNctLKC2ZYWHMMx8Al2bXYZJ6p8YrBC+LD3cRvN9GI=; b=w63Dlk0rw+hybqCrXbJmZk3zGPYdpbnk2ihLnV453SWZaA18dVQNKU9kPWRD3Q/6Mc HakUWynXtI9XJmKiJobnE9zBTbtbMg3ELjrL+7VByx5zG317NeUIMz/Fg1esg4OSFCaZ dkL4US7i5n7H8qiL+1GmmbEgPedvl4WgY/1Xdg6dZfv+TzqaaDAghuJq2avyDD5OcQQc jDQgt0Cl4xUkSBGFdpb8yVREbpHkvJzWZdKSZfaAuDgBfy0fJvVq/ZJuU8ypHl4m+bUC WuFeNCxUJBvGaYhJ3hfSkyqDFw7b4bLADD3VxtFbiqk1GVkemlfFpkQGv73ihEathz7Y ZftA== X-Gm-Message-State: AO0yUKXSjT/KIZYrfUvDqrBgH8wEiL5xvny4xx1v9KXeK3KtRUhd9Q/E 5aEa5tUgFJavAmTGw5iqr8I= X-Google-Smtp-Source: AK7set8hToIouIzfFiZh790fyd4lbNu7ntR/g/k6PTd+0LfSxVXOkYTXysoqkSTZwCIGcpeuNyMi4Q== X-Received: by 2002:a05:600c:3317:b0:3dc:4318:d00d with SMTP id q23-20020a05600c331700b003dc4318d00dmr3643486wmp.11.1676511381604; Wed, 15 Feb 2023 17:36:21 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:21 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 04/13] leds: trigger: netdev: rename and expose NETDEV trigger enum modes Date: Thu, 16 Feb 2023 02:32:21 +0100 Message-Id: <20230216013230.22978-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Rename NETDEV trigger enum modes to a more symbolic name and move them in leds.h to make them accessible by any user. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 53 +++++++++------------------ include/linux/leds.h | 7 ++++ 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 66a81cc9b64d..6872da08676b 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -51,15 +51,6 @@ struct led_netdev_data { unsigned long mode; bool carrier_link_up; -#define NETDEV_LED_LINK 0 -#define NETDEV_LED_TX 1 -#define NETDEV_LED_RX 2 -}; - -enum netdev_led_attr { - NETDEV_ATTR_LINK, - NETDEV_ATTR_TX, - NETDEV_ATTR_RX }; static void set_baseline_state(struct led_netdev_data *trigger_data) @@ -76,7 +67,7 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) if (!trigger_data->carrier_link_up) { led_set_brightness(led_cdev, LED_OFF); } else { - if (test_bit(NETDEV_LED_LINK, &trigger_data->mode)) + if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode)) led_set_brightness(led_cdev, led_cdev->blink_brightness); else @@ -85,8 +76,8 @@ static void set_baseline_state(struct led_netdev_data *trigger_data) /* If we are looking for RX/TX start periodically * checking stats */ - if (test_bit(NETDEV_LED_TX, &trigger_data->mode) || - test_bit(NETDEV_LED_RX, &trigger_data->mode)) + if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) || + test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode)) schedule_delayed_work(&trigger_data->work, 0); } } @@ -146,20 +137,16 @@ static ssize_t device_name_store(struct device *dev, static DEVICE_ATTR_RW(device_name); static ssize_t netdev_led_attr_show(struct device *dev, char *buf, - enum netdev_led_attr attr) + enum led_trigger_netdev_modes attr) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); int bit; switch (attr) { - case NETDEV_ATTR_LINK: - bit = NETDEV_LED_LINK; - break; - case NETDEV_ATTR_TX: - bit = NETDEV_LED_TX; - break; - case NETDEV_ATTR_RX: - bit = NETDEV_LED_RX; + case TRIGGER_NETDEV_LINK: + case TRIGGER_NETDEV_TX: + case TRIGGER_NETDEV_RX: + bit = attr; break; default: return -EINVAL; @@ -169,7 +156,7 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf, } static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, - size_t size, enum netdev_led_attr attr) + size_t size, enum led_trigger_netdev_modes attr) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); unsigned long state; @@ -181,14 +168,10 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, return ret; switch (attr) { - case NETDEV_ATTR_LINK: - bit = NETDEV_LED_LINK; - break; - case NETDEV_ATTR_TX: - bit = NETDEV_LED_TX; - break; - case NETDEV_ATTR_RX: - bit = NETDEV_LED_RX; + case TRIGGER_NETDEV_LINK: + case TRIGGER_NETDEV_TX: + case TRIGGER_NETDEV_RX: + bit = attr; break; default: return -EINVAL; @@ -358,21 +341,21 @@ static void netdev_trig_work(struct work_struct *work) } /* If we are not looking for RX/TX then return */ - if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) && - !test_bit(NETDEV_LED_RX, &trigger_data->mode)) + if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) && + !test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode)) return; dev_stats = dev_get_stats(trigger_data->net_dev, &temp); new_activity = - (test_bit(NETDEV_LED_TX, &trigger_data->mode) ? + (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ? dev_stats->tx_packets : 0) + - (test_bit(NETDEV_LED_RX, &trigger_data->mode) ? + (test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) ? dev_stats->rx_packets : 0); if (trigger_data->last_activity != new_activity) { led_stop_software_blink(trigger_data->led_cdev); - invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode); + invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode); interval = jiffies_to_msecs( atomic_read(&trigger_data->interval)); /* base state is ON (link present) */ diff --git a/include/linux/leds.h b/include/linux/leds.h index c25558ca5f85..a31f158e5351 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -571,6 +571,13 @@ 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 = 1, + TRIGGER_NETDEV_TX, + TRIGGER_NETDEV_RX, +}; + /* Trigger specific functions */ #ifdef CONFIG_LEDS_TRIGGER_DISK void ledtrig_disk_activity(bool write); From patchwork Thu Feb 16 01:32:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654299 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 AC560C64ED9 for ; Thu, 16 Feb 2023 01:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbjBPBgw (ORCPT ); Wed, 15 Feb 2023 20:36:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjBPBgl (ORCPT ); Wed, 15 Feb 2023 20:36:41 -0500 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 B77AA46086; Wed, 15 Feb 2023 17:36:24 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id hg24-20020a05600c539800b003e1f5f2a29cso3002644wmb.4; Wed, 15 Feb 2023 17:36:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=nxNF0bdXrLOqlvz3FHeM2ekp+a2C9OgjFl1GP6LPucY=; b=ZSdgv0lhnvn0Amu7Rj460scpIcG3vg0ZFEjEJsfdlvmnFlOb3TXBTAY46uRgeyaWn7 ChxyOx24SHi2HVI/lEOmj8XjDYuVGu+j4F1a02BdpdGfnJVVhG3qzTwq6g9ZSh6ulTby swZqWtCzDvUHMOk/yNLoIZbBrjlmuxd8Cmp38Au2mcG2mUjajVlBmBwAHRiKezVhpPWs 17+XP5vwvN0gbutGgE25IFVCAYHCaK4AI2miBQUhkgQAnr242NZTzGPYv7OYFEKavlv/ 9wD+GXDIZPMU3SnBUmasPE4/nSzUK0kQaEeEcDYNGHwBMEBPvciNeRR9xRyjcUXmZSsF wbEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=nxNF0bdXrLOqlvz3FHeM2ekp+a2C9OgjFl1GP6LPucY=; b=yqXdEdov0KDOlL0eazVXcgf8weUs1bKn7pp540p5U5VtQfML+2P+PG4IvWEQRKqxb/ U39hqvAVykf4VMKMmObHnStrA9v0W6IptuPeK+ZAyCnwjcWpTEB1g+oUHz/LGdGwbddX J9km624CLR1WfgECst251+Pv5B+u/PkP3DVmfNTV83IBKXXh2fbw53Nek7ycUJZrIXxo N0ylU5IxLFUdbW0qBwf4UlYx1VF5/avWOMt79+TvuVk1Hvbv4e7dnbzuclQ1hsehqcIZ CQUPr3nCLLUt27GmaPgjDpBqAx1ov6v5p/Z8+oytyij8el/DOQ1ahkvCYVUcEH9aWA8+ Tchw== X-Gm-Message-State: AO0yUKUdtCtxJA1wdLngFR6X8IT1aLM9luJj8iaSSWpnPZdHjRQrnZFB GbY2rjVzfJ9pd1P3amaYPhI= X-Google-Smtp-Source: AK7set+Lhqbx2SxRTVH5CpuI73WwZU+6n02S7W6HEFNYdAGo5K2JdhTcugqhNAdnYhaCI1Cb9QQzOA== X-Received: by 2002:a05:600c:3094:b0:3df:f85a:4724 with SMTP id g20-20020a05600c309400b003dff85a4724mr3216285wmn.39.1676511383008; Wed, 15 Feb 2023 17:36:23 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:22 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 05/13] leds: trigger: netdev: convert device attr to macro Date: Thu, 16 Feb 2023 02:32:22 +0100 Message-Id: <20230216013230.22978-6-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Convert link tx and rx device attr to a common macro to reduce common code and in preparation for additional attr. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 57 ++++++++------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 6872da08676b..dd63cadb896e 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -189,47 +189,22 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, return size; } -static ssize_t link_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK); -} - -static ssize_t link_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK); -} - -static DEVICE_ATTR_RW(link); - -static ssize_t tx_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX); -} - -static ssize_t tx_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX); -} - -static DEVICE_ATTR_RW(tx); - -static ssize_t rx_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX); -} - -static ssize_t rx_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX); -} - -static DEVICE_ATTR_RW(rx); +#define DEFINE_NETDEV_TRIGGER(trigger_name, trigger) \ + static ssize_t trigger_name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ + { \ + return netdev_led_attr_show(dev, buf, trigger); \ + } \ + static ssize_t trigger_name##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, size_t size) \ + { \ + return netdev_led_attr_store(dev, buf, size, trigger); \ + } \ + static DEVICE_ATTR_RW(trigger_name) + +DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK); +DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX); +DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX); static ssize_t interval_show(struct device *dev, struct device_attribute *attr, char *buf) From patchwork Thu Feb 16 01:32:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654697 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 10AC4C636CC for ; Thu, 16 Feb 2023 01:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229625AbjBPBgv (ORCPT ); Wed, 15 Feb 2023 20:36:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229768AbjBPBgm (ORCPT ); Wed, 15 Feb 2023 20:36:42 -0500 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 52ADB457FF; Wed, 15 Feb 2023 17:36:25 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id z13so466135wmp.2; Wed, 15 Feb 2023 17:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=iuGXaXqILaNTsxW+v3RUsYfQ+Yu3bUhjcC1ERhfRoBQ=; b=YpnJV1ZjewGu/0d+fLOxiXIUGio7nvM8OhLDpnzU6WTtK3owjw0dBtsFHvvJU7DF7Q CH51XQoVmZCbVctPGlli+ZuCvQCTltP6D8TcUL5CP9BcM1ZKWS4RF5N9fsMYyCWr85WG QxvSzbcMJkvJ+/gyiLX/KACm7o81ALXsHijpD/h3iKSIigSkU+X2QepFLUiebHJK3doN Ll5VfzFLH9iLzh43+T/lga/Qga6qWr6kG3daffHZOSoULx/oE2M45RYb82eYUI0ua7T8 W6bZcYhTKLbcJj+X82wXTJZfy8keca2Yu/JtqgFMZ0F9VCyn7pvUv6h7GSCa2dkli5np nnUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iuGXaXqILaNTsxW+v3RUsYfQ+Yu3bUhjcC1ERhfRoBQ=; b=Snt3r5DQNIEAi7v7Ed/i2JqdMZdAqJKYJfM84RObHCHgoV96sqYZPXApkuHeVtLkYs xXGWFDtQLznE8sD0OjWVq6Cwu97bVcQNJo5IT+UZ5q1u9BqX+FfINxMli9GbLGKzQ6pe fnQ/Wb6pnNvxzVeZjULIU/dr+hq7W9ReRCOHSu4wQrbl6ZAzj16iH/JwXw/6SbqO5WIW kaB7ZRtx+Ztb24+4ZFblqmCKomYUlaJs+mVTh46PgSdhkx0lQmwP1RWkZEWOb+Q+iFC0 IDnJ6OK5dOwClao4mfpJKd1SC2seeW2aO21UEZzmqpGsClLRNyVwGlUejR+1tfxZd5WS XXJg== X-Gm-Message-State: AO0yUKWPiQES8dcxuhUBMwwHuKDI5L9qBdWghjhhFhXK9Hm+o0Zt7xvS Jd0a5Ufw1ssfF9zbJLa7tHI= X-Google-Smtp-Source: AK7set/02v3/QImoPI+x2vebAqwY8KXEa7qrCPdACbl1ohohpA6XMKM1LbaKPtO9XeofPOko95IfWQ== X-Received: by 2002:a05:600c:3509:b0:3df:a04a:1a7 with SMTP id h9-20020a05600c350900b003dfa04a01a7mr3277838wmq.22.1676511384528; Wed, 15 Feb 2023 17:36:24 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:24 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 06/13] leds: trigger: netdev: add hardware control support Date: Thu, 16 Feb 2023 02:32:23 +0100 Message-Id: <20230216013230.22978-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add hardware control support for the Netdev trigger. The trigger on config change will check if the requested trigger can set to blink mode using LED hardware mode and if every blink mode is supported, the trigger will enable hardware mode with the requested configuration. If there is at least one trigger that is not supported and can't run in hardware mode, then software mode will be used instead. A validation is done on every value change and on fail the old value is restored and -EINVAL is returned. In HW blink mode interval setting is not supported as it's handled internally. To use HW blink mode, dev MUST be empty. If set, SW blink mode is forced. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 175 ++++++++++++++++++++++++-- 1 file changed, 165 insertions(+), 10 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index dd63cadb896e..d85be325e492 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -28,7 +28,9 @@ * Configurable sysfs attributes: * * device_name - network device name to monitor + * (not supported in hw mode) * interval - duration of LED blink, in milliseconds + * (not supported in hw mode) * link - LED's normal state reflects whether the link is up * (has carrier) or not * tx - LED blinks on transmitted data @@ -37,6 +39,7 @@ */ struct led_netdev_data { + enum led_blink_modes blink_mode; spinlock_t lock; struct delayed_work work; @@ -53,11 +56,111 @@ struct led_netdev_data { bool carrier_link_up; }; +struct netdev_led_attr_detail { + char *name; + bool hardware_only; + enum led_trigger_netdev_modes bit; +}; + +static struct netdev_led_attr_detail attr_details[] = { + { .name = "link", .bit = TRIGGER_NETDEV_LINK}, + { .name = "tx", .bit = TRIGGER_NETDEV_TX}, + { .name = "rx", .bit = TRIGGER_NETDEV_RX}, +}; + +static bool validate_baseline_state(struct led_netdev_data *trigger_data) +{ + struct led_classdev *led_cdev = trigger_data->led_cdev; + unsigned long hw_blink_modes = 0, sw_blink_modes = 0; + struct netdev_led_attr_detail *detail; + bool force_sw = false; + int i; + + /* Check if we need to force sw mode for some feature */ + if (trigger_data->net_dev) + force_sw = true; + + /* Hardware only controlled LED can't run in sw mode */ + if (force_sw && led_cdev->blink_mode == LED_BLINK_HW_CONTROLLED) + return false; + + /* Check each attr and make sure they are all supported */ + for (i = 0; i < ARRAY_SIZE(attr_details); i++) { + detail = &attr_details[i]; + + /* Mode not active, skip */ + if (!test_bit(detail->bit, &trigger_data->mode)) + continue; + + /* Hardware only mode enabled on software controlled LED */ + if ((force_sw || led_cdev->blink_mode == LED_BLINK_SW_CONTROLLED) && + detail->hardware_only) + return false; + + /* Check if the mode supports hardware mode */ + if (led_cdev->blink_mode != LED_BLINK_SW_CONTROLLED) { + /* Track modes that should be handled by sw */ + if (force_sw) { + sw_blink_modes |= BIT(detail->bit); + continue; + } + + /* Check if the mode is supported */ + if (led_trigger_blink_mode_is_supported(led_cdev, BIT(detail->bit))) + hw_blink_modes |= BIT(detail->bit); + } else { + sw_blink_modes |= BIT(detail->bit); + } + } + + /* We can't run modes handled by both software and hardware. */ + if (hw_blink_modes && sw_blink_modes) + return false; + + /* Make sure we support each requested mode */ + if (hw_blink_modes && hw_blink_modes != trigger_data->mode) + return false; + + /* Modes are valid. Decide now the running mode to later + * set the baseline. + */ + if (sw_blink_modes) + trigger_data->blink_mode = LED_BLINK_SW_CONTROLLED; + else + trigger_data->blink_mode = LED_BLINK_HW_CONTROLLED; + + return true; +} + static void set_baseline_state(struct led_netdev_data *trigger_data) { + int i; int current_brightness; + struct netdev_led_attr_detail *detail; struct led_classdev *led_cdev = trigger_data->led_cdev; + /* Modes already validated. Directly apply hw trigger modes */ + if (trigger_data->blink_mode == LED_BLINK_HW_CONTROLLED) { + /* We are refreshing the blink modes. Reset them */ + led_cdev->hw_control_configure(led_cdev, 0, + LED_BLINK_HW_RESET); + + for (i = 0; i < ARRAY_SIZE(attr_details); i++) { + detail = &attr_details[i]; + + if (!test_bit(detail->bit, &trigger_data->mode)) + continue; + + led_cdev->hw_control_configure(led_cdev, BIT(detail->bit), + LED_BLINK_HW_ENABLE); + } + + led_cdev->hw_control_start(led_cdev); + + return; + } + + /* Handle trigger modes by software */ current_brightness = led_cdev->brightness; if (current_brightness) led_cdev->blink_brightness = current_brightness; @@ -100,6 +203,8 @@ static ssize_t device_name_store(struct device *dev, size_t size) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); + char old_device_name[IFNAMSIZ]; + struct net_device *old_net; if (size >= IFNAMSIZ) return -EINVAL; @@ -108,11 +213,12 @@ static ssize_t device_name_store(struct device *dev, spin_lock_bh(&trigger_data->lock); - if (trigger_data->net_dev) { - dev_put(trigger_data->net_dev); - trigger_data->net_dev = NULL; - } + /* Backup old device name and save old net */ + old_net = trigger_data->net_dev; + trigger_data->net_dev = NULL; + memcpy(old_device_name, trigger_data->device_name, IFNAMSIZ); + /* Set the new device name */ memcpy(trigger_data->device_name, buf, size); trigger_data->device_name[size] = 0; if (size > 0 && trigger_data->device_name[size - 1] == '\n') @@ -122,6 +228,21 @@ static ssize_t device_name_store(struct device *dev, trigger_data->net_dev = dev_get_by_name(&init_net, trigger_data->device_name); + if (!validate_baseline_state(trigger_data)) { + /* Restore old net_dev and device_name */ + dev_put(trigger_data->net_dev); + + /* Restore device settings */ + trigger_data->net_dev = old_net; + memcpy(trigger_data->device_name, old_device_name, IFNAMSIZ); + + spin_unlock_bh(&trigger_data->lock); + return -EINVAL; + } + + /* Everything is ok. We can drop reference to the old net */ + dev_put(old_net); + trigger_data->carrier_link_up = false; if (trigger_data->net_dev != NULL) trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev); @@ -159,7 +280,7 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, size_t size, enum led_trigger_netdev_modes attr) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); - unsigned long state; + unsigned long state, old_mode = trigger_data->mode; int ret; int bit; @@ -184,6 +305,12 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, else clear_bit(bit, &trigger_data->mode); + if (!validate_baseline_state(trigger_data)) { + /* Restore old mode on validation fail */ + trigger_data->mode = old_mode; + return -EINVAL; + } + set_baseline_state(trigger_data); return size; @@ -220,6 +347,8 @@ static ssize_t interval_store(struct device *dev, size_t size) { struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); + int old_interval = atomic_read(&trigger_data->interval); + u32 old_mode = trigger_data->mode; unsigned long value; int ret; @@ -228,13 +357,26 @@ static ssize_t interval_store(struct device *dev, return ret; /* impose some basic bounds on the timer interval */ - if (value >= 5 && value <= 10000) { - cancel_delayed_work_sync(&trigger_data->work); + if (value < 5 || value > 10000) + return -EINVAL; + + /* With hw blink the blink interval is handled internally */ + if (trigger_data->blink_mode == LED_BLINK_HW_CONTROLLED) + return -EINVAL; + + cancel_delayed_work_sync(&trigger_data->work); + + atomic_set(&trigger_data->interval, msecs_to_jiffies(value)); - atomic_set(&trigger_data->interval, msecs_to_jiffies(value)); - set_baseline_state(trigger_data); /* resets timer */ + if (!validate_baseline_state(trigger_data)) { + /* Restore old interval on validation error */ + atomic_set(&trigger_data->interval, old_interval); + trigger_data->mode = old_mode; + return -EINVAL; } + set_baseline_state(trigger_data); /* resets timer */ + return size; } @@ -368,13 +510,25 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) trigger_data->mode = 0; atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); trigger_data->last_activity = 0; + if (led_cdev->blink_mode != LED_BLINK_SW_CONTROLLED) { + /* With hw mode enabled reset any rule set by default */ + if (led_cdev->hw_control_status(led_cdev)) { + rc = led_cdev->hw_control_configure(led_cdev, 0, + LED_BLINK_HW_RESET); + if (rc) + goto err; + } + } led_set_trigger_data(led_cdev, trigger_data); rc = register_netdevice_notifier(&trigger_data->notifier); if (rc) - kfree(trigger_data); + goto err; + return 0; +err: + kfree(trigger_data); return rc; } @@ -394,6 +548,7 @@ static void netdev_trig_deactivate(struct led_classdev *led_cdev) static struct led_trigger netdev_led_trigger = { .name = "netdev", + .supported_blink_modes = LED_TRIGGER_SWHW, .activate = netdev_trig_activate, .deactivate = netdev_trig_deactivate, .groups = netdev_trig_groups, From patchwork Thu Feb 16 01:32:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654698 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 13CA4C6379F for ; Thu, 16 Feb 2023 01:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbjBPBgr (ORCPT ); Wed, 15 Feb 2023 20:36:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbjBPBgn (ORCPT ); Wed, 15 Feb 2023 20:36:43 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B4B5460A8; Wed, 15 Feb 2023 17:36:27 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id f23-20020a05600c491700b003dff4480a17so3255977wmp.1; Wed, 15 Feb 2023 17:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Emg45XsaXtug12JKPR+eF5BojCRRPqwZT9u/94eP10k=; b=DISZgrx6BCflOTggDTSc+82B6r5D4O9inMgejdTfDAERynqaLqtieqAbdGEIlC/442 RL5ZcmRa0Yiq6HHRmtU/jzkOc9lo9rad6jSl0ZfyoSt6AFlfj/8jIF6sPUfgFcbzCXQm f9/9grXb68O+cQwLpEN59TJEN3KxGe2vW1OzcTWMYnSq+vXKuGXAFEX8m/c4F5BfrFnL N1HtHIqPN3CuHDgz9vDSqkwymhWImmYyJfiU+yPfDL/gPaknjSg7svVQpSRmnADQUqb5 WtcKm5ZNw18PmtWnWDbd4k8jrgxa++2bO8lC7qA9xWsgXDDjS960v5lfpR8S4fWfCWdb V0xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Emg45XsaXtug12JKPR+eF5BojCRRPqwZT9u/94eP10k=; b=OYnV3aNb89OvjFIkAfEAPicYPNlaC4PsecLZf/CGZx2ndJBuiCKvm/IlBWa9kzeyxa DLh31O5D9amTu4egbYzfBQVnl5W6F3n1LaCBN/tfZREuqVHMHi9Ns72hPr7hNTpmyEFh sbmf68Yp80Hr6hoVz/D7dHaT38nW+S1jU3X7ryEJbde1W8+q2rP0bCduPT+4ptS+81YM NLTTpPFq87sgvusrw0ql8VVY1+H1C8wxJ0xfruIknN6YlXl0eB1JUVgjKSvxNtby21RV Qxn6QkfKuuiOGCzCLQpTpiVMzZMKEA4QL09kgviSeWTlaU3L1xOKR29CzRz7sHxOl0p7 vOjw== X-Gm-Message-State: AO0yUKUezpm0PrWCEOIhJw96n2fgarskWKCG9s8xGcFxWrjPNBwHfJQK yTCY/wYFKc2Mfi7Qp0mgvWU= X-Google-Smtp-Source: AK7set8lGzEmrqhx8KiQzqZUxydMkwIXl10F0C4+Nsmrut5crIf08p4Xe/sgv0BsKFrW3H4phQ949A== X-Received: by 2002:a05:600c:318f:b0:3df:e468:17dc with SMTP id s15-20020a05600c318f00b003dfe46817dcmr3383094wmp.40.1676511385969; Wed, 15 Feb 2023 17:36:25 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:25 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 07/13] leds: trigger: netdev: use mutex instead of spinlocks Date: Thu, 16 Feb 2023 02:32:24 +0100 Message-Id: <20230216013230.22978-8-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Some LEDs may require to sleep to apply their hardware rules. Convert to mutex lock to fix warning for sleeping under spinlock softirq. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index d85be325e492..6dd04f4d70ea 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include "../leds.h" @@ -40,7 +40,7 @@ struct led_netdev_data { enum led_blink_modes blink_mode; - spinlock_t lock; + struct mutex lock; struct delayed_work work; struct notifier_block notifier; @@ -191,9 +191,9 @@ static ssize_t device_name_show(struct device *dev, struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); ssize_t len; - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); len = sprintf(buf, "%s\n", trigger_data->device_name); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return len; } @@ -211,7 +211,7 @@ static ssize_t device_name_store(struct device *dev, cancel_delayed_work_sync(&trigger_data->work); - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); /* Backup old device name and save old net */ old_net = trigger_data->net_dev; @@ -236,7 +236,7 @@ static ssize_t device_name_store(struct device *dev, trigger_data->net_dev = old_net; memcpy(trigger_data->device_name, old_device_name, IFNAMSIZ); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return -EINVAL; } @@ -250,7 +250,7 @@ static ssize_t device_name_store(struct device *dev, trigger_data->last_activity = 0; set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return size; } @@ -412,7 +412,7 @@ static int netdev_trig_notify(struct notifier_block *nb, cancel_delayed_work_sync(&trigger_data->work); - spin_lock_bh(&trigger_data->lock); + mutex_lock(&trigger_data->lock); trigger_data->carrier_link_up = false; switch (evt) { @@ -435,7 +435,7 @@ static int netdev_trig_notify(struct notifier_block *nb, set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); + mutex_unlock(&trigger_data->lock); return NOTIFY_DONE; } @@ -496,7 +496,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) if (!trigger_data) return -ENOMEM; - spin_lock_init(&trigger_data->lock); + mutex_init(&trigger_data->lock); trigger_data->notifier.notifier_call = netdev_trig_notify; trigger_data->notifier.priority = 10; From patchwork Thu Feb 16 01:32:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654300 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 74668C677F1 for ; Thu, 16 Feb 2023 01:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229837AbjBPBgs (ORCPT ); Wed, 15 Feb 2023 20:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229795AbjBPBgn (ORCPT ); Wed, 15 Feb 2023 20:36:43 -0500 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 02DAE460AE; Wed, 15 Feb 2023 17:36:27 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id az4-20020a05600c600400b003dff767a1f1so452867wmb.2; Wed, 15 Feb 2023 17:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=vhCM3b28R3+woNIHZgCVKD0ugnkmVKAOEKg8BSCfbhs=; b=JTYXQusfYeTpKf5CIdokbUYI/O7XT0GoPLukiIK1Adc91kJgFlf2Db3655jXCjrv9w J3IJLu4tYNvvX9FXmx2wcTLpNIW4n9JbhxcGxitvAsi+b+ZPp2Yctykm1ijGh3tNYDGE AW30u8UMsgt4i/tMHSpDfTS3dI28gNZmj8/xyCwNNzhPHxR/B+kIabo0uRudlkhALAy1 ROexqntER7ioYliK5TNv7sbMput5dSwp88btslEwR3BC9TTOZ+A5qCPrp9y4Xk6ICN5I LyjrP2w+86R+sB3xiUrLkVDdGDI+56VYVKtTxPnJdxk0ooZP7jEpU1U5lIbORNE4JW3g uH9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=vhCM3b28R3+woNIHZgCVKD0ugnkmVKAOEKg8BSCfbhs=; b=yOpAm2i0swewGlEmFc2a1CfHJGeGBQ/2hlNkjz19E+0gX4u4aE15HtGCu6raHueNKN Lm2TDjrWLdT+baiooH8U67GcQLpJe58JwgMaP82+Dds39tv9rT8O9ZPRG7r/21+yDmN8 HiOeegx/XaVXVUu0n1Dt1nPkKvZIQkA/FyXWaG34FXaJidGle6eWQLrpSvLWEVepa4Za EANqmdIFxoLygKHjDdiHe/CY43Axdshf6w1Bh6mIh1G5YXbmuVKgmIwOMQnv6bLIy++Z MmVazFBl3/g4Dmy3gCVkIGM+BfKMqiSlJaXc312HlWd4Ss4p6TddJ0X7KmgE5YbN37CO 4cyg== X-Gm-Message-State: AO0yUKW9xMQXWxuP9EwvrzAySymQjwHg+/9MBTvzN6tzy1ZQf0G1D2G/ NWgHqlnIvLu0bdZ0pA1Gt6M= X-Google-Smtp-Source: AK7set+hcJir70mP7Ikeox+RQ2xNCGRSITRsjGZD9D0kXvJCA08S8XHPyXxewOyEAXl1yGPcsWy1+w== X-Received: by 2002:a05:600c:44d2:b0:3e2:662:add6 with SMTP id f18-20020a05600c44d200b003e20662add6mr2330599wmo.11.1676511387365; Wed, 15 Feb 2023 17:36:27 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:27 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 08/13] leds: trigger: netdev: add available mode sysfs attr Date: Thu, 16 Feb 2023 02:32:25 +0100 Message-Id: <20230216013230.22978-9-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add avaiable_mode sysfs attr to show and give some details about the supported modes and how they can be handled by the trigger. this can be used to get an overview of the different modes currently available and active. A mode with [hardware] can hw blink. A mode with [software] con blink with sw support. A mode with [hardware][software] support both mode but will fallback to sw mode if needed. A mode with [unavailable] will reject any option and can't be enabled due to hw limitation or current configuration. Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 6dd04f4d70ea..b992d617f406 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -35,6 +35,8 @@ * (has carrier) or not * tx - LED blinks on transmitted data * rx - LED blinks on receive data + * available_mode - Display available mode and how they can be handled + * by the LED * */ @@ -382,12 +384,51 @@ static ssize_t interval_store(struct device *dev, static DEVICE_ATTR_RW(interval); +static ssize_t available_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev); + struct netdev_led_attr_detail *detail; + bool support_hw_mode; + int i, len = 0; + + for (i = 0; i < ARRAY_SIZE(attr_details); i++) { + detail = &attr_details[i]; + support_hw_mode = led_trigger_blink_mode_is_supported(trigger_data->led_cdev, + BIT(detail->bit)); + + len += sprintf(buf + len, "%s ", detail->name); + + if (detail->hardware_only) { + if (trigger_data->net_dev || !support_hw_mode) + len += sprintf(buf + len, "[unavailable]"); + else + len += sprintf(buf + len, "[hardware]"); + } else { + len += sprintf(buf + len, "[software]"); + + if (support_hw_mode && !trigger_data->net_dev) + len += sprintf(buf + len, "[hardware]"); + } + + if (test_bit(detail->bit, &trigger_data->mode)) + len += sprintf(buf + len, "[on]"); + + len += sprintf(buf + len, "\n"); + } + + return len; +} + +static DEVICE_ATTR_RO(available_mode); + static struct attribute *netdev_trig_attrs[] = { &dev_attr_device_name.attr, &dev_attr_link.attr, &dev_attr_rx.attr, &dev_attr_tx.attr, &dev_attr_interval.attr, + &dev_attr_available_mode.attr, NULL }; ATTRIBUTE_GROUPS(netdev_trig); From patchwork Thu Feb 16 01:32:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654696 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 67857C636CC for ; Thu, 16 Feb 2023 01:37:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229897AbjBPBh3 (ORCPT ); Wed, 15 Feb 2023 20:37:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229781AbjBPBgq (ORCPT ); Wed, 15 Feb 2023 20:36:46 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D64B846164; Wed, 15 Feb 2023 17:36:30 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id s13-20020a05600c45cd00b003ddca7a2bcbso436494wmo.3; Wed, 15 Feb 2023 17:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Cvd+xH+uABWYG4lAo6qwQojco60Jw9t/Cf4VcdLlrbU=; b=LExgDe66nojEag9TulRXjtJR+0NOwJTKsN2FewR9qwomKPDL6p4qU3sA8qazmP1h0F 2kuI8z8De/F9heHpDfxs0VAwGoNowXVpZyqW7U2LnC5RrF88EM+F1NafTO7XfVgrYPhA 5Xp82NfP3/DpwLc2/EFKauA8nq5GYv+w3+Qig8iYnAa8DbtYnyQroydivC7nt9c4a8Z5 bMygdeSSKzVfgVcbHf1sCgRGLbvMZtZZ2MFyqj33oqLVR4MbyLOZukJf1Eh8DbdAfyOG a1dVKXXHZZ3bVEbCSqenXDRzv22xJ7+0FL/8+mt+oeW5m2aRKRAwuoNSr6qMDzHKbnRx 8IFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Cvd+xH+uABWYG4lAo6qwQojco60Jw9t/Cf4VcdLlrbU=; b=BCnYFXEWoxdwbu/7F1h12mN/8kZwisvoSsZccheXieE/zLCkn7QX44TVFT+/z+3QvW 7E08reLCRCvAApNNFSyyjravg5v+9N85t+6aH1Cc1fty83OYlTYUnuuY8soVUL+ut1QD y7JoVVV7cRA75myfbP6WA7pNko2RIcGOR9KFQzqmRmV+7uArfpR+upjhD32FKkpKQfjD sIAk25kipzayEtwGC0hFysnEvl+RbHLAGp0waG0F5KLnfwVuEwkZCqPOUkLYxdW1NZVw YBjOLYARo/dsqFw7D3xY0XZRe53USSd7R3gSm/4+tXh8n/eF79SgKN3XNYBo2S0zY+XE XAFw== X-Gm-Message-State: AO0yUKUt1Y6Z+UbiooRfbU52nCxmM0eVUhOLBuDYFYaFdyhqIb2UfTx0 PpXqWRuXOJQj7GXkfpGmBRk= X-Google-Smtp-Source: AK7set/yaSvTl+DcBsbUCR9AmTFw/OJe/93EaxiOAi69Ff1hlit5AFMf8fBOsIQd0OOsQncBCplXXg== X-Received: by 2002:a05:600c:c0e:b0:3df:f860:3089 with SMTP id fm14-20020a05600c0c0e00b003dff8603089mr3719917wmb.32.1676511388774; Wed, 15 Feb 2023 17:36:28 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:28 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 09/13] leds: trigger: netdev: add additional hardware only triggers Date: Thu, 16 Feb 2023 02:32:26 +0100 Message-Id: <20230216013230.22978-10-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add additional hardware only triggers commonly supported by switch LEDs. Additional modes: link_10: LED on with link up AND speed 10mbps link_100: LED on with link up AND speed 100mbps link_1000: LED on with link up AND speed 1000mbps half_duplex: LED on with link up AND half_duplex mode full_duplex: LED on with link up AND full duplex mode activity: LED blink on tx or rx event Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 58 +++++++++++++++++++++++++++ include/linux/leds.h | 6 +++ 2 files changed, 64 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index b992d617f406..b229bdb69501 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -33,6 +33,17 @@ * (not supported in hw mode) * link - LED's normal state reflects whether the link is up * (has carrier) or not + * link_10 - LED's normal state reflects whether the link is + * up and at 10mbps speed (hardware only) + * link_100 - LED's normal state reflects whether the link is + * up and at 100mbps speed (hardware only) + * link_1000 - LED's normal state reflects whether the link is + * up and at 1000mbps speed (hardware only) + * half_duplex - LED's normal state reflects whether the link is + * up and hafl duplex (hardware only) + * full_duplex - LED's normal state reflects whether the link is + * up and full duplex (hardware only) + * activity - LED's blinks on transmitted or received data (hardware only) * tx - LED blinks on transmitted data * rx - LED blinks on receive data * available_mode - Display available mode and how they can be handled @@ -66,6 +77,12 @@ struct netdev_led_attr_detail { static struct netdev_led_attr_detail attr_details[] = { { .name = "link", .bit = TRIGGER_NETDEV_LINK}, + { .name = "link_10", .hardware_only = true, .bit = TRIGGER_NETDEV_LINK_10}, + { .name = "link_100", .hardware_only = true, .bit = TRIGGER_NETDEV_LINK_100}, + { .name = "link_1000", .hardware_only = true, .bit = TRIGGER_NETDEV_LINK_1000}, + { .name = "half_duplex", .hardware_only = true, .bit = TRIGGER_NETDEV_HALF_DUPLEX}, + { .name = "full_duplex", .hardware_only = true, .bit = TRIGGER_NETDEV_FULL_DUPLEX}, + { .name = "activity", .hardware_only = true, .bit = TRIGGER_NETDEV_ACTIVITY }, { .name = "tx", .bit = TRIGGER_NETDEV_TX}, { .name = "rx", .bit = TRIGGER_NETDEV_RX}, }; @@ -123,6 +140,23 @@ static bool validate_baseline_state(struct led_netdev_data *trigger_data) if (hw_blink_modes && hw_blink_modes != trigger_data->mode) return false; + /* Check conflicts single rx or tx can't be active if activity is + * active. + */ + if (test_bit(TRIGGER_NETDEV_ACTIVITY, &hw_blink_modes) && + (test_bit(TRIGGER_NETDEV_TX, &hw_blink_modes) || + test_bit(TRIGGER_NETDEV_RX, &hw_blink_modes))) + return false; + + /* Check conflicts single link speed can't be active if link is + * active. + */ + if (test_bit(TRIGGER_NETDEV_LINK, &hw_blink_modes) && + (test_bit(TRIGGER_NETDEV_LINK_10, &hw_blink_modes) || + test_bit(TRIGGER_NETDEV_LINK_100, &hw_blink_modes) || + test_bit(TRIGGER_NETDEV_LINK_1000, &hw_blink_modes))) + return false; + /* Modes are valid. Decide now the running mode to later * set the baseline. */ @@ -267,6 +301,12 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf, switch (attr) { case TRIGGER_NETDEV_LINK: + case TRIGGER_NETDEV_LINK_10: + case TRIGGER_NETDEV_LINK_100: + case TRIGGER_NETDEV_LINK_1000: + case TRIGGER_NETDEV_HALF_DUPLEX: + case TRIGGER_NETDEV_FULL_DUPLEX: + case TRIGGER_NETDEV_ACTIVITY: case TRIGGER_NETDEV_TX: case TRIGGER_NETDEV_RX: bit = attr; @@ -292,6 +332,12 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, switch (attr) { case TRIGGER_NETDEV_LINK: + case TRIGGER_NETDEV_LINK_10: + case TRIGGER_NETDEV_LINK_100: + case TRIGGER_NETDEV_LINK_1000: + case TRIGGER_NETDEV_HALF_DUPLEX: + case TRIGGER_NETDEV_FULL_DUPLEX: + case TRIGGER_NETDEV_ACTIVITY: case TRIGGER_NETDEV_TX: case TRIGGER_NETDEV_RX: bit = attr; @@ -332,6 +378,12 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, static DEVICE_ATTR_RW(trigger_name) DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK); +DEFINE_NETDEV_TRIGGER(link_10, TRIGGER_NETDEV_LINK_10); +DEFINE_NETDEV_TRIGGER(link_100, TRIGGER_NETDEV_LINK_100); +DEFINE_NETDEV_TRIGGER(link_1000, TRIGGER_NETDEV_LINK_1000); +DEFINE_NETDEV_TRIGGER(half_duplex, TRIGGER_NETDEV_HALF_DUPLEX); +DEFINE_NETDEV_TRIGGER(full_duplex, TRIGGER_NETDEV_FULL_DUPLEX); +DEFINE_NETDEV_TRIGGER(activity, TRIGGER_NETDEV_ACTIVITY); DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX); DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX); @@ -425,6 +477,12 @@ static DEVICE_ATTR_RO(available_mode); static struct attribute *netdev_trig_attrs[] = { &dev_attr_device_name.attr, &dev_attr_link.attr, + &dev_attr_link_10.attr, + &dev_attr_link_100.attr, + &dev_attr_link_1000.attr, + &dev_attr_half_duplex.attr, + &dev_attr_full_duplex.attr, + &dev_attr_activity.attr, &dev_attr_rx.attr, &dev_attr_tx.attr, &dev_attr_interval.attr, diff --git a/include/linux/leds.h b/include/linux/leds.h index a31f158e5351..9071ab768776 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -574,6 +574,12 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev) /* Trigger specific enum */ enum led_trigger_netdev_modes { TRIGGER_NETDEV_LINK = 1, + TRIGGER_NETDEV_LINK_10, + TRIGGER_NETDEV_LINK_100, + TRIGGER_NETDEV_LINK_1000, + TRIGGER_NETDEV_HALF_DUPLEX, + TRIGGER_NETDEV_FULL_DUPLEX, + TRIGGER_NETDEV_ACTIVITY, TRIGGER_NETDEV_TX, TRIGGER_NETDEV_RX, }; From patchwork Thu Feb 16 01:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654298 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 DCE32C64ED6 for ; Thu, 16 Feb 2023 01:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229922AbjBPBhb (ORCPT ); Wed, 15 Feb 2023 20:37:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbjBPBgq (ORCPT ); Wed, 15 Feb 2023 20:36:46 -0500 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 0EB9946089; Wed, 15 Feb 2023 17:36:32 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id he5so448411wmb.3; Wed, 15 Feb 2023 17:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Z4ojF02Rta3/KZ2m4JA4g2PG4o7LwkQGypKckn0U9r4=; b=RLVdiG9YFfGFZtsSugkaTPMOCnPZQIVgrLVaEpzaAMAd/k4MqVHjyfFoAynImCmRcC h0uafvsRk+r7b4OpEz2t6GvfO87yHDwHP9VbH6Rzj+EAyD3yznmo2M84HpixFZfvrskS 1MQ/JP2/LDLQpRGF8/TXjeX6fhO8C8n+ukGOJrVedZeQ/YxnNe4DRbxPl6qGmX4EqhoX jiY0+b042nEr90DqwHTnghtZkbSSrGQg60cW3P/KC18hP0ACbPzVngmId6CpWDr1UY5h rS4rd1kjh3gnhEtCB/Zs2jrcCVgSn5n5vy0KnDPeZSGWoeKXBz8EKwNO1SDIv3LLqr6c uP+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Z4ojF02Rta3/KZ2m4JA4g2PG4o7LwkQGypKckn0U9r4=; b=RXvnzhIr2Rrj1ENBMROEwTRc0t8Xz1rbtfxEaIFyqFHf1YQYubwBHG6aXSD5EqR+mr 4S+Ux+oXbDdI8dpmlBwLPraBqS2oPDL0g9FqU89O91hMjOBYAB9VZqiBadPOI27S5G27 tv8yJA3gCNUQbyc4h4pFIGQTp8IwCK7o1be5OOkAvnho5fA/FZBNKELPNXgR8ZkmjAbg Qelr5LJN/sY0dUpreRD+zb6vpcRlnXBzoUC9kw/cKGWB4vZ2C3Cwfy+Se9B5YWDjCiXd b38p4Oi4XFfAj9FFueP2SkI4wiY1wur2okLVghlrW/aWBqXBx32XEZISF+7l4LdpG4F3 XpKg== X-Gm-Message-State: AO0yUKXbrKkd2o0q2OfZPsG1+70wP3gBhI0IS9+PBaZelAr3y8uPnOsF I8WSWTiTa+n3yW6NGI4Yofk= X-Google-Smtp-Source: AK7set/ZxCSaG06XJoZE/BFIeKhHBYlK+RYROwllDzEzMll3LTqRyHJitEcRAKuliiXTAzgdxdoUkg== X-Received: by 2002:a05:600c:444b:b0:3e1:bfc:d16e with SMTP id v11-20020a05600c444b00b003e10bfcd16emr3977611wmn.39.1676511390186; Wed, 15 Feb 2023 17:36:30 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:29 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 10/13] net: dsa: qca8k: add LEDs support Date: Thu, 16 Feb 2023 02:32:27 +0100 Message-Id: <20230216013230.22978-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add LEDs support for qca8k Switch Family. This will provide the LEDs hardware API to permit the PHY LED to support hardware mode. Each port have at least 3 LEDs and they can HW blink, set on/off or follow blink modes configured with the LED in hardware mode. Adds support for leds netdev trigger to support hardware triggers. These LEDs supports only blocking variant of the brightness_set function since they can sleep during access of the switch leds to set the brightness. Signed-off-by: Christian Marangi --- drivers/net/dsa/qca/Kconfig | 9 + drivers/net/dsa/qca/Makefile | 1 + drivers/net/dsa/qca/qca8k-8xxx.c | 4 + drivers/net/dsa/qca/qca8k-leds.c | 419 +++++++++++++++++++++++++++++++ drivers/net/dsa/qca/qca8k.h | 69 +++++ 5 files changed, 502 insertions(+) create mode 100644 drivers/net/dsa/qca/qca8k-leds.c diff --git a/drivers/net/dsa/qca/Kconfig b/drivers/net/dsa/qca/Kconfig index ba339747362c..be67164a444e 100644 --- a/drivers/net/dsa/qca/Kconfig +++ b/drivers/net/dsa/qca/Kconfig @@ -15,3 +15,12 @@ config NET_DSA_QCA8K help This enables support for the Qualcomm Atheros QCA8K Ethernet switch chips. + +config NET_DSA_QCA8K_LEDS_SUPPORT + tristate "Qualcomm Atheros QCA8K Ethernet switch family LEDs support" + depends on NET_DSA_QCA8K + select LEDS_OFFLOAD_TRIGGERS + help + This enabled support for LEDs present on the Qualcomm Atheros + QCA8K Ethernet switch chips. This require the LEDs offload + triggers support as it can run in offload mode. diff --git a/drivers/net/dsa/qca/Makefile b/drivers/net/dsa/qca/Makefile index 701f1d199e93..330ae389e489 100644 --- a/drivers/net/dsa/qca/Makefile +++ b/drivers/net/dsa/qca/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_NET_DSA_AR9331) += ar9331.o obj-$(CONFIG_NET_DSA_QCA8K) += qca8k.o qca8k-y += qca8k-common.o qca8k-8xxx.o +obj-$(CONFIG_NET_DSA_QCA8K_LEDS_SUPPORT) += qca8k-leds.o diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c index 55df4479ea30..a983f7c96b0d 100644 --- a/drivers/net/dsa/qca/qca8k-8xxx.c +++ b/drivers/net/dsa/qca/qca8k-8xxx.c @@ -1798,6 +1798,10 @@ qca8k_setup(struct dsa_switch *ds) if (ret) return ret; + ret = qca8k_setup_led_ctrl(priv); + if (ret) + return ret; + qca8k_setup_pcs(priv, &priv->pcs_port_0, 0); qca8k_setup_pcs(priv, &priv->pcs_port_6, 6); diff --git a/drivers/net/dsa/qca/qca8k-leds.c b/drivers/net/dsa/qca/qca8k-leds.c new file mode 100644 index 000000000000..3653ad9bd90b --- /dev/null +++ b/drivers/net/dsa/qca/qca8k-leds.c @@ -0,0 +1,419 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +#include "qca8k.h" + +static int +qca8k_get_enable_led_reg(int port_num, int led_num, struct qca8k_led_pattern_en *reg_info) +{ + switch (port_num) { + case 0: + reg_info->reg = QCA8K_LED_CTRL_REG(led_num); + reg_info->shift = QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT; + break; + case 1: + case 2: + case 3: + /* Port 123 are controlled on a different reg */ + reg_info->reg = QCA8K_LED_CTRL_REG(3); + reg_info->shift = QCA8K_LED_PHY123_PATTERN_EN_SHIFT(port_num, led_num); + break; + case 4: + reg_info->reg = QCA8K_LED_CTRL_REG(led_num); + reg_info->shift = QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT; + break; + default: + return -EINVAL; + } + + 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, u32 *mask) +{ + /* Parsing specific to netdev trigger */ + if (test_bit(TRIGGER_NETDEV_LINK, &rules)) + *offload_trigger |= QCA8K_LED_LINK_10M_EN_MASK | + QCA8K_LED_LINK_100M_EN_MASK | + QCA8K_LED_LINK_1000M_EN_MASK; + if (test_bit(TRIGGER_NETDEV_LINK_10, &rules)) + *offload_trigger |= QCA8K_LED_LINK_10M_EN_MASK; + if (test_bit(TRIGGER_NETDEV_LINK_100, &rules)) + *offload_trigger |= QCA8K_LED_LINK_100M_EN_MASK; + if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules)) + *offload_trigger |= QCA8K_LED_LINK_1000M_EN_MASK; + if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &rules)) + *offload_trigger |= QCA8K_LED_HALF_DUPLEX_MASK; + if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &rules)) + *offload_trigger |= QCA8K_LED_FULL_DUPLEX_MASK; + if (test_bit(TRIGGER_NETDEV_ACTIVITY, &rules)) + *offload_trigger |= QCA8K_LED_TX_BLINK_MASK | + QCA8K_LED_RX_BLINK_MASK; + 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; + + *mask = *offload_trigger; + + return 0; +} + +static int +qca8k_cled_hw_control_configure(struct led_classdev *ldev, unsigned long rules, + enum led_blink_hw_cmd cmd) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + struct led_trigger *trigger = ldev->trigger; + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + u32 offload_trigger = 0, mask, val; + int ret; + + /* Check trigger compatibility */ + if (strcmp(trigger->name, "netdev")) + return -EOPNOTSUPP; + + if (!strcmp(trigger->name, "netdev")) + ret = qca8k_parse_netdev(rules, &offload_trigger, &mask); + + if (ret) + return ret; + + qca8k_get_control_led_reg(led->port_num, led->led_num, ®_info); + + switch (cmd) { + case LED_BLINK_HW_SUPPORTED: + /* We reach this point, we are sure the trigger is supported */ + return 1; + case LED_BLINK_HW_RESET: + /* We set 4hz by default */ + ret = regmap_update_bits(priv->regmap, reg_info.reg, + QCA8K_LED_RULE_MASK << reg_info.shift, + QCA8K_LED_BLINK_4HZ << reg_info.shift); + break; + case LED_BLINK_HW_ENABLE: + ret = regmap_update_bits(priv->regmap, reg_info.reg, + mask << reg_info.shift, + offload_trigger << reg_info.shift); + break; + case LED_BLINK_HW_DISABLE: + ret = regmap_update_bits(priv->regmap, reg_info.reg, + mask << reg_info.shift, + 0); + break; + case LED_BLINK_HW_STATUS: + ret = regmap_read(priv->regmap, reg_info.reg, &val); + if (ret) + return ret; + + val >>= reg_info.shift; + val &= offload_trigger; + + return val; + default: + return -EOPNOTSUPP; + } + + return ret; +} + +static int +qca8k_led_brightness_set(struct qca8k_led *led, + enum led_brightness brightness) +{ + 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 (brightness) + val = QCA8K_LED_ALWAYS_ON; + + 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 int +qca8k_cled_brightness_set_blocking(struct led_classdev *ldev, + enum led_brightness brightness) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + + return qca8k_led_brightness_set(led, brightness); +} + +static enum led_brightness +qca8k_led_brightness_get(struct qca8k_led *led) +{ + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + u32 val; + int ret; + + qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); + + ret = regmap_read(priv->regmap, reg_info.reg, &val); + if (ret) + return 0; + + 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 > 0 ? 1 : 0; +} + +static enum led_brightness +qca8k_cled_brightness_get(struct led_classdev *ldev) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + + return qca8k_led_brightness_get(led); +} + +static int +qca8k_cled_blink_set(struct led_classdev *ldev, + unsigned long *delay_on, + unsigned long *delay_off) +{ + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); + u32 mask, val = QCA8K_LED_ALWAYS_BLINK_4HZ; + struct qca8k_led_pattern_en reg_info; + struct qca8k_priv *priv = led->priv; + + if (*delay_on == 0 && *delay_off == 0) { + *delay_on = 125; + *delay_off = 125; + } + + if (*delay_on != 125 || *delay_off != 125) { + /* The hardware only supports blinking at 4Hz. Fall back + * to software implementation in other cases. + */ + return -EINVAL; + } + + qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); + + 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; + } + + regmap_update_bits(priv->regmap, reg_info.reg, mask << reg_info.shift, + val << reg_info.shift); + + 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 int +qca8k_cled_hw_control_start(struct led_classdev *led_cdev) +{ + return qca8k_cled_trigger_offload(led_cdev, true); +} + +static int +qca8k_cled_hw_control_stop(struct led_classdev *led_cdev) +{ + return qca8k_cled_trigger_offload(led_cdev, false); +} + +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_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int port_num) +{ + struct fwnode_handle *led = NULL, *leds = NULL; + struct led_init_data init_data = { }; + struct qca8k_led *port_led; + int led_num, port_index; + const char *state; + int ret; + + leds = fwnode_get_named_child_node(port, "leds"); + if (!leds) { + dev_dbg(priv->dev, "No Leds node specified in device tree for port %d!\n", + port_num); + return 0; + } + + fwnode_for_each_child_node(leds, led) { + /* Reg represent the led number of the port. + * Each port can have at least 3 leds attached + * Commonly: + * 1. is gigabit led + * 2. is mbit led + * 3. additional status led + */ + if (fwnode_property_read_u32(led, "reg", &led_num)) + continue; + + if (led_num >= QCA8K_LED_PORT_COUNT) { + dev_warn(priv->dev, "Invalid LED reg defined %d", port_num); + continue; + } + + port_index = 3 * port_num + led_num; + + port_led = &priv->ports_led[port_index]; + port_led->port_num = port_num; + port_led->led_num = led_num; + port_led->priv = priv; + + ret = fwnode_property_read_string(led, "default-state", &state); + if (!ret) { + if (!strcmp(state, "on")) { + port_led->cdev.brightness = 1; + qca8k_led_brightness_set(port_led, 1); + } else if (!strcmp(state, "off")) { + port_led->cdev.brightness = 0; + qca8k_led_brightness_set(port_led, 0); + } else if (!strcmp(state, "keep")) { + port_led->cdev.brightness = + qca8k_led_brightness_get(port_led); + } + } + + /* 3 brightness settings can be applied from Documentation: + * 0 always off + * 1 blink at 4Hz + * 2 always on + * 3 rule controlled + * Suppots only 2 mode: (pcb limitation, with always on and blink + * only the last led is set to this mode) + * 0 always off (sets all leds off) + * 3 rule controlled + */ + port_led->cdev.blink_mode = LED_BLINK_SWHW_CONTROLLED; + port_led->cdev.max_brightness = 1; + port_led->cdev.brightness_set_blocking = qca8k_cled_brightness_set_blocking; + port_led->cdev.brightness_get = qca8k_cled_brightness_get; + port_led->cdev.blink_set = qca8k_cled_blink_set; + port_led->cdev.hw_control_start = qca8k_cled_hw_control_start; + port_led->cdev.hw_control_stop = qca8k_cled_hw_control_stop; + port_led->cdev.hw_control_status = qca8k_cled_hw_control_status; + port_led->cdev.hw_control_configure = qca8k_cled_hw_control_configure; + init_data.default_label = ":port"; + init_data.devicename = "qca8k"; + init_data.fwnode = led; + + ret = devm_led_classdev_register_ext(priv->dev, &port_led->cdev, &init_data); + if (ret) + dev_warn(priv->dev, "Failed to int led"); + } + + return 0; +} + +int +qca8k_setup_led_ctrl(struct qca8k_priv *priv) +{ + struct fwnode_handle *mdio, *port; + int port_num; + int ret; + + mdio = device_get_named_child_node(priv->dev, "mdio"); + if (!mdio) { + dev_info(priv->dev, "No MDIO node specified in device tree!\n"); + return 0; + } + + fwnode_for_each_child_node(mdio, port) { + if (fwnode_property_read_u32(port, "reg", &port_num)) + continue; + + /* Each port can have at least 3 different leds attached */ + ret = qca8k_parse_port_leds(priv, port, port_num); + if (ret) + return ret; + } + + return 0; +} diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h index 7996975d29d3..b5c0dd95160c 100644 --- a/drivers/net/dsa/qca/qca8k.h +++ b/drivers/net/dsa/qca/qca8k.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #define QCA8K_ETHERNET_MDIO_PRIORITY 7 @@ -85,6 +86,50 @@ #define QCA8K_MDIO_MASTER_DATA(x) FIELD_PREP(QCA8K_MDIO_MASTER_DATA_MASK, x) #define QCA8K_MDIO_MASTER_MAX_PORTS 5 #define QCA8K_MDIO_MASTER_MAX_REG 32 + +/* LED control register */ +#define QCA8K_LED_COUNT 15 +#define QCA8K_LED_PORT_COUNT 3 +#define QCA8K_LED_RULE_COUNT 6 +#define QCA8K_LED_RULE_MAX 11 + +#define QCA8K_LED_PHY123_PATTERN_EN_SHIFT(_phy, _led) ((((_phy) - 1) * 6) + 8 + (2 * (_led))) +#define QCA8K_LED_PHY123_PATTERN_EN_MASK GENMASK(1, 0) + +#define QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT 0 +#define QCA8K_LED_PHY4_CONTROL_RULE_SHIFT 16 + +#define QCA8K_LED_CTRL_REG(_i) (0x050 + (_i) * 4) +#define QCA8K_LED_CTRL0_REG 0x50 +#define QCA8K_LED_CTRL1_REG 0x54 +#define QCA8K_LED_CTRL2_REG 0x58 +#define QCA8K_LED_CTRL3_REG 0x5C +#define QCA8K_LED_CTRL_SHIFT(_i) (((_i) % 2) * 16) +#define QCA8K_LED_CTRL_MASK GENMASK(15, 0) +#define QCA8K_LED_RULE_MASK GENMASK(13, 0) +#define QCA8K_LED_BLINK_FREQ_MASK GENMASK(1, 0) +#define QCA8K_LED_BLINK_FREQ_SHITF 0 +#define QCA8K_LED_BLINK_2HZ 0 +#define QCA8K_LED_BLINK_4HZ 1 +#define QCA8K_LED_BLINK_8HZ 2 +#define QCA8K_LED_BLINK_AUTO 3 +#define QCA8K_LED_LINKUP_OVER_MASK BIT(2) +#define QCA8K_LED_TX_BLINK_MASK BIT(4) +#define QCA8K_LED_RX_BLINK_MASK BIT(5) +#define QCA8K_LED_COL_BLINK_MASK BIT(7) +#define QCA8K_LED_LINK_10M_EN_MASK BIT(8) +#define QCA8K_LED_LINK_100M_EN_MASK BIT(9) +#define QCA8K_LED_LINK_1000M_EN_MASK BIT(10) +#define QCA8K_LED_POWER_ON_LIGHT_MASK BIT(11) +#define QCA8K_LED_HALF_DUPLEX_MASK BIT(12) +#define QCA8K_LED_FULL_DUPLEX_MASK BIT(13) +#define QCA8K_LED_PATTERN_EN_MASK GENMASK(15, 14) +#define QCA8K_LED_PATTERN_EN_SHIFT 14 +#define QCA8K_LED_ALWAYS_OFF 0 +#define QCA8K_LED_ALWAYS_BLINK_4HZ 1 +#define QCA8K_LED_ALWAYS_ON 2 +#define QCA8K_LED_RULE_CONTROLLED 3 + #define QCA8K_GOL_MAC_ADDR0 0x60 #define QCA8K_GOL_MAC_ADDR1 0x64 #define QCA8K_MAX_FRAME_SIZE 0x78 @@ -382,6 +427,19 @@ struct qca8k_pcs { int port; }; +struct qca8k_led_pattern_en { + u32 reg; + u8 shift; +}; + +struct qca8k_led { + u8 port_num; + u8 led_num; + u16 old_rule; + struct qca8k_priv *priv; + struct led_classdev cdev; +}; + struct qca8k_priv { u8 switch_id; u8 switch_revision; @@ -406,6 +464,7 @@ struct qca8k_priv { struct qca8k_pcs pcs_port_0; struct qca8k_pcs pcs_port_6; const struct qca8k_match_data *info; + struct qca8k_led ports_led[QCA8K_LED_COUNT]; }; struct qca8k_mib_desc { @@ -511,4 +570,14 @@ int qca8k_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag, int qca8k_port_lag_leave(struct dsa_switch *ds, int port, struct dsa_lag lag); +/* Leds Support function */ +#ifdef CONFIG_NET_DSA_QCA8K_LEDS_SUPPORT +int qca8k_setup_led_ctrl(struct qca8k_priv *priv); +#else +static inline int qca8k_setup_led_ctrl(struct qca8k_priv *priv) +{ + return 0; +} +#endif + #endif /* __QCA8K_H */ From patchwork Thu Feb 16 01:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654695 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 47774C6FA99 for ; Thu, 16 Feb 2023 01:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjBPBhe (ORCPT ); Wed, 15 Feb 2023 20:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjBPBhX (ORCPT ); Wed, 15 Feb 2023 20:37:23 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF08646159; Wed, 15 Feb 2023 17:36:33 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id s13-20020a05600c45cd00b003ddca7a2bcbso436587wmo.3; Wed, 15 Feb 2023 17:36:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=UXjDXVBhPh+t9c62wIxQrMzlmx5/oPRIL9dFvo3+Emc=; b=eSPyZlmnVMuk7xkgaR5rAsNsQHXeLwRWwy9mGle9Ba0+6mFf7vasHk1mk7gtlNhv+g Otp8kwMuIP2+Y0g5vRF9lQJU9B4VvAGnmiaddUS9Av+LwHdtxzejBxiRH8rlnlMe1mwq LvSkPsj+II+gNmlXvSQ2c+EoYzR+5BmcWwR+j153Tm2ATh1P6VYQyEy0HuZuuIJBsA0w ED8pnbZnzuC2OBDmNfZdTHgtjBqKGtkR9udEHnDm40plgvE2FJhR85VrmRG87HSYRn6g 1zoVDF9Vp/Zh8T4uNOh/5TNqrdXt+AHWOo9Mx7UzcvNPXF7dWY9DontZIrQRnJUez1sj d39g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UXjDXVBhPh+t9c62wIxQrMzlmx5/oPRIL9dFvo3+Emc=; b=I02yUd+RLc0hMogeMFBzas3Dc7+4l2WteA28AEsKqogf7zsF3bLGkPR+uyXgEnhUxm OsmufbAUaGojfmvVDNIyXksVa9Kzr1HTniMmE2kXFHalp9/3p8OnvQzqyQ8zJ/dlTaG1 EnroR8gT0HQ0/KiBy9yUwwYqeb0zedXPSVXs8yDTZQfgHK1oe0/6JADQFq2wn9IW5MpY O5A0SRSY5YsniUo3IeIfdGDJ3ld8bums3ayMw2TQH5Vcz2FCpNk/bdc0wX9SdOijXtJ8 MdbMxLdeL+SdAmvoxmdVbegltBh3/Vwmd0dzqVltIma1zMVCFvZmFm23wmsrcZ3ldHTo FISQ== X-Gm-Message-State: AO0yUKVC/4B15VpxmxjVxQm0yf4MHdsXAWfhC1mcBN1nfg4+opwYEffT Sv4nnOtsxdzJ8ySFVy/lTaI= X-Google-Smtp-Source: AK7set/gIe01fhNDx8RfJetArP9XD6OKX2UcVlBJULuAx419s18tbxUMeRl0EjdhF3wHyo3Gz2MV9g== X-Received: by 2002:a05:600c:708:b0:3dc:1687:9ba2 with SMTP id i8-20020a05600c070800b003dc16879ba2mr3525748wmn.35.1676511391667; Wed, 15 Feb 2023 17:36:31 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:31 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 11/13] dt-bindings: leds: Document netdev trigger Date: Thu, 16 Feb 2023 02:32:28 +0100 Message-Id: <20230216013230.22978-12-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Document the netdev trigger that makes the LED blink or turn on based on switch/phy events or an attached network interface. Signed-off-by: Christian Marangi --- Documentation/devicetree/bindings/leds/common.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml index d34bb58c0037..6e016415a4d8 100644 --- a/Documentation/devicetree/bindings/leds/common.yaml +++ b/Documentation/devicetree/bindings/leds/common.yaml @@ -98,6 +98,8 @@ properties: # LED alters the brightness for the specified duration with one software # timer (requires "led-pattern" property) - pattern + # LED blink and turns on based on netdev events + - netdev - pattern: "^cpu[0-9]*$" - pattern: "^hci[0-9]+-power$" # LED is triggered by Bluetooth activity From patchwork Thu Feb 16 01:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654297 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 E3FFEC677F1 for ; Thu, 16 Feb 2023 01:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjBPBhg (ORCPT ); Wed, 15 Feb 2023 20:37:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229809AbjBPBhZ (ORCPT ); Wed, 15 Feb 2023 20:37:25 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEDC7460B5; Wed, 15 Feb 2023 17:36:34 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id s13-20020a05600c45cd00b003ddca7a2bcbso436629wmo.3; Wed, 15 Feb 2023 17:36:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=uTcoFKmrwtKXbMa5FAugHsIQ8yhWeFxvv6LPTwygdbQ=; b=XSoEXiByeWPpHfIqJQlbE7w36QGh178vjtpkbhJUGtG84VWiJSLVhHp0hDDS5AnzTj Obq7ppupjEKKAr+SUuLzJaoAYEJEAX7e1Qu+JpBZ/CmdqdD1meX05ECu9D+fNHCIdFAB MLW44RF+XOS8MV/F24zqNyNyoBxmTXLqdlWAdla6ObXgkBbyXbCz2kJs3wLnCSBOx8DQ jSV/6iPIe+y1fcKdeIzBF3cVSKn3+IKr/gvWmpOAUmQhPkeRL1529XVaQasaRobyddsO RBhclyq0NfdSDS6qLzEHQZvyQn59w71JafsaAlUsdK+TmryrU46Sk4KF4OGa93eT2EbC YdtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=uTcoFKmrwtKXbMa5FAugHsIQ8yhWeFxvv6LPTwygdbQ=; b=cWyjq1jL8UcCeZNczAvoB+M8Q2K94duGvTbUeoM/+yy1JvCcJHDrgd4pMociH6+Rem C5o/KJfgJHVZ9ufiVj7Pfwsxxo6rK9aJQK0ANEoOPbi65zC3DcaXyTOgjufz5FU7vg2p zSscV49Mxr/auo+0alkruoUSUpWpA9ueyguRJctNEyhaONc9rFGF3ZVv8X5DOxKykFJV st2IDOwKOvVjQ/SEV3TNN9MJs+Vn1bPFRZ+4qKrjclb7/lLQ2L5vogk2RcQ3Z3mMvOXv USFwddYcJjUL3tTi7qJh3H2cMHs5IpHxiprfXiDDjuTtyHRjYSg7TxBz3BA7VQlf1xuu SEeA== X-Gm-Message-State: AO0yUKV5LU17XpgsoHx34VQQUmXjisXKtmWk1qkTDXg3mrDgHt+ooH54 NCpbGgwgqHqCZVNZsGuJ1gk= X-Google-Smtp-Source: AK7set/E1wkZ6srvhP22ltPxKprRdznZm5iP1MIP1So73+Ob+qVd4T38CJycWkjRYNZCtvR/vZGQLg== X-Received: by 2002:a05:600c:4d97:b0:3e2:6c8:65b with SMTP id v23-20020a05600c4d9700b003e206c8065bmr2187995wmp.25.1676511393145; Wed, 15 Feb 2023 17:36:33 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:32 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 12/13] dt-bindings: net: phy: Document support for leds node Date: Thu, 16 Feb 2023 02:32:29 +0100 Message-Id: <20230216013230.22978-13-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Document support for leds node in phy and add an example for it. Phy led will have to match led-phy pattern and should be treated as a generic led. Signed-off-by: Christian Marangi --- .../devicetree/bindings/net/ethernet-phy.yaml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml index 1327b81f15a2..34a5a688c13b 100644 --- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml @@ -197,6 +197,13 @@ properties: PHY's that have configurable TX internal delays. If this property is present then the PHY applies the TX delay. + leds: + type: object + + patternProperties: + '^led-phy(@[a-f0-9]+)?$': + $ref: /schemas/leds/common.yaml# + required: - reg @@ -204,6 +211,8 @@ additionalProperties: true examples: - | + #include + ethernet { #address-cells = <1>; #size-cells = <0>; @@ -219,5 +228,18 @@ examples: reset-gpios = <&gpio1 4 1>; reset-assert-us = <1000>; reset-deassert-us = <2000>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led-phy@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + linux,default-trigger = "netdev"; + }; + }; }; }; From patchwork Thu Feb 16 01:32:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 654694 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 848A9C636D6 for ; Thu, 16 Feb 2023 01:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbjBPBiC (ORCPT ); Wed, 15 Feb 2023 20:38:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbjBPBh3 (ORCPT ); Wed, 15 Feb 2023 20:37:29 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C86F945F70; Wed, 15 Feb 2023 17:36:43 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id y1so453699wru.2; Wed, 15 Feb 2023 17:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=+hZ4FOjKbPsdT5yxQsZyvCeHCblBaNw+opiskrre9LM=; b=Yzxas/XGAd0Vjd5xG2zHPk0/D0Hqne4JUyQ7KRQRg8tNWAXYVRsMePCDehMzhoAkS6 8Ul/yMSUhyVWmtdD+SzVGafo6NCDiZYWVD+BNFHNBvw6gIDuun04iBt6hyyD1vIYB0e8 4P81uWP50PllM0TETSnQmswhQeKQSLFV89NkjUD5h6EZ7xfMd+rtypMB0HJDkKwvV6WB iidWN59UyrS+sxjq0cZNthJMKmGTWV2I2kzGRW85e7g2MnHVv/BRIO4opKcXmwlGjwd9 7SLG/OJWtVNB6VNnE5sNMOJUpHoSZIhQ9rrpH67e/2/ujkv9cQm13nvXU4+y7ARgKm0e YFuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=+hZ4FOjKbPsdT5yxQsZyvCeHCblBaNw+opiskrre9LM=; b=1rkQrUGL4rpW56tIFnAVxrOoIzcG4F+JY07hVrqhmM0DXB3I4ee1xHCNk9+gBCIfBF i6Cp89Ds103wWqyBADAqcguLrGOXzTOGmflf9HaHCkmIDnSHV6d7qR/dEkuPsMkYD5fo Ww+rsMkgdbqzz8jEuXqW7+XHNUcoYB28XavcXyxSxv6xTUZFl7aN6c2of0L7wEdDXghl FnO05EMZJgMyOIIOHYL1NozNo8pttLrs5+6QN4fPT/il6MkDDlQyhh+bXWn1NDhsj8vD Adglu03DfslEeF0RtQvO3qyap6w3cg2nLKaGLhRFzJ6D3/j0uQ8Q9czRr+bECLEoGfAK 4vxA== X-Gm-Message-State: AO0yUKW3McdwoFpiyx9Rrb+r2+IJ3JfP1FS0klfkElvvh+UnkwB/GE32 WnXvpDoFUfEoSsoGPM+P2VM= X-Google-Smtp-Source: AK7set9cbwieqzJnsPgi/x1zFPNxp18QtOCEuGPVY3+sNpAUi4rY3xICSmOKfVUyElsilvF1C2mM/g== X-Received: by 2002:adf:fa4d:0:b0:2c5:4ffa:ba62 with SMTP id y13-20020adffa4d000000b002c54ffaba62mr2990533wrr.17.1676511394561; Wed, 15 Feb 2023 17:36:34 -0800 (PST) Received: from localhost.localdomain (93-34-91-73.ip49.fastwebnet.it. [93.34.91.73]) by smtp.googlemail.com with ESMTPSA id v15-20020a05600c214f00b003e1fb31fc2bsm64189wml.37.2023.02.15.17.36.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 17:36:34 -0800 (PST) From: Christian Marangi To: Pavel Machek , Lee Jones , Rob Herring , Krzysztof Kozlowski , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit , Russell King , Jonathan Corbet , Christian Marangi , "Russell King (Oracle)" , Jacek Anaszewski , John Crispin , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Tim Harvey , Alexander Stein , Rasmus Villemoes , Bagas Sanjaya , Arun.Ramadoss@microchip.com Subject: [PATCH v8 13/13] dt-bindings: net: dsa: qca8k: add LEDs definition example Date: Thu, 16 Feb 2023 02:32:30 +0100 Message-Id: <20230216013230.22978-14-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230216013230.22978-1-ansuelsmth@gmail.com> References: <20230216013230.22978-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add LEDs definition example for qca8k using the offload trigger as the default trigger and add all the supported offload triggers by the switch. Signed-off-by: Christian Marangi --- .../devicetree/bindings/net/dsa/qca8k.yaml | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/qca8k.yaml b/Documentation/devicetree/bindings/net/dsa/qca8k.yaml index 389892592aac..ba3821364039 100644 --- a/Documentation/devicetree/bindings/net/dsa/qca8k.yaml +++ b/Documentation/devicetree/bindings/net/dsa/qca8k.yaml @@ -18,6 +18,8 @@ description: PHY it is connected to. In this config, an internal mdio-bus is registered and the MDIO master is used for communication. Mixed external and internal mdio-bus configurations are not supported by the hardware. + Each phy have at least 3 LEDs connected and can be declared + using the standard LEDs structure. properties: compatible: @@ -117,6 +119,7 @@ unevaluatedProperties: false examples: - | #include + #include mdio { #address-cells = <1>; @@ -276,6 +279,27 @@ examples: internal_phy_port1: ethernet-phy@0 { reg = <0>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + linux,default-trigger = "netdev"; + }; + + led@1 { + reg = <1>; + color = ; + function = LED_FUNCTION_LAN; + function-enumerator = <1>; + linux,default-trigger = "netdev"; + }; + }; }; internal_phy_port2: ethernet-phy@1 {