From patchwork Thu Jul 14 21:53:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ma=C3=ADra_Canal?= X-Patchwork-Id: 12918519 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 90C0CC43334 for ; Thu, 14 Jul 2022 21:53:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbiGNVxt (ORCPT ); Thu, 14 Jul 2022 17:53:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232299AbiGNVxr (ORCPT ); Thu, 14 Jul 2022 17:53:47 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B340DDFA8; Thu, 14 Jul 2022 14:53:45 -0700 (PDT) Received: from mx0.riseup.net (mx0-pn.riseup.net [10.0.1.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mx0.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4LkStK2Nx3zDrjw; Thu, 14 Jul 2022 21:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1657835625; bh=Ex8sIbN7b3m/ryXhpiacHfviSvoH7OHIsjjT3wLtN/o=; h=From:To:Cc:Subject:Date:From; b=oR7vvOz7jLJOl1v9DVgEzyVj1trqCsMaNpRoUnFxce/NzPzGLxNi/xu4c6dCd9Fb/ RBrths/1uTQiS9D91GEd4cKLa9bMQvXwlTPTFkByks9Pj+apPrwQkpeOpgJrkQjKjH 3LjL+pVODd4amcH8ABYXIq+btTM2p8asbkPzk9PI= Received: from fews1.riseup.net (fews1-pn.riseup.net [10.0.1.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx0.riseup.net (Postfix) with ESMTPS id 4LkStJ34j8z9tCY; Thu, 14 Jul 2022 21:53:44 +0000 (UTC) X-Riseup-User-ID: B2AE8FB5CD960AF3F6CB82DB39E7CC9A82DE79F371A66BF223551A361A6589AF Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4LkStD4pQTz5vW1; Thu, 14 Jul 2022 21:53:40 +0000 (UTC) From: =?utf-8?q?Ma=C3=ADra_Canal?= To: daniel.thompson@linaro.org, lee.jones@linaro.org, jingoohan1@gmail.com, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Cc: dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, =?utf-8?q?Ma=C3=AD?= =?utf-8?q?ra_Canal?= Subject: [PATCH RESEND v6] backlight: lp855x: Switch to atomic PWM API Date: Thu, 14 Jul 2022 18:53:34 -0300 Message-Id: <20220714215334.78226-1-mairacanal@riseup.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Remove legacy PWM interface (pwm_config, pwm_enable, pwm_disable) and replace it for the atomic PWM API. Reviewed-by: Uwe Kleine-König Reviewed-by: Daniel Thompson Signed-off-by: Maíra Canal --- V1 -> V2: Initialize variable and simplify conditional loop V2 -> V3: Fix assignment of NULL variable V3 -> V4: Replace division for pwm_set_relative_duty_cycle V4 -> V5: Fix overwrite of state.period V5 -> V6: Fix duty cycle rounding and set period outside conditional loop --- drivers/video/backlight/lp855x_bl.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index 2b9e2bbbb03e..fc02c5c16055 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -218,9 +218,8 @@ static int lp855x_configure(struct lp855x *lp) static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) { - unsigned int period = lp->pdata->period_ns; - unsigned int duty = br * period / max_br; struct pwm_device *pwm; + struct pwm_state state; /* request pwm device with the consumer name */ if (!lp->pwm) { @@ -230,18 +229,16 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) lp->pwm = pwm; - /* - * FIXME: pwm_apply_args() should be removed when switching to - * the atomic PWM API. - */ - pwm_apply_args(pwm); + pwm_init_state(lp->pwm, &state); + } else { + pwm_get_state(lp->pwm, &state); } - pwm_config(lp->pwm, duty, period); - if (duty) - pwm_enable(lp->pwm); - else - pwm_disable(lp->pwm); + state.period = lp->pdata->period_ns; + state.duty_cycle = div_u64(br * state.period, max_br); + state.enabled = state.duty_cycle; + + pwm_apply_state(lp->pwm, &state); } static int lp855x_bl_update_status(struct backlight_device *bl)