From patchwork Tue Jul 7 15:06:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 50828 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 570A9229FC for ; Tue, 7 Jul 2015 15:08:34 +0000 (UTC) Received: by wifm2 with SMTP id m2sf22165893wif.1 for ; Tue, 07 Jul 2015 08:08:33 -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=rtxmMDrWv8RWkhjn1zUvL3UIwI+aduW1gKrJgpLXISk=; b=ayNQe/+aoWYt+CjT0q0g77EeH/Icpq0X/F8kBluuxWQr1KGrRVqKJiQZObSp5WaRlN 5oZVv2FiJenRi6+1L+z1sdf4Nt5DEMKzF/QZ+qaefYGtoUYHH1301i9BFf8zf60UaFf4 0ANjjPDvVVlUzhIoHwyFtkKhW0FZUikp5E0GNtM2Ha/OcqTCyoSLuc87SuofPjWfsrTQ Lh4wVmi9J5KV1+0sKEubVVoGR4NliwTg51/yQZnakzpNcIt5rx8DnvOki6/L5QnnMq4a T9sT96HXAQD1LpA7xeU+NiYeBSkPL6Y9mNWV/IkZVeh4AVY7I9vrPEVBibwJA/9yLjxV xV0g== X-Gm-Message-State: ALoCoQmYFllqzMHg2aCv2BdCQuSZB7sFw0sJqD8/A+/6+6DGLIipUNtzWpNoUSamNKmNfX8zvQhR X-Received: by 10.112.160.39 with SMTP id xh7mr2327753lbb.22.1436281713649; Tue, 07 Jul 2015 08:08:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.7.105 with SMTP id i9ls79194laa.96.gmail; Tue, 07 Jul 2015 08:08:33 -0700 (PDT) X-Received: by 10.112.185.100 with SMTP id fb4mr4476162lbc.79.1436281713467; Tue, 07 Jul 2015 08:08:33 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id dw10si18358764lbd.67.2015.07.07.08.08.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2015 08:08:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by lagx9 with SMTP id x9so199433836lag.1 for ; Tue, 07 Jul 2015 08:08:33 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr4471046laj.88.1436281713334; Tue, 07 Jul 2015 08:08:33 -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.112.108.230 with SMTP id hn6csp2453161lbb; Tue, 7 Jul 2015 08:08:31 -0700 (PDT) X-Received: by 10.60.15.133 with SMTP id x5mr4578926oec.80.1436281711226; Tue, 07 Jul 2015 08:08:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1si35164918pdh.95.2015.07.07.08.08.29; Tue, 07 Jul 2015 08:08:31 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932336AbbGGPIX (ORCPT + 29 others); Tue, 7 Jul 2015 11:08:23 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:35935 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932424AbbGGPHL (ORCPT ); Tue, 7 Jul 2015 11:07:11 -0400 Received: by widjy10 with SMTP id jy10so191666133wid.1 for ; Tue, 07 Jul 2015 08:07:10 -0700 (PDT) X-Received: by 10.180.99.71 with SMTP id eo7mr60530602wib.95.1436281630173; Tue, 07 Jul 2015 08:07:10 -0700 (PDT) Received: from localhost.localdomain (host86-178-207-130.range86-178.btcentralplus.com. [86.178.207.130]) by mx.google.com with ESMTPSA id x5sm1360101wif.21.2015.07.07.08.07.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jul 2015 08:07:09 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, broonie@kernel.org, lgirdwood@gmail.com, Lee Jones Subject: [PATCH v2 8/9] regulator: pwm-regulator: Simplify voltage to duty-cycle call Date: Tue, 7 Jul 2015 16:06:52 +0100 Message-Id: <1436281613-899-9-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1436281613-899-1-git-send-email-lee.jones@linaro.org> References: <1436281613-899-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.215.54 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: , If we reverse some of the logic and change the formula used, we can simplify the function greatly. It is intentional that this function is supplied and then re-worked within the same patch-set. The submission in the previous patch is the tried and tested (i.e. in real releases) method written by ST. This patch contains a simplification provided later. It looks and performs better, but doesn't have the same time-under-test that the original method does. The idea is that we keep some history in order to provide an easy way back i.e. revert. Signed-off-by: Lee Jones --- drivers/regulator/pwm-regulator.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index dac145d..d5cb267 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c @@ -93,26 +93,13 @@ static int pwm_regulator_list_voltage(struct regulator_dev *rdev, /** * Continuous voltage call-backs */ -static int pwm_voltage_to_duty_cycle(struct regulator_dev *rdev, - int volt_mV) +static int pwm_voltage_to_duty_cycle(struct regulator_dev *rdev, int req_uV) { - struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev); - int min_mV = rdev->constraints->min_uV / 1000; - int max_mV = rdev->constraints->max_uV / 1000; - int max_duty_cycle = drvdata->max_duty_cycle; - int vdiff = min_mV - max_mV; - int pwm_code; - int tmp; - - tmp = ((max_duty_cycle - min_mV) * max_duty_cycle) / vdiff; - pwm_code = ((tmp + max_duty_cycle) * volt_mV) / vdiff; - - if (pwm_code < 0) - pwm_code = 0; - if (pwm_code > max_duty_cycle) - pwm_code = max_duty_cycle; - - return pwm_code * 100 / max_duty_cycle; + int min_uV = rdev->constraints->min_uV; + int max_uV = rdev->constraints->max_uV; + int diff = max_uV - min_uV; + + return 100 - ((((req_uV * 100) - (min_uV * 100)) / diff)); } static int pwm_regulator_get_voltage(struct regulator_dev *rdev) @@ -131,7 +118,7 @@ static int pwm_regulator_set_voltage(struct regulator_dev *rdev, int duty_cycle; int ret; - duty_cycle = pwm_voltage_to_duty_cycle(rdev, min_uV / 1000); + duty_cycle = pwm_voltage_to_duty_cycle(rdev, min_uV); ret = pwm_config(drvdata->pwm, (drvdata->pwm->period / 100) * duty_cycle,