From patchwork Sun Apr 12 14:54:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Moon X-Patchwork-Id: 6203441 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AA6E69F1C4 for ; Sun, 12 Apr 2015 14:56:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EF51202BE for ; Sun, 12 Apr 2015 14:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 921C420295 for ; Sun, 12 Apr 2015 14:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751704AbbDLO4r (ORCPT ); Sun, 12 Apr 2015 10:56:47 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:34837 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751219AbbDLO4o (ORCPT ); Sun, 12 Apr 2015 10:56:44 -0400 Received: by pddn5 with SMTP id n5so78555817pdd.2; Sun, 12 Apr 2015 07:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=It2DmAO+Y5WtuTfcwqUZwkR8gXk3UfcRLxScrPgn2Uk=; b=vsOb8jN0uB1hcLxAw8q9pJz7Cimx1YZHRjHZHVsvprTCyarcUsdl0OvTAORm+VXm+J nrWKxULXUkHJNRIX/ZAXD1kLWc7xVM3rXaC2wUzmvOVstgLQ66D+pJw4MHa3fyhp4GpC /Fb6AFRMCjV86xL1cCxWjOga7fFGMaNVVFb+D55vwa26bMHUYVemleY1ivVgmNMsonom 8nhQr046+wfWVXfS3HZtVAZYpfel24a2lzDM45gf/LN4BdhT9FM3nPndr/A/rms8sihC 9/Zn5FlGvPf3PxcCO6u9E7v/Uedm6NFNJGNvI/gMBevqo0QFUABXqw22qU6xIHS0L0La DpkA== X-Received: by 10.69.31.171 with SMTP id kn11mr18763406pbd.159.1428850603782; Sun, 12 Apr 2015 07:56:43 -0700 (PDT) Received: from odroidxu3.localdomain ([115.117.44.43]) by mx.google.com with ESMTPSA id vh2sm4557363pbc.49.2015.04.12.07.56.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 12 Apr 2015 07:56:42 -0700 (PDT) From: Anand Moon To: Lukasz Majewski , Guenter Roeck , Eduardo Valentin , Sjoerd Simons , Markus Reichl , Russell King , Kukjin Kim Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Anand Moon Subject: [PATCH v3 6/6] hwmon: pwm-fan: Update the duty cycle inorder to control the pwm-fan Date: Mon, 13 Apr 2015 00:24:12 +0930 Message-Id: <1428850452-4178-7-git-send-email-linux.amoon@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428850452-4178-1-git-send-email-linux.amoon@gmail.com> References: <1428850452-4178-1-git-send-email-linux.amoon@gmail.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to disable the PWM we need to update using following sequence. pwm_config(pwm, 0, period); pwm_disable(pwm); pwm_config() with a zero duty cycle to make it clear the timer and update the PWM registers. pwm_disable will clear the TCON_AUTORELOAD(tcon_chan) and update the PWM register. Next change in state will get trigger unless a new PWM cycle happened. pwm_config(pwm, duty, period); pwm_enable(pwm); Through pwm_config we update the duty cycle and period and update the PWM register. pwm_enable will update the state to TCON_MANUALUPDATE(tcon_chan) and TCON_START(tcon_chan) | TCON_AUTORELOAD(tcon_chan) and update the PWM register. Reported-by: Markus Reichl Tested-by: Markus Reichl Reviewed-by: Lukasz Majewski Reviewed-by: Sjoerd Simons Signed-off-by: Anand Moon --- drivers/hwmon/pwm-fan.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 7c83dc4..f25c841 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -44,26 +44,24 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) int ret = 0; mutex_lock(&ctx->lock); + if (ctx->pwm_value == pwm) goto exit_set_pwm_err; - if (pwm == 0) { - pwm_disable(ctx->pwm); - goto exit_set_pwm; - } - duty = DIV_ROUND_UP(pwm * (ctx->pwm->period - 1), MAX_PWM); ret = pwm_config(ctx->pwm, duty, ctx->pwm->period); if (ret) goto exit_set_pwm_err; + if (pwm == 0) + pwm_disable(ctx->pwm); + if (ctx->pwm_value == 0) { ret = pwm_enable(ctx->pwm); if (ret) goto exit_set_pwm_err; } -exit_set_pwm: ctx->pwm_value = pwm; exit_set_pwm_err: mutex_unlock(&ctx->lock);