From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932904AbcCHLGf (ORCPT ); Tue, 8 Mar 2016 06:06:35 -0500 Received: from hqemgate15.nvidia.com ([216.228.121.64]:13055 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932479AbcCHLG3 (ORCPT ); Tue, 8 Mar 2016 06:06:29 -0500 X-PGP-Universal: processed; by hqnvupgp08.nvidia.com on Tue, 08 Mar 2016 03:05:56 -0800 From: Laxman Dewangan To: , , CC: , , , , Laxman Dewangan Subject: [PATCH 1/5] regulator: pwm: Fix calculation of voltage-to-duty cycle Date: Tue, 8 Mar 2016 16:23:21 +0530 Message-ID: <1457434405-30372-2-git-send-email-ldewangan@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457434405-30372-1-git-send-email-ldewangan@nvidia.com> References: <1457434405-30372-1-git-send-email-ldewangan@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With following equation for calculating voltage_to_duty_cycle_percentage 100 - (((req_uV * 100) - (min_uV * 100)) / diff); we get 0% for max_uV and 100% for min_uV. Correcting this to ((req_uV * 100) - (min_uV * 100)) / diff; to get proper duty cycle. Signed-off-by: Laxman Dewangan Cc: Lee Jones --- drivers/regulator/pwm-regulator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c index 3aca067..4d8eb35 100644 --- a/drivers/regulator/pwm-regulator.c +++ b/drivers/regulator/pwm-regulator.c @@ -115,7 +115,7 @@ static int pwm_voltage_to_duty_cycle_percentage(struct regulator_dev *rdev, int int max_uV = rdev->constraints->max_uV; int diff = max_uV - min_uV; - return 100 - (((req_uV * 100) - (min_uV * 100)) / diff); + return ((req_uV * 100) - (min_uV * 100)) / diff; } static int pwm_regulator_get_voltage(struct regulator_dev *rdev) -- 2.1.4