From patchwork Sat May 27 11:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 687579 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67D64C7EE2C for ; Sat, 27 May 2023 11:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231620AbjE0LaA (ORCPT ); Sat, 27 May 2023 07:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232486AbjE0L3c (ORCPT ); Sat, 27 May 2023 07:29:32 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A34E10E; Sat, 27 May 2023 04:29:29 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f68fc6b479so17456815e9.2; Sat, 27 May 2023 04:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685186966; x=1687778966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=t032UqrKs2qK0Tmykkb/w0e10wBacVTlNSbQa7zNqmM=; b=BtKLeJJ6fl8D8E5IMrP9Oxr77Zt7QurslcYfR5GljVurKTTc5GRZccpr08y8UpmThl nQPxCuHPMkmroDFGSw/qNAU+qYz1bJy+klGJi5JgtZ1ETqGzKVzkRD27PT7r5Eb51y18 VT3xrNliCqVXK11joOG10TLSdMqyAXmOLslC0XWsHTDsx8FA0j2zTOicl9EVM37wBXdx aCuBAGkNU6gA2v83VqEEpjtW3Tt3IP/jgDRB27bMkaoaC/Gs1YjPHIrD8dDA4c/0usDr Bdo++hH7aVn9irKHKFtbp/R8im7SpHkb9KnpwnOd0x47R8fXofYkA2BsaTfnnq4nJ9NE J1PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685186966; x=1687778966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t032UqrKs2qK0Tmykkb/w0e10wBacVTlNSbQa7zNqmM=; b=V2qAHIPDinPCz+1nSmlhD3XQXNKNy7Vdx45VspTKaCTJYXNi3U5YI/mYejmKS7sSU8 aK3D3aVrJwfruPwbriJM8LzaiFKcebjAgrZgI5fo4jxK0fY1XMYxCghN8gCv4E7SC9Oq e8A8vOVw88euRK5WZ9ZHsz4YGcatslAYnmkuxX4gtVhGX62rrBbIDc65orraS+PeZvJf +gs2NT6npe/XAbYDCbJ50/lgmgJ7vJzWZr+jLoVInmjqC23VIhlKG+4ccRAt05fyHJTa lr90h0aVj5t+cIY62prlRc1VGSfLoDQf9kY5haIYntHnbo2BhoOmyiGvD5snYNOBoALk +GbQ== X-Gm-Message-State: AC+VfDzics8kJqJVFQwwdUWjxmb/hqNKJ6W3PIq+GlXn7FZEKiKXTTZH wfwYMk3xHFn6e/swwdHoO2E= X-Google-Smtp-Source: ACHHUZ42ImUe7BEsBhYL4fF76zPWy0NTUQC2m5IjDGbQpJKn6UtUD18UbfN/McWUMIzEQH5gAzpVdA== X-Received: by 2002:a05:600c:2209:b0:3f6:15f:e401 with SMTP id z9-20020a05600c220900b003f6015fe401mr3869447wml.37.1685186966404; Sat, 27 May 2023 04:29:26 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id q13-20020a7bce8d000000b003f43f82001asm11711000wmj.31.2023.05.27.04.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 04:29:25 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , Jonathan Corbet , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Marangi , linux-leds@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [net-next PATCH v3 10/13] leds: trigger: netdev: init mode if hw control already active Date: Sat, 27 May 2023 13:28:51 +0200 Message-Id: <20230527112854.2366-11-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230527112854.2366-1-ansuelsmth@gmail.com> References: <20230527112854.2366-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org On netdev trigger activation, hw control may be already active by default. If this is the case and a device is actually provided by hw_control_get_device(), init the already active mode and set the bool to hw_control bool to true to reflect the already set mode in the trigger_data. Co-developed-by: Andrew Lunn Signed-off-by: Andrew Lunn Signed-off-by: Christian Marangi --- drivers/leds/trigger/ledtrig-netdev.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 5b59441fc415..b0cab2b84ce2 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -452,6 +452,8 @@ static void netdev_trig_work(struct work_struct *work) static int netdev_trig_activate(struct led_classdev *led_cdev) { struct led_netdev_data *trigger_data; + unsigned long mode; + struct device *dev; int rc; trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); @@ -473,6 +475,21 @@ static int netdev_trig_activate(struct led_classdev *led_cdev) atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); trigger_data->last_activity = 0; + /* Check if hw control is active by default on the LED. + * Init already enabled mode in hw control. + */ + if (supports_hw_control(led_cdev) && + !led_cdev->hw_control_get(led_cdev, &mode)) { + dev = led_cdev->hw_control_get_device(led_cdev); + if (dev) { + const char *name = dev_name(dev); + + set_device_name(trigger_data, name, strlen(name)); + trigger_data->hw_control = true; + trigger_data->mode = mode; + } + } + led_set_trigger_data(led_cdev, trigger_data); rc = register_netdevice_notifier(&trigger_data->notifier);