Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1862558ybv; Sat, 8 Feb 2020 07:36:39 -0800 (PST) X-Google-Smtp-Source: APXvYqy5XC3LL2coy/oU4I+0kK7D9DdTYEA/FAmUP2R7IWOrYeXnwpRmJiuAM/Jm2kCav95uDian X-Received: by 2002:a05:6808:315:: with SMTP id i21mr5372743oie.139.1581176199076; Sat, 08 Feb 2020 07:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581176199; cv=none; d=google.com; s=arc-20160816; b=SlV9x8qgPWFhHwYXdZOcHWeAhxjWXpe8jbWqSvFqAz5ei15A2HlyOVnwOWYsfBCr6h VbwHF3LQtqHSmhdLd3C5KHUtU+1ujMYE/1uynoMC/gY/EgDlF+YK5GjJdWOcKXpjfBSV lzS+FbkqiqXivLCEDtaUpzFPxQBGehHyz4t9GfXmVr2afjem/yMaLIAoL5UVVQHScgIP x1lt9hPJuPoa9TXywr3LUAwU4F7BtJZUDYLVVqUxxV/IVg05ZieJSzy/zskfCPZVD8YM xPcE8tRwN8AZgpbYo5Qq8KiGLmDmm8wWx3rBqrAok4F+Fz4G9Dwe+l1Pxiin3T2IE11P B3rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=CRZqjsvS9gdeo0H8F8uHWVFfX2OQqj3P5MZvVu4m4H4=; b=XwC4udXm6PP6l5zMQ+K/m3CsDzf/kauF9NLWYU/lzk+QzuSog68arukyLj6SH6sACL W/IbtnOL8MOEbBFqCUD51WTOyGUqpJs2gqZ8tZxqENeIj2qFKCGHzIHVHi3RAchHUVNt XqMOM7kwDkR4S/DnFjo4dKkpuyG/cmXtD04EvC6aNJ9s9p7BY/ekYEFDGE/NddNzKSwl OYLn+f1rIWBTRhVVv2AJENylludglvs0QqRP2yCVimK8FArFQlFGos4cOWx5bMrRBsrM uiDd5saLgGix1ZD6eEYNGZp11JM5rX0thcc0arJHPINRMqczbu5SAqs2RnWceLGjH+xT NfbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DD8iRaVl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si1616790otq.209.2020.02.08.07.36.17; Sat, 08 Feb 2020 07:36:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DD8iRaVl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727387AbgBHPfq (ORCPT + 99 others); Sat, 8 Feb 2020 10:35:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:56952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727303AbgBHPfq (ORCPT ); Sat, 8 Feb 2020 10:35:46 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5257E21741; Sat, 8 Feb 2020 15:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581176145; bh=qC4ltT8jNAGr/7Ix9q3BWAQAqxE+4oG2Cf9FzB/RJgk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DD8iRaVlpBlQTfZEGEH+GWuR9Xg1vWL2vsI2WQekrUAx2RhQ2oDB+EMUknDLIRo8N vPeH8J6dpHX3eOZTzpmUre1dyt6U3+ZqEGex+SKwHIdFHV3g2g9BiWW0x9KdIqYkiL yJqrgffQjmExWokIwNfk68BWvBWdKg6QdsH2IL7A= Date: Sat, 8 Feb 2020 15:35:41 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , Subject: Re: [PATCH] counter: stm32-timer-cnt: add power management support Message-ID: <20200208153541.448a0df3@archlinux> In-Reply-To: <1580899678-26393-1-git-send-email-fabrice.gasnier@st.com> References: <1580899678-26393-1-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 5 Feb 2020 11:47:58 +0100 Fabrice Gasnier wrote: > Add suspend/resume PM sleep ops. When going to low power, enforce the > counter isn't active. > > Signed-off-by: Fabrice Gasnier > --- > drivers/counter/stm32-timer-cnt.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c > index 3eafcce..3b84503 100644 > --- a/drivers/counter/stm32-timer-cnt.c > +++ b/drivers/counter/stm32-timer-cnt.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > > #define TIM_CCMR_CCXS (BIT(8) | BIT(0)) > @@ -358,10 +359,33 @@ static int stm32_timer_cnt_probe(struct platform_device *pdev) > priv->counter.num_signals = ARRAY_SIZE(stm32_signals); > priv->counter.priv = priv; > > + platform_set_drvdata(pdev, priv); > + > /* Register Counter device */ > return devm_counter_register(dev, &priv->counter); > } > > +static int __maybe_unused stm32_timer_cnt_suspend(struct device *dev) > +{ > + struct stm32_timer_cnt *priv = dev_get_drvdata(dev); > + u32 cr1; > + > + /* Check for active counter */ > + regmap_read(priv->regmap, TIM_CR1, &cr1); > + if (cr1 & TIM_CR1_CEN) > + return -EBUSY; Runtime suspend is allowed to refuse to happen (and that is explicitly documented) Is that allowed for normal suspend? I didn't think it was. This will stop a suspend, but it's doing it by signalling a failure. I'm not sure for example that the system will resume everything that was suspended before this call. Normally you are in the tough luck category if a system decides to suspend underneath you. There are ways to prevent it from userspace (wakelocks etc). > + > + return pinctrl_pm_select_sleep_state(dev); > +} > + > +static int __maybe_unused stm32_timer_cnt_resume(struct device *dev) > +{ > + return pinctrl_pm_select_default_state(dev); > +} > + > +static SIMPLE_DEV_PM_OPS(stm32_timer_cnt_pm_ops, stm32_timer_cnt_suspend, > + stm32_timer_cnt_resume); > + > static const struct of_device_id stm32_timer_cnt_of_match[] = { > { .compatible = "st,stm32-timer-counter", }, > {}, > @@ -373,6 +397,7 @@ static struct platform_driver stm32_timer_cnt_driver = { > .driver = { > .name = "stm32-timer-counter", > .of_match_table = stm32_timer_cnt_of_match, > + .pm = &stm32_timer_cnt_pm_ops, > }, > }; > module_platform_driver(stm32_timer_cnt_driver);