From patchwork Wed Mar 4 12:03:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 5935811 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 F26899F318 for ; Wed, 4 Mar 2015 12:05:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7EDC72026F for ; Wed, 4 Mar 2015 12:05:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8EE4202AE for ; Wed, 4 Mar 2015 12:05:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932571AbbCDME0 (ORCPT ); Wed, 4 Mar 2015 07:04:26 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:15915 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932442AbbCDMEW (ORCPT ); Wed, 4 Mar 2015 07:04:22 -0500 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NKO00HFIS78KK50@mailout4.samsung.com>; Wed, 04 Mar 2015 21:04:20 +0900 (KST) X-AuditID: cbfee61a-f79c06d000004e71-c3-54f6f4c49f68 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id C3.9D.20081.4C4F6F45; Wed, 04 Mar 2015 21:04:20 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NKO00ILPS6ADG60@mmp1.samsung.com>; Wed, 04 Mar 2015 21:04:19 +0900 (KST) From: Lukasz Majewski To: Eduardo Valentin , Kamil Debski , Jean Delvare , Guenter Roeck , Kukjin Kim Cc: lm-sensors@lm-sensors.org, Linux PM list , "linux-samsung-soc@vger.kernel.org" , devicetree@vger.kernel.org, Lukasz Majewski , Kukjin Kim , linux-kernel@vger.kernel.org, Sjoerd Simons , Abhilash Kesavan , Abhilash Kesavan , Lukasz Majewski Subject: [PATCH RESEND v6 4/6] hwmon: pwm-fan: Extract __set_pwm() function to only modify PWM duty cycle Date: Wed, 04 Mar 2015 13:03:42 +0100 Message-id: <1425470624-25793-5-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10.4 In-reply-to: <1425470624-25793-1-git-send-email-l.majewski@samsung.com> References: <1418897591-18332-1-git-send-email-l.majewski@samsung.com> <1425470624-25793-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrKLMWRmVeSWpSXmKPExsVy+t9jAd0jX76FGJxbKmrxeM1iJov5R86x Wsy/co3VYundT2wWP15fYLNY81fJonfBVTaL/sevmS3ePOK2ePNwM6PF5V1z2Cw+9x5htJhx fh+TxZOFZ5gs7kzby2Yx/fhbVgcBj7/Pr7N47Jx1l91j06pONo8HE3ezeayb9pbZY+f3BnaP vi2rGD02n672+LxJLoAzissmJTUnsyy1SN8ugStja+9upoJOwYp77XfZGxjP8HYxcnJICJhI vDj5ghnCFpO4cG89WxcjF4eQwCJGiZ/HtrFDOF1MEmeXvmMDqWIT0JP4fPcpE0hCRGA7o8SK ed/AWpgFrjFL7Nt8lAmkSlggW+J743xWEJtFQFVi5d35YDt4Bdwkdmx7ygaxT1Gi+9kEMJtT wF3i+qMWFoh1zYwSi05+YZ/AyLuAkWEVo2hqQXJBcVJ6rqFecWJucWleul5yfu4mRnBgP5Pa wbiyweIQowAHoxIPb0b0txAh1sSy4srcQ4wSHMxKIryxF4FCvCmJlVWpRfnxRaU5qcWHGKU5 WJTEeZXs20KEBNITS1KzU1MLUotgskwcnFINjGsOGs7c1XLJ4tTnNYcn3/NKKlS8ackzVTP+ TN6qVC1xxR1nXx21+eVxpNHFc4+t3rfXP6Y4uh4NPVQjYB7Q8yzia3p438XAA0wSM86ESRhs 63mSn3Ygb+MuGcPp3pUNW0yCTk2r2hvyVZF3odWEsnX7jdIW6rFtZrKQtNp2+uq9hR4nuVgv vFdiKc5INNRiLipOBAClsiVhaAIAAA== 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 It was necessary to decouple code handling writing to sysfs from the one responsible for setting PWM of the fan. Due to that, new __set_pwm() method was extracted, which is responsible for only setting new PWM duty cycle. Signed-off-by: Lukasz Majewski --- Changes for v2: - None Changes for v3: - The commit headline has been reedited. Changes for v4: - Protect "if (ctx->pwm_value == pwm)" with ctx lock - Initialize ret with zero Changes for v5: - None Changes for v6: - None --- drivers/hwmon/pwm-fan.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 1991d903..bd42d39 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -33,20 +33,14 @@ struct pwm_fan_ctx { unsigned char pwm_value; }; -static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) { - struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); - unsigned long pwm, duty; - ssize_t ret; - - if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) - return -EINVAL; + unsigned long duty; + int ret = 0; mutex_lock(&ctx->lock); - if (ctx->pwm_value == pwm) - goto exit_set_pwm_no_change; + goto exit_set_pwm_err; if (pwm == 0) { pwm_disable(ctx->pwm); @@ -66,13 +60,28 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, exit_set_pwm: ctx->pwm_value = pwm; -exit_set_pwm_no_change: - ret = count; exit_set_pwm_err: mutex_unlock(&ctx->lock); return ret; } +static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); + unsigned long pwm; + int ret; + + if (kstrtoul(buf, 10, &pwm) || pwm > MAX_PWM) + return -EINVAL; + + ret = __set_pwm(ctx, pwm); + if (ret) + return ret; + + return count; +} + static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, char *buf) {