From patchwork Mon Jul 20 15:32:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 6828901 Return-Path: X-Original-To: patchwork-linux-fbdev@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 2963A9F358 for ; Mon, 20 Jul 2015 15:33:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55C7D20503 for ; Mon, 20 Jul 2015 15:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 64E5320451 for ; Mon, 20 Jul 2015 15:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932220AbbGTPcQ (ORCPT ); Mon, 20 Jul 2015 11:32:16 -0400 Received: from down.free-electrons.com ([37.187.137.238]:56222 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755916AbbGTPcO (ORCPT ); Mon, 20 Jul 2015 11:32:14 -0400 Received: by mail.free-electrons.com (Postfix, from userid 106) id DE4D0372; Mon, 20 Jul 2015 17:32:17 +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=-8.1 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-56-159.w82-125.abo.wanadoo.fr [82.125.234.159]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0BE5D372; Mon, 20 Jul 2015 17:32:17 +0200 (CEST) From: Boris Brezillon To: Thierry Reding , linux-pwm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bryan Wu , Richard Purdie , Jacek Anaszewski , linux-leds@vger.kernel.org, Heiko Stuebner , linux-rockchip@lists.infradead.org, Jingoo Han , Lee Jones , linux-fbdev@vger.kernel.org, Mark Brown , Liam Girdwood , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , Doug Anderson , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Boris Brezillon Subject: [PATCH v2 03/10] pwm: move the enabled/disabled info to pwm_state struct Date: Mon, 20 Jul 2015 17:32:00 +0200 Message-Id: <1437406327-6207-4-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437406327-6207-1-git-send-email-boris.brezillon@free-electrons.com> References: <1437406327-6207-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 --- drivers/pwm/core.c | 15 ++++++++++++--- include/linux/pwm.h | 7 ++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index a6bc8e6..3e830ce 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -474,8 +474,15 @@ EXPORT_SYMBOL_GPL(pwm_set_polarity); */ int pwm_enable(struct pwm_device *pwm) { - if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags)) - return pwm->chip->ops->enable(pwm->chip, pwm); + if (pwm && !pwm_is_enabled(pwm)) { + int err; + + err = pwm->chip->ops->enable(pwm->chip, pwm); + if (!err) + pwm->state.enabled = true; + + return err; + } return pwm ? 0 : -EINVAL; } @@ -487,8 +494,10 @@ EXPORT_SYMBOL_GPL(pwm_enable); */ void pwm_disable(struct pwm_device *pwm) { - if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags)) + if (pwm && pwm_is_enabled(pwm)) { pwm->chip->ops->disable(pwm->chip, pwm); + pwm->state.enabled = false; + } } EXPORT_SYMBOL_GPL(pwm_disable); diff --git a/include/linux/pwm.h b/include/linux/pwm.h index fafed26..f4bc034 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -75,8 +75,7 @@ enum pwm_polarity { enum { PWMF_REQUESTED = 1 << 0, - PWMF_ENABLED = 1 << 1, - PWMF_EXPORTED = 1 << 2, + PWMF_EXPORTED = 1 << 1, }; /** @@ -84,11 +83,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; }; struct pwm_device { @@ -104,7 +105,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)