Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3601044pxb; Mon, 24 Jan 2022 13:14:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbC6xM3q9cY73F0wo+dyYtgOXVjfxCi2cqF+eyQBQxulRNRkN79q4vGEK1jax/4eZFZQgO X-Received: by 2002:a17:90b:164a:: with SMTP id il10mr199650pjb.51.1643058874107; Mon, 24 Jan 2022 13:14:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643058874; cv=none; d=google.com; s=arc-20160816; b=yel9Z4GaAON/jj7cVBhl8IK+V3cYxaDpjj5FkmiWSk9vWOpg7DDOGRugcdLMjneIUr deFkV78JE77vmqCtrDobRHRm+LPmpqqbeir7YGpRbCMxsSJOPy4axk5Mp47L8lBYLKiy 6cwPwpiYRSRda22PiehBR9U6B9w0tQfGuHfY4pYK1HnSqbqAFub8gj+S2m5clG47eBOO b6S9KXIpzRVGRHyUaKRAutJyUeD1k7fbfXK4FSTfvX6yGihsChaV7ZZotrW1Vez0Vidc 2Bb6ml2BKikkvHtb2L0DJVyskW2JyC6n7dQ7GbOr+VqF+6UJMN3KVqBqne0w6OfmhIVo YdnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dXVcyviVwSLx5RAGORA+WsAO7m470mEYB+z3BcCp7RA=; b=QJglFMKpDEbcVQcHuvj2iP8QgQ4CmY4Xh6v0BzZXquMDNhXTfDMaYzEawNmyMC+4QP q+fMVGGTLZj5j2+lrMMjvUpwKIOGao3NbgztVHsa/ih4Ktamrw9xHtM72ozA0w30aIhP LNrscyMC9zdyB6uwU3vwSOX4g2cLsJv77n3+XPWiK7vV8oLdiCeSx4d3SKf1zqHmN9Ni iXxnzHi2Y99xOZcMnixXDUTL8qnQJKgdb6ZAUqIVhIOmXEeZqQRHGpcwBqNlZ+Vm9wjq jQ7m321Fd1XzocAvA3t7/docK55ikBnzXHVn01DyPtK6oWlpJ30rM9Uy5k3bpciT6/5h Jqzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CxMdtwUy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x185si7083164pgd.359.2022.01.24.13.14.19; Mon, 24 Jan 2022 13:14:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CxMdtwUy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351669AbiAXUoM (ORCPT + 99 others); Mon, 24 Jan 2022 15:44:12 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:33540 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382208AbiAXUZS (ORCPT ); Mon, 24 Jan 2022 15:25:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D0890B8122C; Mon, 24 Jan 2022 20:25:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A9BFC340E8; Mon, 24 Jan 2022 20:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055915; bh=C2yRUz42DqSxD6SVZ6vEK2YQtCMvqicsfk/FQJFLEfQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CxMdtwUydBNN46lQ+7UMAN+T5M8sftX2pM1ecrdXIhoPjpiOhK2pbTBb0TDjMhsCI iEOX4bIeBB6n5cqjyM49OOjBOc6+mQkd/FK98KHmRlH7r1G6fPnvVqFMiItAjEgedl uJqVa+N5YktjxLVx3WJnSvQwsu35afcCdOWKIaas= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marijn Suijten , AngeloGioacchino Del Regno , Daniel Thompson , Lee Jones , Sasha Levin Subject: [PATCH 5.15 291/846] backlight: qcom-wled: Respect enabled-strings in set_brightness Date: Mon, 24 Jan 2022 19:36:48 +0100 Message-Id: <20220124184110.972393777@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marijn Suijten [ Upstream commit ec961cf3241153e0f27d850f1bf0f172e7d27a21 ] The hardware is capable of controlling any non-contiguous sequence of LEDs specified in the DT using qcom,enabled-strings as u32 array, and this also follows from the DT-bindings documentation. The numbers specified in this array represent indices of the LED strings that are to be enabled and disabled. Its value is appropriately used to setup and enable string modules, but completely disregarded in the set_brightness paths which only iterate over the number of strings linearly. Take an example where only string 2 is enabled with qcom,enabled_strings=<2>: this string is appropriately enabled but subsequent brightness changes would have only touched the zero'th brightness register because num_strings is 1 here. This is simply addressed by looking up the string for this index in the enabled_strings array just like the other codepaths that iterate over num_strings. Likewise enabled_strings is now also used in the autodetection path for consistent behaviour: when a list of strings is specified in DT only those strings will be probed for autodetection, analogous to how the number of strings that need to be probed is already bound by qcom,num-strings. After all autodetection uses the set_brightness helpers to set an initial value, which could otherwise end up changing brightness on a different set of strings. Fixes: 775d2ffb4af6 ("backlight: qcom-wled: Restructure the driver for WLED3") Fixes: 03b2b5e86986 ("backlight: qcom-wled: Add support for WLED4 peripheral") Signed-off-by: Marijn Suijten Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Daniel Thompson Signed-off-by: Lee Jones Link: https://lore.kernel.org/r/20211115203459.1634079-10-marijn.suijten@somainline.org Signed-off-by: Sasha Levin --- drivers/video/backlight/qcom-wled.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c index 5306b06044b4f..f12c76d6e61de 100644 --- a/drivers/video/backlight/qcom-wled.c +++ b/drivers/video/backlight/qcom-wled.c @@ -237,7 +237,7 @@ static int wled3_set_brightness(struct wled *wled, u16 brightness) for (i = 0; i < wled->cfg.num_strings; ++i) { rc = regmap_bulk_write(wled->regmap, wled->ctrl_addr + - WLED3_SINK_REG_BRIGHT(i), + WLED3_SINK_REG_BRIGHT(wled->cfg.enabled_strings[i]), &v, sizeof(v)); if (rc < 0) return rc; @@ -260,7 +260,7 @@ static int wled4_set_brightness(struct wled *wled, u16 brightness) for (i = 0; i < wled->cfg.num_strings; ++i) { rc = regmap_bulk_write(wled->regmap, wled->sink_addr + - WLED4_SINK_REG_BRIGHT(i), + WLED4_SINK_REG_BRIGHT(wled->cfg.enabled_strings[i]), &v, sizeof(v)); if (rc < 0) return rc; @@ -571,7 +571,7 @@ unlock_mutex: static void wled_auto_string_detection(struct wled *wled) { - int rc = 0, i, delay_time_us; + int rc = 0, i, j, delay_time_us; u32 sink_config = 0; u8 sink_test = 0, sink_valid = 0, val; bool fault_set; @@ -618,14 +618,15 @@ static void wled_auto_string_detection(struct wled *wled) /* Iterate through the strings one by one */ for (i = 0; i < wled->cfg.num_strings; i++) { - sink_test = BIT((WLED4_SINK_REG_CURR_SINK_SHFT + i)); + j = wled->cfg.enabled_strings[i]; + sink_test = BIT((WLED4_SINK_REG_CURR_SINK_SHFT + j)); /* Enable feedback control */ rc = regmap_write(wled->regmap, wled->ctrl_addr + - WLED3_CTRL_REG_FEEDBACK_CONTROL, i + 1); + WLED3_CTRL_REG_FEEDBACK_CONTROL, j + 1); if (rc < 0) { dev_err(wled->dev, "Failed to enable feedback for SINK %d rc = %d\n", - i + 1, rc); + j + 1, rc); goto failed_detect; } @@ -634,7 +635,7 @@ static void wled_auto_string_detection(struct wled *wled) WLED4_SINK_REG_CURR_SINK, sink_test); if (rc < 0) { dev_err(wled->dev, "Failed to configure SINK %d rc=%d\n", - i + 1, rc); + j + 1, rc); goto failed_detect; } @@ -661,7 +662,7 @@ static void wled_auto_string_detection(struct wled *wled) if (fault_set) dev_dbg(wled->dev, "WLED OVP fault detected with SINK %d\n", - i + 1); + j + 1); else sink_valid |= sink_test; @@ -701,15 +702,16 @@ static void wled_auto_string_detection(struct wled *wled) /* Enable valid sinks */ if (wled->version == 4) { for (i = 0; i < wled->cfg.num_strings; i++) { + j = wled->cfg.enabled_strings[i]; if (sink_config & - BIT(WLED4_SINK_REG_CURR_SINK_SHFT + i)) + BIT(WLED4_SINK_REG_CURR_SINK_SHFT + j)) val = WLED4_SINK_REG_STR_MOD_MASK; else /* Disable modulator_en for unused sink */ val = 0; rc = regmap_write(wled->regmap, wled->sink_addr + - WLED4_SINK_REG_STR_MOD_EN(i), val); + WLED4_SINK_REG_STR_MOD_EN(j), val); if (rc < 0) { dev_err(wled->dev, "Failed to configure MODULATOR_EN rc=%d\n", rc); -- 2.34.1