From patchwork Wed May 24 19:47:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 13254476 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 8FF85C77B7C for ; Wed, 24 May 2023 19:53:00 +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:In-Reply-To:References:Cc:To:From: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hJhznXysbUe6iyL5UtmRanZxBVp2jW/zyDlWt4EdapY=; b=JRm8iHtvRu3+Kc aYJErI5M6E5IWMS+xH+ej1YjpxLgiyIPufCCjc6+r6qV0SjdSAWVyXCJ1aX7J5o8lVw8xO+bjbMyY /M/SgV26sBBiTI2uDxZbqceNjVC4nykKuf+3T3A1hHCyS+lPdowIhsUWMDjNlXmRCLv3IadlMTlrR /Tka48jrQzWwXqPsds/l78N4ORVRWB5jIyD6FXYXgYIrXGfQKtCN0tx1tUkwl+u00VAVpnKAYDntj jvvd5Beh0B7qvL5PQno/wrRD6bXUasKxHrrn+LH2xu2OxtdNa2slDhxtapd485QHw+VSJLnw6JPvx VT9EFbA7Idc5mfSBpqvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q1uXO-00EWDX-0e; Wed, 24 May 2023 19:52:46 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1uXL-00EWCf-0r; Wed, 24 May 2023 19:52:44 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-510d967249aso2859610a12.1; Wed, 24 May 2023 12:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684957959; x=1687549959; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=FfpJcXgNC9r2DJpgp6E9iGBv/JmFVRlvC0D1pq4re0k=; b=RyeyFUci0Xkt3P2B6mgdNQYs5srDXC6YVdvztLyA0HhBmXkdEzPioa6aoT2CbHeCCh vwrKMEXZA9hWTdO2IW4nQQSn2NLYjjSzx01lJoQtVMzyQ2QrvDnpjIQ9S/L/oau1bhtG ouY/95M7IpRpLWExR8yefpbOoekwlXHa6YG4UKzOFu+l0AJ9FdjKkd/72CNYM/GhbLsd EVwW+IN+x8sUJEBFovKYJMD51o0/a7f0C1U0BQLr+kJi0r8Rv/oqrPcS+mvd6Q/A+R5O 9SetGwMTAlbUWxAqwwaGtL5DEMwy/z/yRIKOHvbff+rA04BMj//G47ihP2NvpfKq1Kpx z6Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684957959; x=1687549959; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FfpJcXgNC9r2DJpgp6E9iGBv/JmFVRlvC0D1pq4re0k=; b=S+zvxEtQFGxMBHojvM0IWTYBu7ziFInU7cRB5HDkMlP5yva+xqCMc34BQfns7GuVCu uYqpyrXWl3QKaGUKLKXESTymWfsxftQrB8oiuZKAlaIeFSVHnH5mD1fhYZh8pzcL1A/A MGxKo1OIxA/foX0gAbUBqNUHEZw/6ZdzxF899poRrNjLdc7ymg/Q5xB8lU90LTGbNHfv bV3DClhCmbICJcxaG+B9MzTLo8pu1kDF1QefnXPfsmjW5odzcM6NiWAWMsiy2mP2/18/ ngXkbbryKWtmewQ+tRqL5sNubr00N0qMcpIO1bJi5/ty7GTlhxHGJsoq68/MFLYapKd5 Cn5w== X-Gm-Message-State: AC+VfDzdC5PDUc6eTYsoXqFU5XDTP+W75Ro7laAOaOWGk8BgYHzwH39/ 1BIGmTFtXUdIKa/U8hB3hYU= X-Google-Smtp-Source: ACHHUZ5LNXTyD94Y8CVwqrQrbJL9IGSs2sEcAr6YfOqlSGqos84mpbqvuYMAKymvzgVdMu1Hx9bW2g== X-Received: by 2002:a05:6402:187:b0:4fd:2b04:6e8b with SMTP id r7-20020a056402018700b004fd2b046e8bmr2979484edv.29.1684957958850; Wed, 24 May 2023 12:52:38 -0700 (PDT) Received: from ?IPV6:2a01:c23:c519:9c00:cd4b:d130:35c7:5e08? (dynamic-2a01-0c23-c519-9c00-cd4b-d130-35c7-5e08.c23.pool.telefonica.de. [2a01:c23:c519:9c00:cd4b:d130:35c7:5e08]) by smtp.googlemail.com with ESMTPSA id bq2-20020a056402214200b00510d7152dc7sm249605edb.30.2023.05.24.12.52.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 12:52:38 -0700 (PDT) Message-ID: <2f376c8b-32a9-a3a7-3454-4a864ab8ab44@gmail.com> Date: Wed, 24 May 2023 21:47:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: [PATCH v5 RESEND 1/6] pwm: meson: modify and simplify calculation in meson_pwm_get_state Content-Language: en-US From: Heiner Kallweit To: Jerome Brunet , Martin Blumenstingl , Neil Armstrong , Kevin Hilman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , "thierry.reding@gmail.com" Cc: "linux-arm-kernel@lists.infradead.org" , "open list:ARM/Amlogic Meson..." , linux-pwm@vger.kernel.org, Dmitry Rokosov References: In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230524_125243_323930_EB635D66 X-CRM114-Status: GOOD ( 11.72 ) 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 I don't see a reason why we should treat the case lo < hi differently and return 0 as period and duty_cycle. The current logic was added with c375bcbaabdb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()"), Martin as original author doesn't remember why it was implemented this way back then. So let's handle it as normal use case and also remove the optimization for lo == 0. I think the improved readability is worth it. Fixes: c375bcbaabdb ("pwm: meson: Read the full hardware state in meson_pwm_get_state()") Reviewed-by: Uwe Kleine-König Reviewed-by: Dmitry Rokosov Acked-by: Martin Blumenstingl Cc: stable@vger.kernel.org Signed-off-by: Heiner Kallweit --- drivers/pwm/pwm-meson.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 5732300eb..3865538dd 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -351,18 +351,8 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, channel->lo = FIELD_GET(PWM_LOW_MASK, value); channel->hi = FIELD_GET(PWM_HIGH_MASK, value); - if (channel->lo == 0) { - state->period = meson_pwm_cnt_to_ns(chip, pwm, channel->hi); - state->duty_cycle = state->period; - } else if (channel->lo >= channel->hi) { - state->period = meson_pwm_cnt_to_ns(chip, pwm, - channel->lo + channel->hi); - state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, - channel->hi); - } else { - state->period = 0; - state->duty_cycle = 0; - } + state->period = meson_pwm_cnt_to_ns(chip, pwm, channel->lo + channel->hi); + state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, channel->hi); state->polarity = PWM_POLARITY_NORMAL;