From patchwork Mon Jan 23 16:06:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 47229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1696357wrn; Mon, 23 Jan 2023 08:23:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXtfd/ikZW8L24vsRcRXdJwpsszXYPUNBiM3yRd4v3VSXQP1+t+1XzQG+2MHNQq/W6M1dvsL X-Received: by 2002:aa7:d294:0:b0:49e:1d59:7954 with SMTP id w20-20020aa7d294000000b0049e1d597954mr27664983edq.26.1674491008957; Mon, 23 Jan 2023 08:23:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674491008; cv=none; d=google.com; s=arc-20160816; b=CUiTgd7jXa+HGpZ4t8tO3FNKqaXxpxD+yVTjQ0TzwNKFYffsGl7dJYOeYxaXAngZhC ObKaW5otkIgmB1ow/94PBr82hgISthmcLq0m4JOGtOD75ApxI98dU8EX/xJg6nMqsMkg zXxiPwx+EeqTm+RbEZTLXdVH7MJxnKZOh1WlWB34jHEPVVMMPBBB1bGwA71MeF62nQjE Umvzi0DnJ1BlGMMpfduRY1oOh9T44novtm1jzfEQb+1U5fIbwE7c1qnUwoewUQX7SW2i te1R79BxCzd7R5NXhDUQuqM7mNkHzjmc1ehpPrWPolTXtHETKzlwubj7d5wZX+NDJCQr ZKqg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u64mIc1Gnk/nfVHUFq6LwDdDW2ZizF8uHVYCr+kRadM=; b=u37LpDiYzvkt5yu4fEyRnXp+bHf3uyfZP5/Cs8BFa9VG5pPRNqEg9zbPvZNSCGCBgy XyDIRUaYtbXcNFWhHv7OPlEkXIdUBoeh0zx2Zgqis9NfbIvT8hSj/UdkglF11Jc7lzpg AzFLfsNiRVQsfzeMYgf0uC9YL1M9+9lrQWFmerqfyRBLYXMvaP3gl4iavRaukaNWXugd zP1aRE7hE1Uom3nlgB8Ssmvj6GGTUsxM2DeJ0lyDONCAIJ9AsthfytIl+afM0Y7ZIDH6 slVWsx2FK0arIY3KNaskCwgaxSP9z+LWRzBMvL4F72XZ2SWGVfrLC+tqNfvafXFQD2vP eAQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=l5xAWlcW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r28-20020a50c01c000000b00461c50013b8si55300096edb.192.2023.01.23.08.23.05; Mon, 23 Jan 2023 08:23:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=l5xAWlcW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232249AbjAWQGZ (ORCPT + 99 others); Mon, 23 Jan 2023 11:06:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231659AbjAWQGY (ORCPT ); Mon, 23 Jan 2023 11:06:24 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6ECCDE7; Mon, 23 Jan 2023 08:06:23 -0800 (PST) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 5DDD86602E1B; Mon, 23 Jan 2023 16:06:21 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1674489982; bh=E4V4fApG7LhWq16TtQ6eUGLIDwf3PHKpT4N6BRwMD5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l5xAWlcWUx08oMvA/eWOdsbcrOR+U3pZbcBjQpt/BPWZXP/Z21nBhIWLQbkqj54c0 j/hIJ+LkGsFm01jMo7nggTEdPMsd3ONZ+oFesVc+Cp5dJNH3DBxKEYvRNhc6Hij8pI GMn1mEzBCzkS5MKjK9TiEqL02e2WKAA36WLo9LGBNmHjeVoCMcWE8sl7KotR/rQaj2 CVohRzLs3nQeKYqs7RQ45Dkq9NAlv1BOHhdcPFWZSDMbmsq7S4dVFQ/7RmDgZJvSHW 6Oy6JPzdJ3qATiOKqWVdKepRX3zTiOg2I5/U2IwXX+Lljt64IBiXYrky3h43JmRML+ rkLbhMIZuMJ/Q== From: AngeloGioacchino Del Regno To: thierry.reding@gmail.com Cc: u.kleine-koenig@pengutronix.de, matthias.bgg@gmail.com, weiqing.kong@mediatek.com, jitao.shi@mediatek.com, linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@collabora.com, AngeloGioacchino Del Regno Subject: [PATCH 1/2] pwm: mtk-disp: Disable shadow registers before setting backlight values Date: Mon, 23 Jan 2023 17:06:14 +0100 Message-Id: <20230123160615.375969-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123160615.375969-1-angelogioacchino.delregno@collabora.com> References: <20230123160615.375969-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755831083900030472?= X-GMAIL-MSGID: =?utf-8?q?1755831083900030472?= If shadow registers usage is not desired, disable that before performing any write to CON0/1 registers in the .apply() callback, otherwise we may lose clkdiv or period/width updates. Fixes: cd4b45ac449a ("pwm: Add MediaTek MT2701 display PWM driver support") Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Nícolas F. R. A. Prado Tested-by: Nícolas F. R. A. Prado --- drivers/pwm/pwm-mtk-disp.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index 692a06121b28..82b430d881a2 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -138,6 +138,19 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, high_width = mul_u64_u64_div_u64(state->duty_cycle, rate, div); value = period | (high_width << PWM_HIGH_WIDTH_SHIFT); + if (mdp->data->bls_debug && !mdp->data->has_commit) { + /* + * For MT2701, disable double buffer before writing register + * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. + */ + mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, + mdp->data->bls_debug_mask, + mdp->data->bls_debug_mask); + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, + mdp->data->con0_sel, + mdp->data->con0_sel); + } + mtk_disp_pwm_update_bits(mdp, mdp->data->con0, PWM_CLKDIV_MASK, clk_div << PWM_CLKDIV_SHIFT); @@ -152,17 +165,6 @@ static int mtk_disp_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, mtk_disp_pwm_update_bits(mdp, mdp->data->commit, mdp->data->commit_mask, 0x0); - } else { - /* - * For MT2701, disable double buffer before writing register - * and select manual mode and use PWM_PERIOD/PWM_HIGH_WIDTH. - */ - mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, - mdp->data->bls_debug_mask, - mdp->data->bls_debug_mask); - mtk_disp_pwm_update_bits(mdp, mdp->data->con0, - mdp->data->con0_sel, - mdp->data->con0_sel); } mtk_disp_pwm_update_bits(mdp, DISP_PWM_EN, mdp->data->enable_mask, From patchwork Mon Jan 23 16:06:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 47230 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1696546wrn; Mon, 23 Jan 2023 08:23:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXv98hoNIbR9NOvqRUz70gZFwM1hnCU0V/CsOCqQhTD8TNwKpPFKL4V5xp7KvNcQ4n+1XutK X-Received: by 2002:a17:906:230a:b0:86f:5375:9f63 with SMTP id l10-20020a170906230a00b0086f53759f63mr24454809eja.39.1674491035665; Mon, 23 Jan 2023 08:23:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674491035; cv=none; d=google.com; s=arc-20160816; b=T8eRykDbZUgsvL+w3jL4GE0G0QnYCJr8mcXovYVKd+K7XSQ4w5WDcfvs/pWGltc6Ep 4788w7i8q7lVlcCXQeJ3CP4iRH/qxqK53+ts6c0I5dtfklJvWCVU3r55NXPagG5hlmP/ 24DVENjZtuD/BZXbe/KSyqJ4Ai7H6atdODn9H9g5RW+FV2HpQftA6C2xpSZTEL3Es5pA andwbxBIMjqvrv0OlNbJ45sJ5UexAmR0cf4wjD9Mtw+P1kphSLgVjTt+6LhSAb04n8ok bjT9M+uizYys/HsViBuPZMpFpZhOKyKeruYbCqpYXNRD/9itlZ0xfHZYxvUTwce7QX20 5b+g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1hgLz6o6NOhRQW3qOtoP4+/IX9vTrGiJtyHS7zEj4CE=; b=apeH5tFWQGeTRE2sv4K/a4mVmpiZ+UwIcfLf9o9C8KBEUUDja6bo9d1kocT8OgQp7M fGMttIGzxpmRMFOVrpX8G8vDjE5ZOXKa1yuZNO4PLvKopD1P7THFqtnm/hxiOQqgQD0s d0HBppkqAwH2w6D8qqFymY6a5ez+LQ2GfW3TBmHoc3xFFglZvyHH87A8udy0UXxBvOWI hjbEkymdIkWXCFDjdCnjoiABNPlRjxUa59iYOgHJvG6Xa6nKLm1ErFZWwsXhbUnlGCgM BXg753ez7D7SG7lgtiwSbG+5pFp3ULnjx9YQtWhSyIX8GRQNDkT3yvDSpC+/VZeuxBt1 PZlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="H3V1YsI/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq15-20020a1709073f0f00b0087255f93509si22325926ejc.1004.2023.01.23.08.23.10; Mon, 23 Jan 2023 08:23:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="H3V1YsI/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233054AbjAWQG3 (ORCPT + 99 others); Mon, 23 Jan 2023 11:06:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjAWQGY (ORCPT ); Mon, 23 Jan 2023 11:06:24 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE0EAD529; Mon, 23 Jan 2023 08:06:23 -0800 (PST) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 270926602E39; Mon, 23 Jan 2023 16:06:22 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1674489982; bh=a//s0VQPI4VdLC1yskDrbe3IDSo3z5asw/jCKWGhMlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H3V1YsI/b+cbffNHubYqbr0HJ7rUbYaejxLw+JGWCgYDdM4NWGo0N/D08482o4TqI Q7R9Lgt+M023xCUnAiQW3HEviuOqk69dXNzV4ufWXNyeu2bsGKhruDo+bTCOmEEge0 XNdHYZvCYM6D5fd5MjSgG5CET4ba2iqhmaL5xOuzGhhZg/41scThqm58W/HPG/1m/h DpRqNnV9teGc9T/zLhYqu0wF63mlmAgNUuZcPofkwCBGTPJyUlbQuuSR2a0JwCqCRi QNSOCcBPUNP61fNPQT1XTA5TvaOp/SmZuLGfROcw6GrKnoRbNit1RyeEcXivfrdb1A 6yW8j4K1va6JQ== From: AngeloGioacchino Del Regno To: thierry.reding@gmail.com Cc: u.kleine-koenig@pengutronix.de, matthias.bgg@gmail.com, weiqing.kong@mediatek.com, jitao.shi@mediatek.com, linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@collabora.com, AngeloGioacchino Del Regno Subject: [PATCH 2/2] pwm: mtk-disp: Configure double buffering before reading in .get_state() Date: Mon, 23 Jan 2023 17:06:15 +0100 Message-Id: <20230123160615.375969-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230123160615.375969-1-angelogioacchino.delregno@collabora.com> References: <20230123160615.375969-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755831112319944536?= X-GMAIL-MSGID: =?utf-8?q?1755831112319944536?= The DISP_PWM controller's default behavior is to always use register double buffering: all reads/writes are then performed on shadow registers instead of working registers and this becomes an issue in case our chosen configuration in Linux is different from the default (or from the one that was pre-applied by the bootloader). An example of broken behavior is when the controller is configured to use shadow registers, but this driver wants to configure it otherwise: what happens is that the .get_state() callback is called right after registering the pwmchip and checks whether the PWM is enabled by reading the DISP_PWM_EN register; At this point, if shadow registers are enabled but their content was not committed before booting Linux, we are *not* reading the current PWM enablement status, leading to the kernel knowing that the hardware is actually enabled when, in reality, it's not. The aforementioned issue emerged since this driver was fixed with commit 0b5ef3429d8f ("pwm: mtk-disp: Fix the parameters calculated by the enabled flag of disp_pwm") making it to read the enablement status from the right register. Configure the controller in the .get_state() callback to avoid this desync issue and get the backlight properly working again. Fixes: 3f2b16734914 ("pwm: mtk-disp: Implement atomic API .get_state()") Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Nícolas F. R. A. Prado Tested-by: Nícolas F. R. A. Prado --- drivers/pwm/pwm-mtk-disp.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c index 82b430d881a2..fe9593f968ee 100644 --- a/drivers/pwm/pwm-mtk-disp.c +++ b/drivers/pwm/pwm-mtk-disp.c @@ -196,6 +196,16 @@ static int mtk_disp_pwm_get_state(struct pwm_chip *chip, return err; } + /* + * Apply DISP_PWM_DEBUG settings to choose whether to enable or disable + * registers double buffer and manual commit to working register before + * performing any read/write operation + */ + if (mdp->data->bls_debug) + mtk_disp_pwm_update_bits(mdp, mdp->data->bls_debug, + mdp->data->bls_debug_mask, + mdp->data->bls_debug_mask); + rate = clk_get_rate(mdp->clk_main); con0 = readl(mdp->base + mdp->data->con0); con1 = readl(mdp->base + mdp->data->con1);