From patchwork Mon Dec 2 12:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Riepler X-Patchwork-Id: 847479 Received: from sender2-op-o11.zoho.eu (sender2-op-o11.zoho.eu [136.143.171.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9A80205AD5; Mon, 2 Dec 2024 12:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.171.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733141294; cv=pass; b=ObmTZlBatafvvP0F6IlXAXziIWD0xpw8ZwB/9FN2Cq29VSUb6mhnLEsCA3AGNpEOxNCNDPEJwzlhIMLwFTE7lqngb30Lc+0Ju9j83cAejUc4LQCXbuYeLUKAdU14zgx8MaVPdGXCQTWqnulGNjNoHu9nD5JcA/n/NuaDcwQ9bQk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733141294; c=relaxed/simple; bh=hHFka5L2zVORZlNG1xvolgyFI+LGuuqcR6ENNyanQ+U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ngcETZAFyPo551HkIAl7i2kYQpziHyWB7pOipFVGHww4/3sUBMG90nqyXEDhpyoBSu5ebL6Fa9Vxbv5BidEzIeZ3FQIsL0axKuF9bBwAgY5PxjA6YerQL1Qm4CHHIG/+w9Pr5kLFHWvSW7yFYMzWJn1pDzu3xRFvH3cfzUlexvg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chaosfield.at; spf=pass smtp.mailfrom=chaosfield.at; dkim=pass (1024-bit key) header.d=chaosfield.at header.i=jakob+lkml@chaosfield.at header.b=DQnLpBQM; arc=pass smtp.client-ip=136.143.171.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chaosfield.at Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosfield.at Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosfield.at header.i=jakob+lkml@chaosfield.at header.b="DQnLpBQM" ARC-Seal: i=1; a=rsa-sha256; t=1733141276; cv=none; d=zohomail.eu; s=zohoarc; b=ic9ejCH1Wzo/gP2ZAjrCMCGRn0xNhXMo0F4THnYLAMn261HP6VtLBF4FKRao9MJu93Sqm1L5KstGMhZLZGNzDkSuSw0o2FR1Zg5crYfl2jCOCaQYzuBGlY/6anEsdhTBmLDEeb3Y3mBtp7yrEqic4gEgPitOakXKzuf4JXvG3wE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1733141276; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=BMV9SMnLebQrEW79GXBEprl8gCg+plSDoj9lVar/fxY=; b=kjTqduZ/huYbM3WO9LEaWjmS0NIGETJZXSon8p2YnWXZjYY9YWXKJ7eFGBKKsYb7sgeW9qC610Y9Zj2D31byXB6PavLiVWw1+yz2F+eY0+T75aKFa0r6QFw8SCeRNTK5mwy0EV/0aJEdXwtiqLYThnQgYSYemH7VDZ9YfLMzFlA= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=chaosfield.at; spf=pass smtp.mailfrom=jakob+lkml@chaosfield.at; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1733141276; s=zohoeu1; d=chaosfield.at; i=jakob+lkml@chaosfield.at; h=Message-ID:Date:Date:MIME-Version:Subject:Subject:To:To:Cc:Cc:References:From:From:In-Reply-To:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=BMV9SMnLebQrEW79GXBEprl8gCg+plSDoj9lVar/fxY=; b=DQnLpBQM/g2VhVYaqcmyN2NN6dhIywA3mLcS2u4yCZvApsby2dNriC8LWKorLnX/ eCvqon+ZtWmqMMgqJfJQXiVu74e5AHlGM/y5OUESJZsCCWxwWJrw3zr+tR09PgfE4zZ PFOcFD7/keDQPOZiLmpAii671VXqwkuAn9fIfHiY= Received: by mx.zoho.eu with SMTPS id 1733141272255861.7005327403868; Mon, 2 Dec 2024 13:07:52 +0100 (CET) Message-ID: <50bbd767-b0e0-4788-975b-f5d9598208e5@chaosfield.at> Date: Mon, 2 Dec 2024 13:07:51 +0100 Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2] leds: pwm-multicolor: Disable PWM when going to suspend To: Pavel Machek , Lee Jones Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Uwe_?= =?utf-8?q?Kleine-K=C3=B6nig?= References: Content-Language: en-US From: Jakob Riepler In-Reply-To: X-ZohoMailClient: External This fixes suspend on platforms like stm32mp1xx, where the PWM consumer has to be disabled for the PWM to enter suspend. Another positive side effect is that active-low LEDs now properly turn off instead of going back to full brightness when they are set to 0. Link: https://lore.kernel.org/all/20240417153846.271751-2-u.kleine-koenig@pengutronix.de/ Signed-off-by: Jakob Riepler Acked-by: Uwe Kleine-König Acked-by: Uwe Kleine-König --- Changes in v2:  - fix wrong line-breaks in patch  drivers/leds/rgb/leds-pwm-multicolor.c | 8 +++++++-  1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/leds/rgb/leds-pwm-multicolor.c b/drivers/leds/rgb/leds-pwm-multicolor.c index e1a81e0109e8..f80a06cc31f8 100644 --- a/drivers/leds/rgb/leds-pwm-multicolor.c +++ b/drivers/leds/rgb/leds-pwm-multicolor.c @@ -50,7 +50,13 @@ static int led_pwm_mc_set(struct led_classdev *cdev,              duty = priv->leds[i].state.period - duty;            priv->leds[i].state.duty_cycle = duty; -        priv->leds[i].state.enabled = duty > 0; +        /* +         * Disabling a PWM doesn't guarantee that it emits the inactive level. +         * So keep it on. Only for suspending the PWM should be disabled because +         * otherwise it refuses to suspend. The possible downside is that the +         * LED might stay (or even go) on. +         */ +        priv->leds[i].state.enabled = !(cdev->flags & LED_SUSPENDED);          ret = pwm_apply_might_sleep(priv->leds[i].pwm,                          &priv->leds[i].state);          if (ret)