From patchwork Wed May 29 07:47:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 1106925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=renesas.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45DNHD4dVlz9s3l for ; Wed, 29 May 2019 17:52:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbfE2Hwy (ORCPT ); Wed, 29 May 2019 03:52:54 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:7651 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725895AbfE2Hwy (ORCPT ); Wed, 29 May 2019 03:52:54 -0400 X-IronPort-AV: E=Sophos;i="5.60,526,1549897200"; d="scan'208";a="17060847" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 29 May 2019 16:52:52 +0900 Received: from localhost.localdomain (unknown [10.166.17.210]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 536B24009418; Wed, 29 May 2019 16:52:52 +0900 (JST) From: Yoshihiro Shimoda To: thierry.reding@gmail.com Cc: linux-pwm@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 1/4] pwm: Add power management descriptions Date: Wed, 29 May 2019 16:47:59 +0900 Message-Id: <1559116082-9851-2-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org This patch adds power management descriptions that consumers should implement it. Signed-off-by: Yoshihiro Shimoda --- Documentation/pwm.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/pwm.txt b/Documentation/pwm.txt index 8fbf0aa..996e5ea 100644 --- a/Documentation/pwm.txt +++ b/Documentation/pwm.txt @@ -65,6 +65,10 @@ period). struct pwm_args contains 2 fields (period and polarity) and should be used to set the initial PWM config (usually done in the probe function of the PWM user). PWM arguments are retrieved with pwm_get_args(). +All consumers should really be reconfiguring the PWM upon resume as +appropriate. This is the only way to ensure that everything is resumed in +the proper order. + Using PWMs with the sysfs interface ----------------------------------- @@ -141,6 +145,9 @@ The implementation of ->get_state() (a method used to retrieve initial PWM state) is also encouraged for the same reason: letting the PWM user know about the current PWM state would allow him to avoid glitches. +Drivers should not implement any power management. In other words, +consumers should implement it as described as the "Using PWMs" section. + Locking ------- From patchwork Wed May 29 07:48:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 1106926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=renesas.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45DNHF1Sgqz9sB8 for ; Wed, 29 May 2019 17:52:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726245AbfE2Hwz (ORCPT ); Wed, 29 May 2019 03:52:55 -0400 Received: from relmlor1.renesas.com ([210.160.252.171]:25351 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725865AbfE2Hwz (ORCPT ); Wed, 29 May 2019 03:52:55 -0400 X-IronPort-AV: E=Sophos;i="5.60,526,1549897200"; d="scan'208";a="17264014" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 29 May 2019 16:52:52 +0900 Received: from localhost.localdomain (unknown [10.166.17.210]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 77B334003EA5; Wed, 29 May 2019 16:52:52 +0900 (JST) From: Yoshihiro Shimoda To: thierry.reding@gmail.com Cc: linux-pwm@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 2/4] pwm: sysfs: Switch to SPDX identifier Date: Wed, 29 May 2019 16:48:00 +0900 Message-Id: <1559116082-9851-3-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org Adopt the SPDX license identifier headers to ease license compliance management. Signed-off-by: Yoshihiro Shimoda --- drivers/pwm/sysfs.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 719f8fa..7eb4a13 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -1,19 +1,10 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * A simple sysfs interface for the generic PWM framework * * Copyright (C) 2013 H Hartley Sweeten * * Based on previous work by Lars Poeschel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. */ #include From patchwork Wed May 29 07:48:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 1106927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=renesas.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45DNHF4l78z9sBb for ; Wed, 29 May 2019 17:52:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725865AbfE2Hw4 (ORCPT ); Wed, 29 May 2019 03:52:56 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:7651 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725895AbfE2Hw4 (ORCPT ); Wed, 29 May 2019 03:52:56 -0400 X-IronPort-AV: E=Sophos;i="5.60,526,1549897200"; d="scan'208";a="17060850" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 29 May 2019 16:52:52 +0900 Received: from localhost.localdomain (unknown [10.166.17.210]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 9BD334001DCA; Wed, 29 May 2019 16:52:52 +0900 (JST) From: Yoshihiro Shimoda To: thierry.reding@gmail.com Cc: linux-pwm@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 3/4] pwm: sysfs: Add suspend/resume support Date: Wed, 29 May 2019 16:48:01 +0900 Message-Id: <1559116082-9851-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org According to the Documentation/pwm.txt, all PWM consumers should have power management. Since this sysfs interface is one of consumers so that this patch adds suspend/resume support. Signed-off-by: Yoshihiro Shimoda --- drivers/pwm/sysfs.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c index 7eb4a13..72dafdd 100644 --- a/drivers/pwm/sysfs.c +++ b/drivers/pwm/sysfs.c @@ -18,6 +18,7 @@ struct pwm_export { struct device child; struct pwm_device *pwm; struct mutex lock; + bool enabled_in_suspend; }; static struct pwm_export *child_to_pwm_export(struct device *child) @@ -372,10 +373,73 @@ static struct attribute *pwm_chip_attrs[] = { }; ATTRIBUTE_GROUPS(pwm_chip); +static int pwm_class_suspend_resume(struct device *parent, bool suspend) +{ + struct pwm_chip *chip = dev_get_drvdata(parent); + unsigned int i; + int ret = 0; + + for (i = 0; i < chip->npwm; i++) { + struct pwm_device *pwm = &chip->pwms[i]; + struct device *child; + struct pwm_export *export; + struct pwm_state state; + + if (!test_bit(PWMF_EXPORTED, &pwm->flags)) + continue; + + child = device_find_child(parent, pwm, pwm_unexport_match); + if (!child) + goto rollback; + + export = child_to_pwm_export(child); + put_device(child); /* for device_find_child() */ + if (!export) + goto rollback; + + mutex_lock(&export->lock); + pwm_get_state(pwm, &state); + if (suspend) { + if (state.enabled) + export->enabled_in_suspend = true; + state.enabled = false; + } else if (export->enabled_in_suspend) { + state.enabled = true; + export->enabled_in_suspend = false; + } + ret = pwm_apply_state(pwm, &state); + mutex_unlock(&export->lock); + if (ret < 0) + goto rollback; + } + + return ret; + +rollback: + /* roll back only when suspend */ + if (suspend) + pwm_class_suspend_resume(parent, false); + + return ret; +} + +static int pwm_class_suspend(struct device *parent) +{ + return pwm_class_suspend_resume(parent, true); +} + +static int pwm_class_resume(struct device *parent) +{ + return pwm_class_suspend_resume(parent, false); +} + +static SIMPLE_DEV_PM_OPS(pwm_class_pm_ops, pwm_class_suspend, pwm_class_resume); + static struct class pwm_class = { .name = "pwm", .owner = THIS_MODULE, .dev_groups = pwm_chip_groups, + .pm = &pwm_class_pm_ops, }; static int pwmchip_sysfs_match(struct device *parent, const void *data) From patchwork Wed May 29 07:48:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 1106928 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pwm-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=renesas.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 45DNHG0tTjz9s3l for ; Wed, 29 May 2019 17:52:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbfE2Hw4 (ORCPT ); Wed, 29 May 2019 03:52:56 -0400 Received: from relmlor1.renesas.com ([210.160.252.171]:28844 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726141AbfE2Hw4 (ORCPT ); Wed, 29 May 2019 03:52:56 -0400 X-IronPort-AV: E=Sophos;i="5.60,526,1549897200"; d="scan'208";a="17264017" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 29 May 2019 16:52:52 +0900 Received: from localhost.localdomain (unknown [10.166.17.210]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id A79D34003EA5; Wed, 29 May 2019 16:52:52 +0900 (JST) From: Yoshihiro Shimoda To: thierry.reding@gmail.com Cc: linux-pwm@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 4/4] pwm: rcar: Remove suspend/resume support Date: Wed, 29 May 2019 16:48:02 +0900 Message-Id: <1559116082-9851-5-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1559116082-9851-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> Sender: linux-pwm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pwm@vger.kernel.org According to the Documentation/pwm.txt, all PWM consumers should implement power management instead of the PWM driver. So, this patch removes suspend/resume support. Signed-off-by: Yoshihiro Shimoda --- drivers/pwm/pwm-rcar.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c index cfe7dd1..5b2b8ec 100644 --- a/drivers/pwm/pwm-rcar.c +++ b/drivers/pwm/pwm-rcar.c @@ -254,50 +254,11 @@ static const struct of_device_id rcar_pwm_of_table[] = { }; MODULE_DEVICE_TABLE(of, rcar_pwm_of_table); -#ifdef CONFIG_PM_SLEEP -static struct pwm_device *rcar_pwm_dev_to_pwm_dev(struct device *dev) -{ - struct rcar_pwm_chip *rcar_pwm = dev_get_drvdata(dev); - struct pwm_chip *chip = &rcar_pwm->chip; - - return &chip->pwms[0]; -} - -static int rcar_pwm_suspend(struct device *dev) -{ - struct pwm_device *pwm = rcar_pwm_dev_to_pwm_dev(dev); - - if (!test_bit(PWMF_REQUESTED, &pwm->flags)) - return 0; - - pm_runtime_put(dev); - - return 0; -} - -static int rcar_pwm_resume(struct device *dev) -{ - struct pwm_device *pwm = rcar_pwm_dev_to_pwm_dev(dev); - struct pwm_state state; - - if (!test_bit(PWMF_REQUESTED, &pwm->flags)) - return 0; - - pm_runtime_get_sync(dev); - - pwm_get_state(pwm, &state); - - return rcar_pwm_apply(pwm->chip, pwm, &state); -} -#endif /* CONFIG_PM_SLEEP */ -static SIMPLE_DEV_PM_OPS(rcar_pwm_pm_ops, rcar_pwm_suspend, rcar_pwm_resume); - static struct platform_driver rcar_pwm_driver = { .probe = rcar_pwm_probe, .remove = rcar_pwm_remove, .driver = { .name = "pwm-rcar", - .pm = &rcar_pwm_pm_ops, .of_match_table = of_match_ptr(rcar_pwm_of_table), } };