From patchwork Mon Apr 24 13:13:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartlomiej Zolnierkiewicz X-Patchwork-Id: 9696121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 43D2F60389 for ; Mon, 24 Apr 2017 13:13:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3421A2074F for ; Mon, 24 Apr 2017 13:13:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28D4126B41; Mon, 24 Apr 2017 13:13:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CB7F2074F for ; Mon, 24 Apr 2017 13:13:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1170778AbdDXNNr (ORCPT ); Mon, 24 Apr 2017 09:13:47 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:15206 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934188AbdDXNNp (ORCPT ); Mon, 24 Apr 2017 09:13:45 -0400 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20170424131342epoutp026e1443f8a344587651b87297e906082f~4V6Bk85D90212502125epoutp02m; Mon, 24 Apr 2017 13:13:42 +0000 (GMT) Received: from epsmges5p2.samsung.com (unknown [182.195.42.45]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20170424131342epcas5p4ada1ddb2cb87ebee7a979e4aaf24a593~4V6BZ1vaf2863328633epcas5p4a; Mon, 24 Apr 2017 13:13:42 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2.samsung.com (EPCPMTA) with SMTP id B7.19.21921.60AFDF85; Mon, 24 Apr 2017 22:13:42 +0900 (KST) Received: from epsmgms2p2.samsung.com (unknown [182.195.42.80]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20170424131342epcas5p4cb2f53f6c780119557ff3da56fb8f0a8~4V6BMBlld2863328633epcas5p4Z; Mon, 24 Apr 2017 13:13:42 +0000 (GMT) X-AuditID: b6c32a2d-f792a6d0000055a1-c0-58fdfa0617a7 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p2.samsung.com (Symantec Messaging Gateway) with SMTP id CE.94.26901.60AFDF85; Mon, 24 Apr 2017 22:13:42 +0900 (KST) Received: from AMDC3058.DIGITAL.local ([106.120.53.102]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OOX006JS0QMW870@mmp1.samsung.com>; Mon, 24 Apr 2017 22:13:42 +0900 (KST) From: Bartlomiej Zolnierkiewicz To: Thierry Reding , Jean Delvare , Guenter Roeck , Kamil Debski Cc: Tomasz Figa , linux-pwm@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, b.zolnierkie@samsung.com Subject: [PATCH] hwmon: pwm-fan: switch to new atomic PWM API Date: Mon, 24 Apr 2017 15:13:17 +0200 Message-id: <1493039598-25881-1-git-send-email-b.zolnierkie@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPIsWRmVeSWpSXmKPExsWy7bCmui7br78RBvvuqFtsnLGe1eLshECL mSfaWS3aX29ltLi8aw6bxd27qxgtZpzfx2TxZOEZJoufu+axWK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r31bF2MXBxCAtsYJR6sOsAM4fxilFjV/JIRpIpNwEpiYvsqRpCEiMB0RokZM7ez gjjMAvsYJVZ3TQFq4eAQFrCV+HPaE6SBRUBVYsGhGWwgNq+Ah8S8c/sZIdbJSZw8Npl1AiP3 AkaGVYxcqQXFuem5xUYFRpsYgcG67bBWwA7GpnPRhxgFOBiVeHg3/PwTIcSaWFZcmXuIUYKD WUmE9+2lvxFCvCmJlVWpRfnxRaU5qcWHGE2BVk5klhJNzgdGUl5JvKGJpZGJgZmZoZGBsZmS OO+EwC8RQgLpiSWp2ampBalFMH1MHJxSDYzObG4xK5/0GO5If7p2V6BJhcHi05Ymi7sZ6jdM sH9eLNfhmbw6Ysa6S7/YxSZZGFY2aNZr/I/8xln0+MyNZc0mTWf2HEl5abv5idJ6lkN5Vh7f HOc73I/7xiG5fc3iTMvP83XLevZt0WafH3N/na7JDO8a3QBBrdnRNy9PD/IQadfeeDfLSVOJ pTgj0VCLuag4EQBbeB2sbAIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170424131342epcas5p4cb2f53f6c780119557ff3da56fb8f0a8 X-Msg-Generator: CA X-Sender-IP: 182.195.42.80 X-Local-Sender: =?UTF-8?B?QmFydGxvbWllaiBab2xuaWVya2lld2ljehtTUlBPTC1LZXJu?= =?UTF-8?B?ZWwgKFRQKRvsgrzshLHsoITsnpAbU2VuaW9yIFNvZnR3YXJlIEVuZ2luZWVy?= X-Global-Sender: =?UTF-8?B?QmFydGxvbWllaiBab2xuaWVya2lld2ljehtTUlBPTC1LZXJu?= =?UTF-8?B?ZWwgKFRQKRtTYW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBF?= =?UTF-8?B?bmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 105P X-CMS-RootMailID: 20170424131342epcas5p4cb2f53f6c780119557ff3da56fb8f0a8 X-RootMTR: 20170424131342epcas5p4cb2f53f6c780119557ff3da56fb8f0a8 References: Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Switch pwm-fan driver to new atomic PWM API. Signed-off-by: Bartlomiej Zolnierkiewicz --- Depends on "[PATCH v2 0/3] pwm: pwm-samsung: fix suspend/resume support" patchset (https://www.spinics.net/lists/kernel/msg2495209.html). drivers/hwmon/pwm-fan.c | 68 +++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 9dc40f3..4ac7700 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -40,31 +40,22 @@ struct pwm_fan_ctx { static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) { - struct pwm_args pargs; - unsigned long duty; + unsigned long period; int ret = 0; - - pwm_get_args(ctx->pwm, &pargs); + struct pwm_state state = { }; mutex_lock(&ctx->lock); if (ctx->pwm_value == pwm) goto exit_set_pwm_err; - duty = DIV_ROUND_UP(pwm * (pargs.period - 1), MAX_PWM); - ret = pwm_config(ctx->pwm, duty, pargs.period); - if (ret) - goto exit_set_pwm_err; - - if (pwm == 0) - pwm_disable(ctx->pwm); + pwm_init_state(ctx->pwm, &state); + period = ctx->pwm->args.period; + state.duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM); + state.enabled = pwm ? true : false; - if (ctx->pwm_value == 0) { - ret = pwm_enable(ctx->pwm); - if (ret) - goto exit_set_pwm_err; - } - - ctx->pwm_value = pwm; + ret = pwm_apply_state(ctx->pwm, &state); + if (!ret) + ctx->pwm_value = pwm; exit_set_pwm_err: mutex_unlock(&ctx->lock); return ret; @@ -218,10 +209,9 @@ static int pwm_fan_probe(struct platform_device *pdev) { struct thermal_cooling_device *cdev; struct pwm_fan_ctx *ctx; - struct pwm_args pargs; struct device *hwmon; - int duty_cycle; int ret; + struct pwm_state state = { }; ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); if (!ctx) @@ -237,28 +227,16 @@ static int pwm_fan_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ctx); - /* - * FIXME: pwm_apply_args() should be removed when switching to the - * atomic PWM API. - */ - pwm_apply_args(ctx->pwm); - - /* Set duty cycle to maximum allowed */ - pwm_get_args(ctx->pwm, &pargs); - - duty_cycle = pargs.period - 1; ctx->pwm_value = MAX_PWM; - ret = pwm_config(ctx->pwm, duty_cycle, pargs.period); - if (ret) { - dev_err(&pdev->dev, "Failed to configure PWM\n"); - return ret; - } + /* Set duty cycle to maximum allowed and enable PWM output */ + pwm_init_state(ctx->pwm, &state); + state.duty_cycle = ctx->pwm->args.period - 1; + state.enabled = true; - /* Enbale PWM output */ - ret = pwm_enable(ctx->pwm); + ret = pwm_apply_state(ctx->pwm, &state); if (ret) { - dev_err(&pdev->dev, "Failed to enable PWM\n"); + dev_err(&pdev->dev, "Failed to configure PWM\n"); return ret; } @@ -266,8 +244,8 @@ static int pwm_fan_probe(struct platform_device *pdev) ctx, pwm_fan_groups); if (IS_ERR(hwmon)) { dev_err(&pdev->dev, "Failed to register hwmon device\n"); - pwm_disable(ctx->pwm); - return PTR_ERR(hwmon); + ret = PTR_ERR(hwmon); + goto err_pwm_disable; } ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx); @@ -282,14 +260,20 @@ static int pwm_fan_probe(struct platform_device *pdev) if (IS_ERR(cdev)) { dev_err(&pdev->dev, "Failed to register pwm-fan as cooling device"); - pwm_disable(ctx->pwm); - return PTR_ERR(cdev); + ret = PTR_ERR(cdev); + goto err_pwm_disable; } ctx->cdev = cdev; thermal_cdev_update(cdev); } return 0; + +err_pwm_disable: + state.enabled = false; + pwm_apply_state(ctx->pwm, &state); + + return ret; } static int pwm_fan_remove(struct platform_device *pdev)