From patchwork Mon Nov 16 08:56:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 7622351 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8B982BF90C for ; Mon, 16 Nov 2015 09:00:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A255A205AA for ; Mon, 16 Nov 2015 09:00:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83666205B5 for ; Mon, 16 Nov 2015 09:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752839AbbKPJAb (ORCPT ); Mon, 16 Nov 2015 04:00:31 -0500 Received: from down.free-electrons.com ([37.187.137.238]:34687 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752406AbbKPI5N (ORCPT ); Mon, 16 Nov 2015 03:57:13 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id F1E01441; Mon, 16 Nov 2015 09:57:10 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost.localdomain (AToulouse-657-1-1082-82.w92-146.abo.wanadoo.fr [92.146.160.82]) by mail.free-electrons.com (Postfix) with ESMTPSA id A29B3442; Mon, 16 Nov 2015 09:57:09 +0100 (CET) From: Boris Brezillon To: Thierry Reding , linux-pwm@vger.kernel.org Cc: Mike Turquette , Stephen Boyd , linux-clk@vger.kernel.org, Mark Brown , Liam Girdwood , Kamil Debski , lm-sensors@lm-sensors.org, Jean Delvare , Guenter Roeck , Dmitry Torokhov , linux-input@vger.kernel.org, Bryan Wu , Richard Purdie , Jacek Anaszewski , linux-leds@vger.kernel.org, Maxime Ripard , Chen-Yu Tsai , linux-sunxi@googlegroups.com, Joachim Eastwood , Thomas Petazzoni , Heiko Stuebner , linux-rockchip@lists.infradead.org, Jingoo Han , Lee Jones , linux-fbdev@vger.kernel.org, Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Robert Jarzmik , Alexandre Belloni , Julia Lawall , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Boris Brezillon Subject: [PATCH v4 16/24] pwm: move the enabled/disabled info to pwm_state struct Date: Mon, 16 Nov 2015 09:56:39 +0100 Message-Id: <1447664207-24370-17-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com> References: <1447664207-24370-1-git-send-email-boris.brezillon@free-electrons.com> Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prepare the transition to PWM atomic update by moving the enabled/disabled state into the pwm_state struct. This way we can easily update the whole PWM state by copying the new state in the ->state field. Signed-off-by: Boris Brezillon Tested-by: Heiko Stuebner --- drivers/pwm/core.c | 17 +++++++++++++---- include/linux/pwm.h | 7 ++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index f1c6769..6bbda6c 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -508,10 +508,10 @@ int pwm_enable(struct pwm_device *pwm) mutex_lock(&pwm->lock); - if (!test_and_set_bit(PWMF_ENABLED, &pwm->flags)) { + if (!pwm_is_enabled(pwm)) { err = pwm->chip->ops->enable(pwm->chip, pwm); - if (err) - clear_bit(PWMF_ENABLED, &pwm->flags); + if (!err) + pwm->state.enabled = true; } mutex_unlock(&pwm->lock); @@ -526,8 +526,17 @@ EXPORT_SYMBOL_GPL(pwm_enable); */ void pwm_disable(struct pwm_device *pwm) { - if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags)) + if (!pwm) + return; + + mutex_lock(&pwm->lock); + + if (pwm_is_enabled(pwm)) { pwm->chip->ops->disable(pwm->chip, pwm); + pwm->state.enabled = false; + } + + mutex_unlock(&pwm->lock); } EXPORT_SYMBOL_GPL(pwm_disable); diff --git a/include/linux/pwm.h b/include/linux/pwm.h index af42299..398c58c 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -76,8 +76,7 @@ enum pwm_polarity { enum { PWMF_REQUESTED = 1 << 0, - PWMF_ENABLED = 1 << 1, - PWMF_EXPORTED = 1 << 2, + PWMF_EXPORTED = 1 << 1, }; /* @@ -85,11 +84,13 @@ enum { * @period: PWM period (in nanoseconds) * @duty_cycle: PWM duty cycle (in nanoseconds) * @polarity: PWM polarity + * @enabled: PWM enabled status */ struct pwm_state { unsigned int period; unsigned int duty_cycle; enum pwm_polarity polarity; + bool enabled; }; /** @@ -117,7 +118,7 @@ struct pwm_device { static inline bool pwm_is_enabled(const struct pwm_device *pwm) { - return test_bit(PWMF_ENABLED, &pwm->flags); + return pwm->state.enabled; } static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)