From patchwork Fri Mar 10 19:14:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13169982 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 4CBE1C6FD19 for ; Fri, 10 Mar 2023 19:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=YwXeAzh8oBaVu9EpbuRm2Wa41NXFv7ZW8pD2x3hkOZ8=; b=eLtLt1vy30gMXS Rj8nQ3+XWeeNiaMjc6wU9rLx2OuilBmCS3cG2+iVfeXHUT3DEmCXB5KfWcKbj12X4dEn+TxqRgYE9 Ee6aLfXc/+Y59kMWqeGMadaLBSkWGsi/J63vjdLDiR4OWklBk2RhyMuWVFV2y4QGNn+51vcx1g0Hq fclH8NPjH3sq+ubT+pDD6lGgtxGqAC6u05QzSmT7+ZCptoyQwX9VQ5gcj32wn4nVBll1jelWSFjjw cQsQe/yHcDEwhAVzod4B4ViegHtMtHcx/RAIxkLvp8UB4AV3LcGSC1r+Ib4CM29fVAJ9BxJOo4B+c MZdvqmOMfTNt2P5a9+NA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1paiCF-00Fsvx-MT; Fri, 10 Mar 2023 19:14:31 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1paiC7-00Fstu-DR for linux-amlogic@lists.infradead.org; Fri, 10 Mar 2023 19:14:24 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1paiC0-00039I-AU; Fri, 10 Mar 2023 20:14:16 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1paiBz-003F4t-1o; Fri, 10 Mar 2023 20:14:15 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1paiBy-003s90-C1; Fri, 10 Mar 2023 20:14:14 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: Thierry Reding Cc: Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, Munehisa Kamata , kernel@pengutronix.de Subject: [PATCH] pwm: meson: Explicitly set .polarity in .get_state() Date: Fri, 10 Mar 2023 20:14:05 +0100 Message-Id: <20230310191405.2606296-1-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2146; i=u.kleine-koenig@pengutronix.de; h=from:subject; bh=AkvlThN+cI4a7dkV/VVfPk4VyPpzaAaoFocdrcBpL8w=; b=owEBbQGS/pANAwAKAcH8FHityuwJAcsmYgBkC4F69olWoJ7Ed8sEbDh/GIath8w3HSWFxFiab mqyHO9+FZqJATMEAAEKAB0WIQR+cioWkBis/z50pAvB/BR4rcrsCQUCZAuBegAKCRDB/BR4rcrs Cd1cCACRuq4c1vOJc5h+ju5vADCJKzKpVpiaqj7YLKTdWqMgE2/XsTqcRN7wE1LuoYXAj/cD/kI JEhpkS/9pfiN6KggwQnUPcv6eqw2hHGodfX6WMxbTAN/1iOI2fPWWTs8jK8XrQFZJJsLaa/DEav bPbvFVeAfaHXy/Qb7HM6J6grZZB1HA0IuLz8uW/jAi6hvMiAtCNrdSLXKTw+BxhF3RSd2aHD9DU LDlFiybwK6hYAIknDz6VkMG2GAduKOc8Ky8XcQWZXZ8LHggcDCNJL1Jg6uVlHv0c6ljmGCPfn/i JsNZZvcnjzmHzgNcjakO23YJoNWJ51LwDaMvKmhWHdDp72tz X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-amlogic@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230310_111423_461692_51A0E4C6 X-CRM114-Status: GOOD ( 16.38 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The driver only supports normal polarity. Complete the implementation of .get_state() by setting .polarity accordingly. This fixes a regression that was possible since commit c73a3107624d ("pwm: Handle .get_state() failures") which stopped to zero-initialize the state passed to the .get_state() callback. This was reported at https://forum.odroid.com/viewtopic.php?f=177&t=46360 . While this was an unintended side effect, the real issue is the driver's callback not setting the polarity. There is a complicating fact, that the .apply() callback fakes support for inversed polarity. This is not (and cannot) be matched by .get_state(). As fixing this isn't easy, only point it out in a comment to prevent authors of other drivers from copying that approach. Fixes: c375bcbaabdb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()") Reported-by: Munehisa Kamata Signed-off-by: Uwe Kleine-König Acked-by: Martin Blumenstingl --- Hello, similar to the patches for four other drivers[1], I think we should apply this patch as a fix. Best regards Uwe [1] https://lore.kernel.org/linux-pwm/20230228135508.1798428-1-u.kleine-koenig@pengutronix.de drivers/pwm/pwm-meson.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 16d79ca5d8f5..5cd7b90872c6 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -162,6 +162,12 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, duty = state->duty_cycle; period = state->period; + /* + * Note this is wrong. The result is an output wave that isn't really + * inverted and so is wrongly identified by .get_state as normal. + * Fixing this needs some care however as some machines might rely on + * this. + */ if (state->polarity == PWM_POLARITY_INVERSED) duty = period - duty; @@ -358,6 +364,8 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, state->duty_cycle = 0; } + state->polarity = PWM_POLARITY_NORMAL; + return 0; }