From patchwork Fri Jul 14 12:14:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13313629 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BF6FC001DD for ; Fri, 14 Jul 2023 12:14:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 73B8510E880; Fri, 14 Jul 2023 12:14:52 +0000 (UTC) Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D51010E87B for ; Fri, 14 Jul 2023 12:14:49 +0000 (UTC) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4fba86f069bso3117309e87.3 for ; Fri, 14 Jul 2023 05:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689336887; x=1691928887; 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=u06tgDOD7cwIlWOvnR6QjrDtX4w5Uq2Dumh06lblnLk=; b=ZizL2KNz/0ekwzdN2fp2PsVPMxigv2//r6fIw5YtSY1gfA26UnViwFAwKYTeWE+ry1 J1mY/W0BMGlW8T0OqGzdODUNivKMJWVH4xzAVctXIIPNatG5gHyphQ4XsGzOmMM3TQBC QdkyetoY5N8aa96YceojRE2LJCSb7gkwLADV5FbwXaqGaO4PX9eqx0B+WLIZVyuJtwIB Yc5DwxgsZboK+aMDgrgpR3EWF3o5/yyd5r6Vn8zyPoCWEuZWK+M5R3q1Sw4iDOMZBK+M Re87sH+EYylefiUsfAgCRdm3rVXKnp6vmCtPT4dQGA0vDErYl53o1h4V0LTIYq4ymyO4 SYlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689336887; x=1691928887; 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=u06tgDOD7cwIlWOvnR6QjrDtX4w5Uq2Dumh06lblnLk=; b=MNn2wbiGNlhL6uA1eBR27HNcuSw3OMYw449kexpk7csiUYssKgjvwuG2x8nc4Zd2KQ kR2Tlo306WB9PSWmUVsnA9CPWQ5/UsZsXoKdsy7lDUfsncuER/6JuX3QeVUw1xCJCA18 hwffKnEVBtJv+EEJGaEW7XRsezZLo6n54P3NWNdMPy/s7bnH1oofTAFG3iSvmY2yxfVH F8nwAZSJ33zicO3wmsHZ9M7BR6DCtK5C2Nowh5KkYYh8NcMWZaN2Rn9QY8zf5AuaKuVr CWOjbhkmMaAYjleegT8870IL/4Z6E+MjoCgpHNM+4pu41ldnMFYfVvkHEk3TDph4a0By FXLg== X-Gm-Message-State: ABy/qLag27grnSK8BNrlwD9p/xKYHTZJy/VDat41BL26Bwke+N813WaV FnYuCFdJ8QCxdUc7gEXSWSMfJ+8fJW8= X-Google-Smtp-Source: APBJJlGNPi8pSZ8rf/rWqB+YjLfzQrM1dD3D5TWqynTfLfRfWzSrKRfBIO1TOT36Zd5dZpJAfkCn3g== X-Received: by 2002:a19:5003:0:b0:4fc:3756:754e with SMTP id e3-20020a195003000000b004fc3756754emr3201988lfb.56.1689336887104; Fri, 14 Jul 2023 05:14:47 -0700 (PDT) Received: from tablet.my.domain (ip-37-248-157-105.multi.internet.cyfrowypolsat.pl. [37.248.157.105]) by smtp.gmail.com with ESMTPSA id r16-20020aa7d150000000b0051e19bf66a4sm5680666edo.83.2023.07.14.05.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 05:14:46 -0700 (PDT) From: Artur Weber To: Lee Jones Subject: [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change Date: Fri, 14 Jul 2023 14:14:39 +0200 Message-ID: <20230714121440.7717-2-aweber.kernel@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230714121440.7717-1-aweber.kernel@gmail.com> References: <20230714121440.7717-1-aweber.kernel@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, Daniel Thompson , Artur Weber , Jingoo Han , Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Thierry Reding , ~postmarketos/upstreaming@lists.sr.ht, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" As pointed out by Uwe Kleine-König[1], the changes introduced in commit c1ff7da03e16 ("video: backlight: lp855x: Get PWM for PWM mode during probe") caused the PWM state set up by the bootloader to be re-set when the driver is probed. This differs from the behavior from before that patch, where the PWM state would be initialized on the first brightness change. Fix this by moving the PWM state initialization into the PWM control function. Add a new variable, needs_pwm_init, to the device info struct to allow us to check whether we need the initialization, or whether it has already been done. [1] https://lore.kernel.org/lkml/20230614083953.e4kkweddjz7wztby@pengutronix.de/ Fixes: c1ff7da03e16 ("video: backlight: lp855x: Get PWM for PWM mode during probe") Signed-off-by: Artur Weber Reviewed-by: Daniel Thompson --- drivers/video/backlight/lp855x_bl.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index 1c9e921bca14..349ec324bc1e 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -71,6 +71,7 @@ struct lp855x { struct device *dev; struct lp855x_platform_data *pdata; struct pwm_device *pwm; + bool needs_pwm_init; struct regulator *supply; /* regulator for VDD input */ struct regulator *enable; /* regulator for EN/VDDIO input */ }; @@ -220,7 +221,15 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) { struct pwm_state state; - pwm_get_state(lp->pwm, &state); + if (lp->needs_pwm_init) { + pwm_init_state(lp->pwm, &state); + /* Legacy platform data compatibility */ + if (lp->pdata->period_ns > 0) + state.period = lp->pdata->period_ns; + lp->needs_pwm_init = false; + } else { + pwm_get_state(lp->pwm, &state); + } state.duty_cycle = div_u64(br * state.period, max_br); state.enabled = state.duty_cycle; @@ -387,7 +396,6 @@ static int lp855x_probe(struct i2c_client *cl) const struct i2c_device_id *id = i2c_client_get_device_id(cl); const struct acpi_device_id *acpi_id = NULL; struct device *dev = &cl->dev; - struct pwm_state pwmstate; struct lp855x *lp; int ret; @@ -470,15 +478,11 @@ static int lp855x_probe(struct i2c_client *cl) else return dev_err_probe(dev, ret, "getting PWM\n"); + lp->needs_pwm_init = false; lp->mode = REGISTER_BASED; dev_dbg(dev, "mode: register based\n"); } else { - pwm_init_state(lp->pwm, &pwmstate); - /* Legacy platform data compatibility */ - if (lp->pdata->period_ns > 0) - pwmstate.period = lp->pdata->period_ns; - pwm_apply_state(lp->pwm, &pwmstate); - + lp->needs_pwm_init = true; lp->mode = PWM_BASED; dev_dbg(dev, "mode: PWM based\n"); } From patchwork Fri Jul 14 12:14:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artur Weber X-Patchwork-Id: 13313630 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2AD9EB64DA for ; Fri, 14 Jul 2023 12:14:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 74BD610E881; Fri, 14 Jul 2023 12:14:53 +0000 (UTC) Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by gabe.freedesktop.org (Postfix) with ESMTPS id 375F910E87E for ; Fri, 14 Jul 2023 12:14:51 +0000 (UTC) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-51e590a8ab5so2319647a12.2 for ; Fri, 14 Jul 2023 05:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689336889; x=1691928889; 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=TgPMyqhcYOSoB/wLOssO63qlIlM49Q140+nxqiBvG58=; b=EbmcQKgul6r57U77VkLKxO0Std3+UK3ldoAw+5il/pbmMcEIV1j+yevY/ZXv9VkR1J +/4YKAtOae75xN9J3tA3yU6G/kVO8Gp0bFwl5dIJuAwF2wZIh3TyV4U7YEdginHL/7Wb 7Q1POHwuTeLeqtDaHV/M3Jf86N/52phGiATyqOFX3N/F+/oJdH8fEQuZ8P4tssx7VF0i cnKyIvsUWZ8cnnyPsUwLjS0mxRidx3JCST4tNTSARsNIg+Uq4qVposX3W9wSB2mTqIYb deDgxSM8kXx180pIPlKeKPAAvQEkHfxRwlsp0RxiOIOL/chzdSVfhdoEG8qejnhK4qJg EGMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689336889; x=1691928889; 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=TgPMyqhcYOSoB/wLOssO63qlIlM49Q140+nxqiBvG58=; b=IA1xmknX+HzPKXEbOiq3uM4GR6exhsxeve3Ek/lI/wU86d42DmOHrX8KS6Ym167DGw ajE09YiZPSPxKTbOc5URarOEHh4xhh7+7bkToun/cLLA1qUXyBR/9jvqCKYQ1Jk4nN9z wuAsppXPpVd5E1ucsMHFDZ2q/TnnoUN1GTQVez3solit2dsv3yHL1egS768/0oHRGxsu AcKJzZKdb34C6djfn1Tfs8XAy9w3dbriLfR3JN3FObRxI7Sq8SEsr5HaOjoMtamkbd4S sa5RmQ8J4dWF37nU1spwuYXGd5xHLDDMVjfNuawNWLXCaAz4r780/WRWdKLyWE6q26S3 hNow== X-Gm-Message-State: ABy/qLbu31aUGbXLmjIu2ELE+UdW7Ev8++qamhvsAC+rvc59Z7N03thQ 0pZC6IYsbfY8i3LN1PPzKRk= X-Google-Smtp-Source: APBJJlGCZk5eIAzsAIRe5sakyckPhJ0aqKFTBus5ia20xD48WrEFzxV5rsu/e+vLMLzskRlnKNWdwQ== X-Received: by 2002:a50:fa98:0:b0:51e:4bc7:3976 with SMTP id w24-20020a50fa98000000b0051e4bc73976mr5022133edr.10.1689336888953; Fri, 14 Jul 2023 05:14:48 -0700 (PDT) Received: from tablet.my.domain (ip-37-248-157-105.multi.internet.cyfrowypolsat.pl. [37.248.157.105]) by smtp.gmail.com with ESMTPSA id r16-20020aa7d150000000b0051e19bf66a4sm5680666edo.83.2023.07.14.05.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 05:14:48 -0700 (PDT) From: Artur Weber To: Lee Jones Subject: [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness Date: Fri, 14 Jul 2023 14:14:40 +0200 Message-ID: <20230714121440.7717-3-aweber.kernel@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230714121440.7717-1-aweber.kernel@gmail.com> References: <20230714121440.7717-1-aweber.kernel@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, Daniel Thompson , Artur Weber , Jingoo Han , Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Thierry Reding , ~postmarketos/upstreaming@lists.sr.ht, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The lp855x_bl_update_status function's return type is int, but it always returns 0, without checking for the results of the write_byte/pwm_ctrl functions called within. Make this function return the return values of the functions it calls, and modify the lp855x_pwm_ctrl function to return errors. Signed-off-by: Artur Weber Reviewed-by: Daniel Thompson --- drivers/video/backlight/lp855x_bl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c index 349ec324bc1e..61a7f45bfad8 100644 --- a/drivers/video/backlight/lp855x_bl.c +++ b/drivers/video/backlight/lp855x_bl.c @@ -217,7 +217,7 @@ static int lp855x_configure(struct lp855x *lp) return ret; } -static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) +static int lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) { struct pwm_state state; @@ -234,23 +234,26 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br) state.duty_cycle = div_u64(br * state.period, max_br); state.enabled = state.duty_cycle; - pwm_apply_state(lp->pwm, &state); + return pwm_apply_state(lp->pwm, &state); } static int lp855x_bl_update_status(struct backlight_device *bl) { struct lp855x *lp = bl_get_data(bl); int brightness = bl->props.brightness; + int ret; if (bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) brightness = 0; if (lp->mode == PWM_BASED) - lp855x_pwm_ctrl(lp, brightness, bl->props.max_brightness); + ret = lp855x_pwm_ctrl(lp, brightness, + bl->props.max_brightness); else if (lp->mode == REGISTER_BASED) - lp855x_write_byte(lp, lp->cfg->reg_brightness, (u8)brightness); + ret = lp855x_write_byte(lp, lp->cfg->reg_brightness, + (u8)brightness); - return 0; + return ret; } static const struct backlight_ops lp855x_bl_ops = {