Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp886778ybp; Fri, 4 Oct 2019 06:33:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5dhUnmkyIhWIo+maVxo/QZNXk+eBY5qLB/MgtqNv18c+AzXL1kTOZKsjtPyc2dcORoH8r X-Received: by 2002:a17:906:c721:: with SMTP id fj1mr12360807ejb.177.1570196029721; Fri, 04 Oct 2019 06:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570196029; cv=none; d=google.com; s=arc-20160816; b=EiVd/9vGrsCDW4S63ADE0XieGmp9LlqXjS255EQdIeJPeWllW85m8UVkt4WLTB+lJe BH8sGX8J1Neuas9mDmHaqf3ji1wmTKsCk//jkmYoc9y7BHfM/pBmxbP/pBSg3qnazSRh 3HX0LRpC0vRBufLKBX/kCpV99wP9/5UqY+AVXCk9oGLTEo+d1+VocD3Cw3b7/jWsruVS KuQ38uqEvjCjHoxWicxpHSg7Di35QQhsdfpPTHD+UCt4yTu10gmiqX/CMCQxSeDxRNMj MAURdaJPPnU9E/PKsdC5fCPW6bD4XjIgyzlHePjLxaFxyGd9XWwLTNIf1wq8sREWzBnv 4JTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=enjD7GinjPEmXbD794v1TL8qB8AXAn8TuqNGVlImRwo=; b=XtgDXPyB9UinrMuvRr80H6nfjhEmpmhBcRweHLa54H71QysXpZons/YDjLSH6qs+15 fmZ6Hkvp7lmKtjSa8Sx1x9wjlUeFGfmvdnZRhF7YgkEmT760RQjmI0Dow0yIsUW/Lrjv rdWXWrF8eT5otx5PZTk/Q5Jzxq4q2uzvk1M7T8kfis5Z+C5pTiUJseMuDd0ulbepTeJg aRgkJhBND2UN+DFs5N51HkKPOmJNXeUEKk6vdBK7v6O+prLMEAq3sjKWPJTH4vFXsFuU sonw2v8jVo7cR6MvUYimGL0LMO3M+TguStsb+C5BrKZhyufi3vvKmfoNbIvjsbaxXz2h vBcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=cVOCOZBf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay2si3440985edb.343.2019.10.04.06.33.25; Fri, 04 Oct 2019 06:33:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=cVOCOZBf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388690AbfJDNdJ (ORCPT + 99 others); Fri, 4 Oct 2019 09:33:09 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45415 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388668AbfJDNdI (ORCPT ); Fri, 4 Oct 2019 09:33:08 -0400 Received: by mail-lj1-f193.google.com with SMTP id q64so6505068ljb.12 for ; Fri, 04 Oct 2019 06:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=enjD7GinjPEmXbD794v1TL8qB8AXAn8TuqNGVlImRwo=; b=cVOCOZBfFV4/Q55ikZfbm3e6RfV3oQtgU+vNCBrhPnWHW0yMoE/YOhCTLpEuSkzPyt p/jSR/BxvhMiDKgCkwbGaaribeHJHsoJnVzAtd0w3FmfMc8fEw6xUkR16/spC40jUK7j aqmMH79uB6vD7zvJf5xhJIjmux8oZvPGm4juI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=enjD7GinjPEmXbD794v1TL8qB8AXAn8TuqNGVlImRwo=; b=edC9vCUwI+qLyD2zg/9rXrhll47FgpFXPI00n9uzu4I7zinR7XcwoW7erzjJn1xuZm 9lI8si4jg34NyeMbcLdv7zTX6zseHmOAzI72VMk/Vto1dr4XaI0sjt14nyqoQWSGMFaw tj73TUGpI16BLRwx5Cz30abBOf7CEkscUal15GzEXustlYARU3F8POXLUfe3VUylhvrQ WqxhOwF63Tq9rYjPptuZyFuZDVsjm+rbnz5rFv+4HZXjmBIvTFgXzQ/GGKkHRjdS2dmL AQVWXXvzrA4BTczvPTexz+WdKG2/7zEKnPMkpeLhTjPlxf/Di+nllceb9QsxCigKLwHf diTQ== X-Gm-Message-State: APjAAAWke3ejBJgpaN4n3vjLV8VGPqSoxkmErHGJax/0wS9rHR2px1Fk Bws6QJaJMUZR1gbAzYvwdrKz3Q== X-Received: by 2002:a2e:9585:: with SMTP id w5mr3871975ljh.220.1570195985888; Fri, 04 Oct 2019 06:33:05 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id y26sm1534991ljj.90.2019.10.04.06.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 06:33:05 -0700 (PDT) From: Rasmus Villemoes To: Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: devicetree@vger.kernel.org, Rob Herring , Rasmus Villemoes , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] pwm: mxs: avoid a division in mxs_pwm_apply() Date: Fri, 4 Oct 2019 15:32:06 +0200 Message-Id: <20191004133207.6663-6-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004133207.6663-1-linux@rasmusvillemoes.dk> References: <20191004133207.6663-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the divisor is not a compile-time constant (unless gcc somehow decided to unroll the loop PERIOD_CDIV_MAX times), this does a somewhat expensive 32/32 division. Replace that with a right shift. We still have a 64/32 division just below, but at least in that case the divisor is compile-time constant. Signed-off-by: Rasmus Villemoes --- drivers/pwm/pwm-mxs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c index 57562221c439..f2e57fcf8f8b 100644 --- a/drivers/pwm/pwm-mxs.c +++ b/drivers/pwm/pwm-mxs.c @@ -33,8 +33,8 @@ #define PERIOD_CDIV(div) (((div) & 0x7) << 20) #define PERIOD_CDIV_MAX 8 -static const unsigned int cdiv[PERIOD_CDIV_MAX] = { - 1, 2, 4, 8, 16, 64, 256, 1024 +static const u8 cdiv_shift[PERIOD_CDIV_MAX] = { + 0, 1, 2, 3, 4, 6, 8, 10 }; struct mxs_pwm_chip { @@ -71,7 +71,7 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, rate = clk_get_rate(mxs->clk); while (1) { - c = rate / cdiv[div]; + c = rate >> cdiv_shift[div]; c = c * state->period; do_div(c, 1000000000); if (c < PERIOD_PERIOD_MAX) -- 2.20.1