From patchwork Mon Jul 14 14:33:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 33598 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BD48920CAD for ; Mon, 14 Jul 2014 14:34:50 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id rd3sf30827579pab.11 for ; Mon, 14 Jul 2014 07:34:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=JhMFvnqbk9PHnBcqEu11SeYEByD4bu9h0PP6q77m/Vs=; b=F4rwqBItyVm9dltDSKuRjpZc4O2xbPZhi2W3hvTdY1FBaeLG5hZjljy0rKq3kn+KIv 0k2L+h06AECDZACc7myOG+4EQFRoJ6HBHaSAuAe8Tc5vpR8+vAgdeKT0fewK0e1ugw56 x0O+XMFvO8yKYZ2DUTsXrAPUxucvccr+i05IsVVRisYgvE6abLETIBMJCK6HjovpzerN 5F07trJWR5twAWAvnHJ9QdI7yhKzOGtMqlZd9NL7pIZP9EWUYRgKWoj4w/0Xz+gwYZrC 9LAUolUouMFos654g5K9cLs71mmxu640frASCH1mm2MVaYGOfD7bw3IM8aEDvIfekzb1 duHg== X-Gm-Message-State: ALoCoQnZs2IGLkNPP9jHV9UztC9hz/PmrVlSLbTUA3wM+4f+nbP9zdCob51lxR0gUV4SOHmpm4U0 X-Received: by 10.66.246.229 with SMTP id xz5mr7864794pac.34.1405348489983; Mon, 14 Jul 2014 07:34:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.245 with SMTP id l108ls140594qgf.83.gmail; Mon, 14 Jul 2014 07:34:49 -0700 (PDT) X-Received: by 10.52.186.103 with SMTP id fj7mr545911vdc.53.1405348489855; Mon, 14 Jul 2014 07:34:49 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id ti9si2061675vdc.35.2014.07.14.07.34.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 07:34:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hq11so6212143vcb.17 for ; Mon, 14 Jul 2014 07:34:49 -0700 (PDT) X-Received: by 10.58.56.102 with SMTP id z6mr15782999vep.7.1405348489775; Mon, 14 Jul 2014 07:34:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp139598vcb; Mon, 14 Jul 2014 07:34:49 -0700 (PDT) X-Received: by 10.68.136.226 with SMTP id qd2mr17001951pbb.72.1405348488967; Mon, 14 Jul 2014 07:34:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nj1si9302953pbc.95.2014.07.14.07.34.47; Mon, 14 Jul 2014 07:34:47 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755932AbaGNOem (ORCPT + 28 others); Mon, 14 Jul 2014 10:34:42 -0400 Received: from mail-ig0-f171.google.com ([209.85.213.171]:52013 "EHLO mail-ig0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755914AbaGNOeN (ORCPT ); Mon, 14 Jul 2014 10:34:13 -0400 Received: by mail-ig0-f171.google.com with SMTP id l13so1781134iga.10 for ; Mon, 14 Jul 2014 07:34:12 -0700 (PDT) X-Received: by 10.50.4.103 with SMTP id j7mr25893144igj.30.1405348452282; Mon, 14 Jul 2014 07:34:12 -0700 (PDT) Received: from localhost.localdomain (host109-148-237-85.range109-148.btcentralplus.com. [109.148.237.85]) by mx.google.com with ESMTPSA id q11sm25317390igr.7.2014.07.14.07.34.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 07:34:11 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, thierry.reding@gmail.com, linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, ajitpal.singh@st.com Subject: [PATCH v2 11/11] pwm: sti: Remove PWM period table Date: Mon, 14 Jul 2014 15:33:32 +0100 Message-Id: <1405348412-7352-12-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405348412-7352-1-git-send-email-lee.jones@linaro.org> References: <1405348412-7352-1-git-send-email-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Ajit Pal Singh Removes the PWM period table. Instead the prescaler is computed from the period value passed in the config() function. Signed-off-by: Ajit Pal Singh Signed-off-by: Lee Jones --- drivers/pwm/pwm-sti.c | 64 +++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/drivers/pwm/pwm-sti.c b/drivers/pwm/pwm-sti.c index 1aa901d..ceeeef6 100644 --- a/drivers/pwm/pwm-sti.c +++ b/drivers/pwm/pwm-sti.c @@ -10,7 +10,6 @@ * (at your option) any later version. */ -#include #include #include #include @@ -56,7 +55,6 @@ struct sti_pwm_chip { struct regmap_field *prescale_high; struct regmap_field *pwm_en; struct regmap_field *pwm_int_en; - unsigned long *pwm_periods; struct pwm_chip chip; struct pwm_device *cur; unsigned int en_count; @@ -77,29 +75,31 @@ static inline struct sti_pwm_chip *to_sti_pwmchip(struct pwm_chip *chip) } /* - * Calculate the period values supported by the PWM for the - * current clock rate. + * Calculate the prescaler value corresponding to the period. */ -static void sti_pwm_calc_periods(struct sti_pwm_chip *pc) +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; - struct device *dev = pc->dev; unsigned long val; - int i; + unsigned int ps; /* - * period_ns = (10^9 * (prescaler + 1) * (MAX_PWM_COUNT + 1)) / CLK_RATE + * prescale = ((period_ns * clk_rate) / (10^9 * (max_pwm_count + 1)) - 1 */ val = NSEC_PER_SEC / pc->clk_rate; val *= cdata->max_pwm_cnt + 1; - dev_dbg(dev, "possible periods for clkrate[HZ]:%lu\n", pc->clk_rate); - - for (i = 0; i <= cdata->max_prescale; i++) { - pc->pwm_periods[i] = val * (i + 1); - dev_dbg(dev, "prescale:%d, period[ns]:%lu\n", - i, pc->pwm_periods[i]); + if (period % val) { + return -EINVAL; + } else { + ps = period / val - 1; + if (ps > cdata->max_prescale) + return -EINVAL; } + *prescale = ps; + + return 0; } /* Calculate the number of PWM devices configured with a period. */ @@ -120,17 +120,6 @@ unsigned int sti_pwm_count_configured(struct pwm_chip *chip) return ncfg; } -static int sti_pwm_cmp_periods(const void *key, const void *elt) -{ - unsigned long i = *(unsigned long *)key; - unsigned long j = *(unsigned long *)elt; - - if (i < j) - return -1; - else - return i == j ? 0 : 1; -} - /* * For STiH4xx PWM IP, the PWM period is fixed to 256 local clock cycles. * The only way to change the period (apart from changing the PWM input clock) @@ -148,7 +137,6 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_device *cur = pc->cur; struct device *dev = pc->dev; unsigned int prescale = 0, pwmvalx; - unsigned long *found; int ret; unsigned int ncfg; bool period_same = false; @@ -178,21 +166,9 @@ static int sti_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, return ret; if (!period_same) { - /* - * Search for matching period value. - * The corresponding index is our prescale value. - */ - found = bsearch(&period_ns, &pc->pwm_periods[0], - cdata->max_prescale + 1, - sizeof(unsigned long), - sti_pwm_cmp_periods); - if (!found) { - dev_err(dev, - "failed to find matching period\n"); - ret = -EINVAL; + ret = sti_pwm_get_prescale(pc, period_ns, &prescale); + if (ret) goto clk_dis; - } - prescale = found - &pc->pwm_periods[0]; ret = regmap_field_write(pc->prescale_low, @@ -373,12 +349,6 @@ static int sti_pwm_probe(struct platform_device *pdev) if (ret) return ret; - pc->pwm_periods = devm_kzalloc(dev, - sizeof(unsigned long) * (pc->cdata->max_prescale + 1), - GFP_KERNEL); - if (!pc->pwm_periods) - return -ENOMEM; - pc->clk = of_clk_get_by_name(np, "pwm"); if (IS_ERR(pc->clk)) { dev_err(dev, "failed to get PWM clock\n"); @@ -397,8 +367,6 @@ static int sti_pwm_probe(struct platform_device *pdev) return ret; } - sti_pwm_calc_periods(pc); - pc->chip.dev = dev; pc->chip.ops = &sti_pwm_ops; pc->chip.base = -1;