From patchwork Wed Mar 30 20:03:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 8702941 Return-Path: X-Original-To: patchwork-intel-gfx@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 2A6FB9F44D for ; Wed, 30 Mar 2016 20:07:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3320C20389 for ; Wed, 30 Mar 2016 20:07:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 29E2920383 for ; Wed, 30 Mar 2016 20:07:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EAA226E8D8; Wed, 30 Mar 2016 20:06:55 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail.free-electrons.com (down.free-electrons.com [37.187.137.238]) by gabe.freedesktop.org (Postfix) with ESMTP id A40066E8A6; Wed, 30 Mar 2016 20:05:45 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id 655B01CC0; Wed, 30 Mar 2016 22:05:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost.localdomain (LFbn-1-2159-240.w90-76.abo.wanadoo.fr [90.76.216.240]) by mail.free-electrons.com (Postfix) with ESMTPSA id AAA341826; Wed, 30 Mar 2016 22:05:19 +0200 (CEST) From: Boris Brezillon To: Thierry Reding , linux-pwm@vger.kernel.org Date: Wed, 30 Mar 2016 22:03:58 +0200 Message-Id: <1459368249-13241-36-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459368249-13241-1-git-send-email-boris.brezillon@free-electrons.com> References: <1459368249-13241-1-git-send-email-boris.brezillon@free-electrons.com> Cc: Milo Kim , Kamil Debski , Heiko Stuebner , linux-doc@vger.kernel.org, David Airlie , Mike Turquette , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, Alexandre Belloni , Daniel Vetter , Lee Jones , linux-clk@vger.kernel.org, linux-leds@vger.kernel.org, Boris Brezillon , Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, Alexander Shiyan , Jonathan Corbet , Robert Jarzmik , lm-sensors@lm-sensors.org, linux-rockchip@lists.infradead.org, Chen-Yu Tsai , Tomi Valkeinen , linux-input@vger.kernel.org, Jean-Christophe Plagniol-Villard , intel-gfx@lists.freedesktop.org, Guenter Roeck , Jean Delvare , Joachim Eastwood , Bryan Wu , Mark Brown , Jacek Anaszewski , linux-arm-kernel@lists.infradead.org, Thomas Petazzoni , Ryan Mallon , Jingoo Han , Dmitry Torokhov , Stephen Boyd , Liam Girdwood , Hartley Sweeten , Richard Purdie , Kukjin Kim , Maxime Ripard Subject: [Intel-gfx] [PATCH v5 35/46] hwmon: pwm-fan: switch to the atomic API X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP pwm_config/enable/disable() have been deprecated and should be replaced by pwm_apply_state(). Signed-off-by: Boris Brezillon Acked-by: Kamil Debski --- drivers/hwmon/pwm-fan.c | 81 ++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 82c5656..da4e4ab 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -40,8 +40,8 @@ struct pwm_fan_ctx { static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) { + struct pwm_state pstate; struct pwm_args pargs = { }; - unsigned long duty; int ret = 0; pwm_get_args(ctx->pwm, &pargs); @@ -50,19 +50,17 @@ static int __set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm) 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; - + pwm_get_state(ctx->pwm, &pstate); + pstate.period = pargs.period; + pstate.duty_cycle = DIV_ROUND_UP(pwm * (pargs.period - 1), MAX_PWM); if (pwm == 0) - pwm_disable(ctx->pwm); + pstate.enabled = false; + else + pstate.enabled = true; - if (ctx->pwm_value == 0) { - ret = pwm_enable(ctx->pwm); - if (ret) - goto exit_set_pwm_err; - } + ret = pwm_apply_state(ctx->pwm, &pstate); + if (ret) + goto exit_set_pwm_err; ctx->pwm_value = pwm; exit_set_pwm_err: @@ -217,10 +215,10 @@ static int pwm_fan_of_get_cooling_data(struct device *dev, static int pwm_fan_probe(struct platform_device *pdev) { struct thermal_cooling_device *cdev; + struct pwm_state pstate; struct pwm_args pargs = { }; struct pwm_fan_ctx *ctx; struct device *hwmon; - int duty_cycle; int ret; ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); @@ -239,27 +237,25 @@ static int pwm_fan_probe(struct platform_device *pdev) /* Set duty cycle to maximum allowed */ pwm_get_args(ctx->pwm, &pargs); - duty_cycle = pargs.period - 1; + pwm_get_state(ctx->pwm, &pstate); + + pstate.period = pargs.period; + pstate.duty_cycle = pargs.period - 1; + pstate.enabled = true; ctx->pwm_value = MAX_PWM; - ret = pwm_config(ctx->pwm, duty_cycle, pargs.period); + ret = pwm_apply_state(ctx->pwm, &pstate); if (ret) { dev_err(&pdev->dev, "Failed to configure PWM\n"); return ret; } - /* Enbale PWM output */ - ret = pwm_enable(ctx->pwm); - if (ret) { - dev_err(&pdev->dev, "Failed to enable PWM\n"); - return ret; - } - hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan", ctx, pwm_fan_groups); if (IS_ERR(hwmon)) { dev_err(&pdev->dev, "Failed to register hwmon device\n"); - pwm_disable(ctx->pwm); + pstate.enabled = false; + pwm_apply_state(ctx->pwm, &pstate); return PTR_ERR(hwmon); } @@ -275,7 +271,8 @@ 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); + pstate.enabled = false; + pwm_apply_state(ctx->pwm, &pstate); return PTR_ERR(cdev); } ctx->cdev = cdev; @@ -290,8 +287,14 @@ static int pwm_fan_remove(struct platform_device *pdev) struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev); thermal_cooling_device_unregister(ctx->cdev); - if (ctx->pwm_value) - pwm_disable(ctx->pwm); + if (ctx->pwm_value) { + struct pwm_state pstate; + + pwm_get_state(ctx->pwm, &pstate); + pstate.enabled = false; + pwm_apply_state(ctx->pwm, &pstate); + } + return 0; } @@ -300,27 +303,35 @@ static int pwm_fan_suspend(struct device *dev) { struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); - if (ctx->pwm_value) - pwm_disable(ctx->pwm); + if (ctx->pwm_value) { + struct pwm_state pstate; + + pwm_get_state(ctx->pwm, &pstate); + pstate.enabled = false; + pwm_apply_state(ctx->pwm, &pstate); + } + return 0; } static int pwm_fan_resume(struct device *dev) { struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); + struct pwm_state pstate; struct pwm_args pargs = { }; - unsigned long duty; - int ret; if (ctx->pwm_value == 0) return 0; pwm_get_args(ctx->pwm, &pargs); - duty = DIV_ROUND_UP(ctx->pwm_value * (pargs.period - 1), MAX_PWM); - ret = pwm_config(ctx->pwm, duty, pargs.period); - if (ret) - return ret; - return pwm_enable(ctx->pwm); + pwm_get_state(ctx->pwm, &pstate); + + pstate.period = pargs.period; + pstate.duty_cycle = DIV_ROUND_UP(ctx->pwm_value * (pargs.period - 1), + MAX_PWM); + pstate.enabled = true; + + return pwm_apply_state(ctx->pwm, &pstate); } #endif