From patchwork Wed Mar 30 20:03:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 8858701 Return-Path: X-Original-To: patchwork-linux-rockchip@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 A9CD69F46C for ; Fri, 15 Apr 2016 20:58:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FFB320379 for ; Fri, 15 Apr 2016 20:58:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 986AB20295 for ; Fri, 15 Apr 2016 20:58:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1arApJ-0000cK-9R; Fri, 15 Apr 2016 20:58:53 +0000 Received: from down.free-electrons.com ([37.187.137.238] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1alMMq-0005AO-QO; Wed, 30 Mar 2016 20:05:33 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id B6A051848; Wed, 30 Mar 2016 22:05:01 +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 ED8761836; Wed, 30 Mar 2016 22:04:49 +0200 (CEST) From: Boris Brezillon To: Thierry Reding , linux-pwm@vger.kernel.org Subject: [PATCH v5 19/46] pwm: switch to the atomic API Date: Wed, 30 Mar 2016 22:03:42 +0200 Message-Id: <1459368249-13241-20-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160330_130529_506707_E1FFDC3F X-CRM114-Status: GOOD ( 14.74 ) X-Spam-Score: -2.9 (--) X-Mailman-Approved-At: Fri, 15 Apr 2016 13:58:39 -0700 X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 , Jani Nikula , 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 , Daniel Vetter , Maxime Ripard MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace legacy pwm_get/set_xxx() and pwm_config/enable/disable() calls by pwm_get/apply_state(). Signed-off-by: Boris Brezillon --- drivers/pwm/core.c | 5 ++++- drivers/pwm/sysfs.c | 61 +++++++++++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 62e6b3c..c2b1569 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -882,13 +882,16 @@ static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) for (i = 0; i < chip->npwm; i++) { struct pwm_device *pwm = &chip->pwms[i]; + struct pwm_state pstate; + + pwm_get_state(pwm, &pstate); seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); if (test_bit(PWMF_REQUESTED, &pwm->flags)) seq_puts(s, " requested"); - if (pwm_is_enabled(pwm)) + if (pstate.enabled) seq_puts(s, " enabled"); seq_puts(s, "\n"); diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index ab28c89..7ec1747 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -47,13 +47,13 @@ static ssize_t period_show(struct device *child, { struct pwm_export *export = child_to_pwm_export(child); const struct pwm_device *pwm = export->pwm; - unsigned int period; + struct pwm_state pstate; mutex_lock(&export->lock); - period = pwm_get_period(pwm); + pwm_get_state(pwm, &pstate); mutex_unlock(&export->lock); - return sprintf(buf, "%u\n", period); + return sprintf(buf, "%u\n", pstate.period); } static ssize_t period_store(struct device *child, @@ -62,6 +62,7 @@ static ssize_t period_store(struct device *child, { struct pwm_export *export = child_to_pwm_export(child); struct pwm_device *pwm = export->pwm; + struct pwm_state pstate; unsigned int val; int ret; @@ -70,7 +71,9 @@ static ssize_t period_store(struct device *child, return ret; mutex_lock(&export->lock); - ret = pwm_config(pwm, pwm_get_duty_cycle(pwm), val); + pwm_get_state(pwm, &pstate); + pstate.period = val; + ret = pwm_apply_state(pwm, &pstate); mutex_unlock(&export->lock); return ret ? : size; @@ -82,13 +85,13 @@ static ssize_t duty_cycle_show(struct device *child, { struct pwm_export *export = child_to_pwm_export(child); const struct pwm_device *pwm = export->pwm; - unsigned int duty; + struct pwm_state pstate; mutex_lock(&export->lock); - duty = pwm_get_duty_cycle(pwm); + pwm_get_state(pwm, &pstate); mutex_unlock(&export->lock); - return sprintf(buf, "%u\n", duty); + return sprintf(buf, "%u\n", pstate.duty_cycle); } static ssize_t duty_cycle_store(struct device *child, @@ -97,6 +100,7 @@ static ssize_t duty_cycle_store(struct device *child, { struct pwm_export *export = child_to_pwm_export(child); struct pwm_device *pwm = export->pwm; + struct pwm_state pstate; unsigned int val; int ret; @@ -105,7 +109,9 @@ static ssize_t duty_cycle_store(struct device *child, return ret; mutex_lock(&export->lock); - ret = pwm_config(pwm, val, pwm_get_period(pwm)); + pwm_get_state(pwm, &pstate); + pstate.duty_cycle = val; + ret = pwm_apply_state(pwm, &pstate); mutex_unlock(&export->lock); return ret ? : size; @@ -117,13 +123,13 @@ static ssize_t enable_show(struct device *child, { struct pwm_export *export = child_to_pwm_export(child); const struct pwm_device *pwm = export->pwm; - bool enabled; + struct pwm_state pstate; mutex_lock(&export->lock); - enabled = pwm_is_enabled(pwm); + pwm_get_state(pwm, &pstate); mutex_unlock(&export->lock); - return sprintf(buf, "%d\n", enabled); + return sprintf(buf, "%d\n", pstate.enabled); } static ssize_t enable_store(struct device *child, @@ -132,24 +138,20 @@ static ssize_t enable_store(struct device *child, { struct pwm_export *export = child_to_pwm_export(child); struct pwm_device *pwm = export->pwm; + struct pwm_state pstate; int val, ret; ret = kstrtoint(buf, 0, &val); if (ret) return ret; + if (val != 0 && val != 1) + return -EINVAL; + mutex_lock(&export->lock); - switch (val) { - case 0: - pwm_disable(pwm); - break; - case 1: - ret = pwm_enable(pwm); - break; - default: - ret = -EINVAL; - break; - } + pwm_get_state(pwm, &pstate); + pstate.enabled = val; + ret = pwm_apply_state(pwm, &pstate); mutex_unlock(&export->lock); return ret ? : size; @@ -162,9 +164,13 @@ static ssize_t polarity_show(struct device *child, struct pwm_export *export = child_to_pwm_export(child); const struct pwm_device *pwm = export->pwm; const char *polarity = "unknown"; + struct pwm_state pstate; mutex_lock(&export->lock); - switch (pwm_get_polarity(pwm)) { + pwm_get_state(pwm, &pstate); + mutex_unlock(&export->lock); + + switch (pstate.polarity) { case PWM_POLARITY_NORMAL: polarity = "normal"; break; @@ -173,7 +179,6 @@ static ssize_t polarity_show(struct device *child, polarity = "inversed"; break; } - mutex_unlock(&export->lock); return sprintf(buf, "%s\n", polarity); } @@ -185,6 +190,7 @@ static ssize_t polarity_store(struct device *child, struct pwm_export *export = child_to_pwm_export(child); struct pwm_device *pwm = export->pwm; enum pwm_polarity polarity; + struct pwm_state pstate; int ret; if (sysfs_streq(buf, "normal")) @@ -195,7 +201,12 @@ static ssize_t polarity_store(struct device *child, return -EINVAL; mutex_lock(&export->lock); - ret = pwm_set_polarity(pwm, polarity); + pwm_get_state(pwm, &pstate); + pstate.polarity = polarity; + if (pstate.enabled) + ret = -EBUSY; + else + ret = pwm_apply_state(pwm, &pstate); mutex_unlock(&export->lock); return ret ? : size;