Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp809546imj; Sat, 9 Feb 2019 08:22:02 -0800 (PST) X-Google-Smtp-Source: AHgI3IZtnIUp5A43jOZr2hNIHWJuQ4ghl8doaNlj21wpppCi23oGpE7zLM/TI4qM3ZeloJYWXyJC X-Received: by 2002:a62:4b4d:: with SMTP id y74mr28061746pfa.186.1549729322640; Sat, 09 Feb 2019 08:22:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549729322; cv=none; d=google.com; s=arc-20160816; b=v+kH5TKn268iMhPMKV6axgTGgWgS72oZ66A+Nayxx6PPh6EMNkfCNf/p1ul22p7tpi VDEmVgpOGAEaptZkSCa7eEKqLxs9GxGlTe2ydUmzzvCJMe4zykYr0TANXEKBbaotAyqt 3kcSadZ5qDXlD5zkrG/JmNX8FKfqlN+zFpN7z1kIW7h3OyBVlc05F+nQQ+qYj0ii05yO vY6uRMFX+0dCWE/TFVadY7RhyNyo9XBtjCaDqnZR8By8oxCZyIV4qGEYQWRuEBfup9je ABVX09vsUHL28bDj/a65PA7D6c0ZrTgxflIDPtK+/X3plGbha/jnuyvWrpcrRbqU1u9b nPuw== 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=8DATw/WV/LYtQbV4vifA4UD/zrt0qR+5tUDNs//yI3Y=; b=irMjbzCSy29Ppfwq5FQUyky9N6X3ohi+s8LJXHh31eloJrKBxmjhkao/UQv23Y4ntL N+jIMsVUa38plFzc+Z+0e3q63B0PwrsyIZ68d6U0zqvWBZ8yDSKbB3f8Uec56sIrxJzW ZPXfkt5Q4fpbNDnwi9zE6Z8YnGig+4/ZGLpYWbc8OKG3Gs5F8bodYfok3XSCzhob0n1w UAWxxN8y8/KdlsCZ5ugpBX/yI3XNFFtSrSUfvrci2dLzhZb5nTUPvUeNjK5Ws+jDoZWi /4P4v9nhNMhrhVwWLVjKmjN4NyCicrgg0hj+8fZ+/acLxfZj7fyYvUaMcYTtVmF71qFz xB8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yWgd0+UO; 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 q90si5515475pfi.214.2019.02.09.08.21.46; Sat, 09 Feb 2019 08:22:02 -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=yWgd0+UO; 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 S1727037AbfBIQVl (ORCPT + 99 others); Sat, 9 Feb 2019 11:21:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:37846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726880AbfBIQVl (ORCPT ); Sat, 9 Feb 2019 11:21:41 -0500 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 6D7C621773; Sat, 9 Feb 2019 16:21:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549729300; bh=b+KHT29ZeKLsTBAEvpCqPqqPmSZcaSy2thRyQaseod8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=yWgd0+UOoHooGSYlqa0T7782h063nHtNFqk3yc9RAF0/PwzvnDG9e9EX+QJrC0MXH Au40D7x4/ywMkPZLWphXxBlBOfLOhpK2bg4UuTXF3JvAQPpIKwvUPwQIZCL3OyN97Y MI16IhG68l7cfteEYPSvhFCEYsdq+g7Ic7Nlge28= Date: Sat, 9 Feb 2019 16:21:33 +0000 From: Jonathan Cameron To: Fabrice Gasnier Cc: , , , , , , , , , , , Subject: Re: [PATCH 4/4] iio: counter: stm32-lptimer: Add power management support Message-ID: <20190209162133.65e6fd93@archlinux> In-Reply-To: <1549370429-19116-5-git-send-email-fabrice.gasnier@st.com> References: <1549370429-19116-1-git-send-email-fabrice.gasnier@st.com> <1549370429-19116-5-git-send-email-fabrice.gasnier@st.com> X-Mailer: Claws Mail 3.17.3 (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 Tue, 5 Feb 2019 13:40:29 +0100 Fabrice Gasnier wrote: > Add suspend/resume PM sleep ops. When going to low power, disable > active counter. Only active counter should be resumed: don't touch > disabled counter, as it may be used by other LPTimer MFD child driver. > > Signed-off-by: Fabrice Gasnier I think this looks fine. I'm not totally sure if patches 3,4 are separable from 1,2 though so please let me know whether I should take these now, or let all 4 go in together via some path? Thanks, Jonathan > --- > drivers/iio/counter/stm32-lptimer-cnt.c | 55 +++++++++++++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > > diff --git a/drivers/iio/counter/stm32-lptimer-cnt.c b/drivers/iio/counter/stm32-lptimer-cnt.c > index 42fb8ba..2a49cce 100644 > --- a/drivers/iio/counter/stm32-lptimer-cnt.c > +++ b/drivers/iio/counter/stm32-lptimer-cnt.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > > struct stm32_lptim_cnt { > @@ -23,6 +24,7 @@ struct stm32_lptim_cnt { > u32 preset; > u32 polarity; > u32 quadrature_mode; > + bool enabled; > }; > > static int stm32_lptim_is_enabled(struct stm32_lptim_cnt *priv) > @@ -50,6 +52,7 @@ static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv, > > if (!enable) { > clk_disable(priv->clk); > + priv->enabled = false; > return 0; > } > > @@ -79,6 +82,7 @@ static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv, > regmap_write(priv->regmap, STM32_LPTIM_CR, 0); > return ret; > } > + priv->enabled = true; > > /* Start LP timer in continuous mode */ > return regmap_update_bits(priv->regmap, STM32_LPTIM_CR, > @@ -361,6 +365,56 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev) > return devm_iio_device_register(&pdev->dev, indio_dev); > } > > +#ifdef CONFIG_PM_SLEEP > +static int stm32_lptim_cnt_suspend(struct device *dev) > +{ > + struct stm32_lptim_cnt *priv = dev_get_drvdata(dev); > + int ret; > + > + /* Only take care of enabled counter: don't disturb other MFD child */ > + if (priv->enabled) { > + ret = stm32_lptim_setup(priv, 0); > + if (ret) > + return ret; > + > + ret = stm32_lptim_set_enable_state(priv, 0); > + if (ret) > + return ret; > + > + /* Force enable state for later resume */ > + priv->enabled = true; > + } > + > + return pinctrl_pm_select_sleep_state(dev); > +} > + > +static int stm32_lptim_cnt_resume(struct device *dev) > +{ > + struct stm32_lptim_cnt *priv = dev_get_drvdata(dev); > + int ret; > + > + ret = pinctrl_pm_select_default_state(dev); > + if (ret) > + return ret; > + > + if (priv->enabled) { > + priv->enabled = false; > + ret = stm32_lptim_setup(priv, 1); > + if (ret) > + return ret; > + > + ret = stm32_lptim_set_enable_state(priv, 1); > + if (ret) > + return ret; > + } > + > + return 0; > +} > +#endif > + > +static SIMPLE_DEV_PM_OPS(stm32_lptim_cnt_pm_ops, stm32_lptim_cnt_suspend, > + stm32_lptim_cnt_resume); > + > static const struct of_device_id stm32_lptim_cnt_of_match[] = { > { .compatible = "st,stm32-lptimer-counter", }, > {}, > @@ -372,6 +426,7 @@ static int stm32_lptim_cnt_probe(struct platform_device *pdev) > .driver = { > .name = "stm32-lptimer-counter", > .of_match_table = stm32_lptim_cnt_of_match, > + .pm = &stm32_lptim_cnt_pm_ops, > }, > }; > module_platform_driver(stm32_lptim_cnt_driver);