From patchwork Tue Aug 16 09:35:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 73979 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1897316qga; Tue, 16 Aug 2016 02:38:54 -0700 (PDT) X-Received: by 10.98.210.69 with SMTP id c66mr62156517pfg.71.1471340329511; Tue, 16 Aug 2016 02:38:49 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e184si31447781pfa.193.2016.08.16.02.38.47; Tue, 16 Aug 2016 02:38: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=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753900AbcHPJif (ORCPT + 27 others); Tue, 16 Aug 2016 05:38:35 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:35882 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753395AbcHPJfs (ORCPT ); Tue, 16 Aug 2016 05:35:48 -0400 Received: by mail-wm0-f49.google.com with SMTP id q128so132774668wma.1 for ; Tue, 16 Aug 2016 02:35:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u8iOpoDGp+Ccam3TkRVOkt8HWIbCJjguOMYaKEs/KCo=; b=UO37L4BhJ7xQZiE9QnhktD3x5akl75rU9JO61ytM5wyz8uCR3BIOcNzk8ezQmlplbw HfFTYRp0LIaYqPUFUSt3gfiNoPuHFNYXdiz7aHA0sMLV1gtnQ/t3nt8UF8hymipwIz0Z RYRM1GS+KrtoCIqBLAyrDka+r62nY5w3hDA4s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=u8iOpoDGp+Ccam3TkRVOkt8HWIbCJjguOMYaKEs/KCo=; b=l8A83rg76EyRV4TS/ASkSRc9lky9pzFsbKX77IQjSTv1UPL7d5ptcaOO7Z+VlrC1Ls 0+L6HpeQajCwPBlQteg8pfmUi15tDGv1q+lhV1ENUj8/ydP8HhMe19KbgDVeyez4X2JH O8UAJKv2fRoqkfHCinrjphitCfCx2xOnqd6liooewcdl8uQjtUmQ2V9a04SCtoHSBXaC i21SOZIxGXCANm7k7Ctfw+hLYT540eyE/W5ORPRSrinzaAGxyyPRpbRDWPdoRvcf+Kp+ Wj6s/2FgmaQTyNMJXFS2ylvarsOPVmjB81zvIXXVtcVNOnwiyPLfq8SswNgL+gijjfgy l/rQ== X-Gm-Message-State: AEkooutVUlfjxqPGmUreCytGnpQoYvIwRB6THn8ugYKi3w/l5WqeGF8Y/ATWpFGorK/iW2BG X-Received: by 10.28.22.6 with SMTP id 6mr21508620wmw.55.1471340146693; Tue, 16 Aug 2016 02:35:46 -0700 (PDT) Received: from localhost.localdomain (host81-129-169-93.range81-129.btcentralplus.com. [81.129.169.93]) by smtp.gmail.com with ESMTPSA id g1sm16614889wjy.5.2016.08.16.02.35.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2016 02:35:45 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, patrice.chotard@st.com, thierry.reding@gmail.com, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, Lee Jones Subject: [PATCH v4 09/17] pwm: sti: Only request clock rate when you need to Date: Tue, 16 Aug 2016 10:35:00 +0100 Message-Id: <20160816093508.28307-10-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160816093508.28307-1-lee.jones@linaro.org> References: <20160816093508.28307-1-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the original code the clock rate was only obtained during initialisation; however, the rate may change between then and its use. This patch ensures the correct rate is acquired just before use. Signed-off-by: Lee Jones --- drivers/pwm/pwm-sti.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) -- 2.9.0 diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 246df77..863d5a9 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -51,7 +51,6 @@ struct sti_pwm_compat_data { struct sti_pwm_chip { struct device *dev; - unsigned long clk_rate; struct clk *pwm_clk; struct regmap *regmap; struct sti_pwm_compat_data *cdata; @@ -86,13 +85,20 @@ static int sti_pwm_get_prescale(struct sti_pwm_chip *pc, unsigned long period, unsigned int *prescale) { struct sti_pwm_compat_data *cdata = pc->cdata; + unsigned long clk_rate; unsigned long val; unsigned int ps; + clk_rate = clk_get_rate(pc->pwm_clk); + if (!clk_rate) { + dev_err(pc->dev, "failed to get clock rate\n"); + return -EINVAL; + } + /* * prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_count + 1)) - 1 */ - val = NSEC_PER_SEC / pc->clk_rate; + val = NSEC_PER_SEC / clk_rate; val *= cdata->max_pwm_cnt + 1; if (period % val) { @@ -353,12 +359,6 @@ static int sti_pwm_probe(struct platform_device *pdev) return PTR_ERR(pc->pwm_clk); } - pc->clk_rate = clk_get_rate(pc->pwm_clk); - if (!pc->clk_rate) { - dev_err(dev, "failed to get clock rate\n"); - return -EINVAL; - } - ret = clk_prepare(pc->pwm_clk); if (ret) { dev_err(dev, "failed to prepare clock\n");