From patchwork Sat Aug 24 14:09:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 11113005 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E90231395 for ; Sat, 24 Aug 2019 14:10:23 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C4D1821670 for ; Sat, 24 Aug 2019 14:10:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CiNTR4OI"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=gmx.net header.i=@gmx.net header.b="FPLvHF3F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4D1821670 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gmx.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ze8fXyiOb26jz8OkT8pEbWrtbYreAJy5nZrs6McmZ5s=; b=CiNTR4OIfDhart SUutNvDaNnWfIh9/AbNoCxiXYA9ecwy+59NXfcGzYqKzgn6ACuuHB5SQ1RFlFO8VJJmyTrFVWQajf hP6w7oiQZcnPqeFd2hsOn+bsGkrFfdAGglDfWoLxbmpiVf6ss6llrvflsQi0pmVi/moxE7KKl+vFT NdygyAo0+qZcEBaY2kMQazWnzDyY57nBSOzrMOxx97+36yAWy4Iie60qNRuE5QDJ+LlflwdlCzYAJ 4Wf5RIkoOWZIiXfkj7Y4kcfsAujZGybOo82GaOgKPXSlpBTq5AP6xfyF+Say8/98RjQs8e2pFXyMb zZqbaTFFNSmFhdFxPyXA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i1WkI-0005Lc-VW; Sat, 24 Aug 2019 14:10:23 +0000 Received: from mout.gmx.net ([212.227.15.15]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i1Wk6-0004nb-Ck for linux-arm-kernel@lists.infradead.org; Sat, 24 Aug 2019 14:10:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1566655798; bh=p0356BK30yaqXao28qVvueaMUHmiPXaegoIWDiukDy4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=FPLvHF3F1eQfEPy73mmnsP53NAh3u0jSpEB6+THailv4zEuzdwna+GR2Qdwomhdbg b57U7oFf2mC0Mp1JqCC+7e+h8yQ4TXj3KWUZlQyO1R0CjYS3ucmkUCnNOtwIBFbWpS pP0p5ffueiouSsEgYGkVPJTHYLQlZqJzfjJ67JXo= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([37.4.249.106]) by mail.gmx.com (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M9FjR-1i7Jcv1UNL-006NXj; Sat, 24 Aug 2019 16:09:58 +0200 From: Stefan Wahren To: Thierry Reding , Eric Anholt , Florian Fainelli , Ray Jui , Scott Branden Subject: [PATCH V2 2/3] pwm: bcm2835: fix period_ns range check Date: Sat, 24 Aug 2019 16:09:47 +0200 Message-Id: <1566655788-24949-3-git-send-email-wahrenst@gmx.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1566655788-24949-1-git-send-email-wahrenst@gmx.net> References: <1566655788-24949-1-git-send-email-wahrenst@gmx.net> MIME-Version: 1.0 X-Provags-ID: V03:K1:k1uKE8Vftkrl/41pYV+oH5xV1tYyIKl3SA79jsJlrEm/znGfmxb vPUsPCH8MQooBxIiiEtewqIVeYrGjl3jviqP8jmvZ4IlQI5NOg1gyUr+zVhtmGMIpwqQRZC ofGmes5DadQ5HKqt55IRir7pgwGeU17r3lXenKeizqsDayV8WzJd3enSOaz2Q1IHKEoWEZI /cEL5M9rYiEhlcyJNz4qg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:3tPCBJyhJdI=:xOSDLVNwC7SqyhMgU539A4 7aeaknVIaXPH9QUXP+JzCWJXnrgxEiPxDbAFFprte/SEx9E41q9NsACEuv/bJIDAz7IgKCQIE xsJPJ8Ec/KhuvP59+sQ2DWHqEZUwhxqT+sGpZoQXVnc4P4DcqIhex/hbANU0We4xHbPB0BEHN xMHwdeG+q1XRtNy6+fznb3KD83w9M6lgfj0y+fIBzz7q2vqsmNo5rgOPLsGa1/B+K7k3RZZvi AEy2V2f0DAGjD2EXt5j9Ad9ZBDlCphG+SfE+OzQLTK1R16jOBAEmheJ5Aen10pfd4MViMz4j8 Qzt1qWlYi4zIwVcQQop1rN8/E1t+vlC7Pq6xfUJl8fJzGqHjj3kN5oByfs96JSu9sS4EQvdDy GSSoJ4HKUj6RJu8RFMSvVsOaanXzxAsTZ2k/5OHrb9af4ftw/0PFjjTEl9U4EIvq03cOOddhN 5n5f01B0uLJFwK3FcA9vSjmRCmnav5CnXdoOD0YabC/PvHh/lxSFeSPY3icNjKoZH+ftb/iBe NuUzTTshP8lvnw1e7FqWF93HaxY90QeMxWJB4QX0Oi6A0saQetB5kbWKizf9UU12Qh5UsUc5B j5dR5IQIYUUf7Gutpo6OOXtJMdHPsdkkLin4eKPI2Q2douWFpkNce1ry8wtGqOyLeVZF33+hY rp+ao2uxWBjPwH5BjSbBEa9LPh6LdNb8jneD3qfcCeLx5qUswjq8ZUmNnTYMlE10+LmnYwDIt HYC7Wrodh/T9+w8Y4OwxVySrPVTgCLmV+6RwXgVHSaquks5+iZQNtMQPoLjGGkrNHsZdJrs5R fTi4+mYJhZphoXQWtAb0HJwJR747kG1BTIHruaz8I0U6Pp35OTyPYF4/owfYnqpOcU4Rf5kSy dA6fwsSZPEmFv4feyM4a3Kt9RyOZ1pnLzVszETdsgD0C1mf0O0yhuxQVbPivL3qeMBW0xtGzu XLYc0UkREnqb4iOAlbGdJyaHwN9Om26iGTDlAC09XYONa70aiaiH3zmGIaXcyk1cUYJYonG8O eBBp0XgAyGrNxXKiEZxH6oGoqbetllotSHBodJhn+0AINbHobSTjn+os+2IyqUNnEGkOZ9GsM GZmzu6LguSop88VdH8YBidqW6ErftZObrgFaxEKvgLeZjlE1255qNN95ouM7RVMIgTXi8TIyd 4Jkoo= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190824_071010_749862_7CC9052F X-CRM114-Status: GOOD ( 13.02 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [212.227.15.15 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (wahrenst[at]gmx.net) -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pwm@vger.kernel.org, Stefan Wahren , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The range check for period_ns was written under assumption of a fixed PWM clock. With clk-bcm2835 driver the PWM clock is a dynamic one. So fix this by doing the range check on the period register value. Signed-off-by: Stefan Wahren Acked-by: Uwe Kleine-König --- drivers/pwm/pwm-bcm2835.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c index 5276306..2c82386 100644 --- a/drivers/pwm/pwm-bcm2835.c +++ b/drivers/pwm/pwm-bcm2835.c @@ -21,7 +21,7 @@ #define PERIOD(x) (((x) * 0x10) + 0x10) #define DUTY(x) (((x) * 0x10) + 0x14) -#define MIN_PERIOD 108 /* 9.2 MHz max. PWM clock */ +#define PERIOD_MIN 0x2 struct bcm2835_pwm { struct pwm_chip chip; @@ -64,6 +64,7 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, struct bcm2835_pwm *pc = to_bcm2835_pwm(chip); unsigned long rate = clk_get_rate(pc->clk); unsigned long scaler; + u32 period; if (!rate) { dev_err(pc->dev, "failed to get clock rate\n"); @@ -71,14 +72,14 @@ static int bcm2835_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, } scaler = DIV_ROUND_CLOSEST(NSEC_PER_SEC, rate); + period = DIV_ROUND_CLOSEST(period_ns, scaler); - if (period_ns <= MIN_PERIOD) + if (period < PERIOD_MIN) return -EINVAL; writel(DIV_ROUND_CLOSEST(duty_ns, scaler), pc->base + DUTY(pwm->hwpwm)); - writel(DIV_ROUND_CLOSEST(period_ns, scaler), - pc->base + PERIOD(pwm->hwpwm)); + writel(period, pc->base + PERIOD(pwm->hwpwm)); return 0; }