Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3970404ybv; Mon, 10 Feb 2020 09:46:33 -0800 (PST) X-Google-Smtp-Source: APXvYqwsu4KJNJ2sinpBVW/c/+iyaipaeBfGvIipf64gDD/AJTgCP/JnUMhoUh43z+9jAHhDw9q1 X-Received: by 2002:aca:889:: with SMTP id 131mr135563oii.3.1581356793603; Mon, 10 Feb 2020 09:46:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581356793; cv=none; d=google.com; s=arc-20160816; b=VE9IgV10DGKe7EWY5IVQJvcVAhX9SSuK0jorU2Bhr/GMms3bj0lDgz8FINQAXACGjJ DYuYZNLnRzK48grL5OyJczLO2PgFauYdeOj05UPUZSd2+PJ9QUARpLI0XT6Igbszb6Rb hiAy96IcYSWPa9UlFxdJi+InLszP/zAxAkvkey80Ppr3YyUnJ/8D81cnv44QM633bTGx +KgPLHSwPfAwtdDhooHH7fjTwG/6uBfew0fKIbXIVWuldwbaI43GsTGut5Hub81aD5E+ LIHr0t8ZXMQWMUt1q7CfX0M9fQC1xYdoSJBrkXHraQXxoH9fU9umcHFtyFGiQNeRXyLV og/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=c1zhLfQHfrUfvkp0MTuGkuwB8y82vgQU4IfRGdXFd5k=; b=HCxuowERYj9jI01XI87bA+5pO6CDvsVJH02zRctJSNNE6xJhHvuu7cS8d02F1lT8HF OE7phn+TbpyL8PeaWNLxhiQSHZdTikgjZaICIHrsjWuW/N8zwpp8D3zCsFe/HoPQQ9K9 pxOtVm7jfIrV0ITB2nysX83wGA6+YFNK9tGc6YTS23EmQK9mBcIkAxi9jJPufj5PLhFD 28MHiRrC8sG5UHq4JzczGCqRfDSFPFuX+vVLW+23x2gnc96AsvF4i7WivGyTbAQExDs3 8/DXz9sGszgJa1WtNHEhiEqKW5KunL4TXLmm/9y41BOZ15SqJkxZCkSrZdrUcnR2GENT jjDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bVqj8QgM; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l14si417357oii.37.2020.02.10.09.46.21; Mon, 10 Feb 2020 09:46:33 -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=@gmail.com header.s=20161025 header.b=bVqj8QgM; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728040AbgBJRqJ (ORCPT + 99 others); Mon, 10 Feb 2020 12:46:09 -0500 Received: from mail-yw1-f67.google.com ([209.85.161.67]:45312 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728010AbgBJRqJ (ORCPT ); Mon, 10 Feb 2020 12:46:09 -0500 Received: by mail-yw1-f67.google.com with SMTP id a125so3784812ywe.12; Mon, 10 Feb 2020 09:46:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=c1zhLfQHfrUfvkp0MTuGkuwB8y82vgQU4IfRGdXFd5k=; b=bVqj8QgM5OlikSgs9Kf4RXNCDtoJmQ8E9efAXgds9jlaEE8+UbeRTMgRb5fstC1Mhx k/uub/bsuUK6xPR8j7coolX+ew3ilVxeZCq31NwF6TXcA2Hb+LoyfERWncfohs0bkU8V WzGgCq76QV9mI4MUzvzifjm9XDvYFWfdfASEavK/AQmrfXaLldxGckLWZfEVqzJb11wM ujgBmMnXoXLnfrsQx+fmI9MSue6BDkhA7xo4fdq/IwQomihaNVIb7irhAhenqAd3NMz3 SW28jXWBvrBDX+ft5xVZrOB4r+LSEAuyLMsSsdwdOaWorFAzJR9abp4BwrzfMFfhAWt6 u5cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=c1zhLfQHfrUfvkp0MTuGkuwB8y82vgQU4IfRGdXFd5k=; b=AQGRsMTqq3tDVlFpQ7080pZ2brMGQKa7mx+kwE19nmUbZ9gucpgAGRJR9jIUr3cGYT j/vDRv9Gakyp2qg9Ktv/8EaUlJmTS3LZpnCG0znZSU+qh/8xdR2ilvJDYuj8QJDquk1M /m0d78Vxk84zM6VgDms5O6CgplCmPVaEC7vggvjHOd7zKGDWPAc3P+C9cB5oxbh41o3F qCPlzxNzMr09zkCo6Ajwvj35gsDmbqvbqo1PjVnO5rAPzk2pFT3ZMsPfePU7GETKTUvj rdPKSBUc5soxe7zF5HADXCm7jwMdN0ZzkscVTdf0uYlhlv7hRt4QL9KPVq8N5P0knubM 6kUA== X-Gm-Message-State: APjAAAXB9//ksxg5t22N5TQ3VIKLQaXIOX+/cld/SQW19+TCEJ2gNz0s +sGCGEFRdv/aMHu7nqjweyY= X-Received: by 2002:a0d:cb54:: with SMTP id n81mr1817971ywd.375.1581356766107; Mon, 10 Feb 2020 09:46:06 -0800 (PST) Received: from icarus (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id m62sm530815ywb.107.2020.02.10.09.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 09:46:05 -0800 (PST) Date: Mon, 10 Feb 2020 12:45:50 -0500 From: William Breathitt Gray To: Fabrice Gasnier Cc: jic23@kernel.org, alexandre.torgue@st.com, mcoquelin.stm32@gmail.com, benjamin.gaignard@st.com, linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] counter: stm32-timer-cnt: add power management support Message-ID: <20200210174550.GA4626@icarus> References: <1581355198-30428-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1581355198-30428-1-git-send-email-fabrice.gasnier@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 10, 2020 at 06:19:58PM +0100, Fabrice Gasnier wrote: > Add suspend/resume PM sleep ops. When going to low power, enforce the > counter isn't active. Gracefully restore its state upon resume in case > it's been left enabled prior to suspend. > > Acked-by: William Breathitt Gray > Signed-off-by: Fabrice Gasnier > --- > Changes in v2: > - Don't refuse to suspend in case the counter has been left enabled. > Gracefully disable it and restore its state upon resume. > --- > drivers/counter/stm32-timer-cnt.c | 63 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 63 insertions(+) > > diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c > index 3eafcce..50496f4 100644 > --- a/drivers/counter/stm32-timer-cnt.c > +++ b/drivers/counter/stm32-timer-cnt.c > @@ -12,6 +12,7 @@ > #include Unrelated to your patch but it caught my eye: are iio headers necessary for this file? I suspect they are not needed since this driver does not make use of the IIO interface. William Breathitt Gray > #include > #include > +#include > #include > > #define TIM_CCMR_CCXS (BIT(8) | BIT(0)) > @@ -20,11 +21,20 @@ > #define TIM_CCER_MASK (TIM_CCER_CC1P | TIM_CCER_CC1NP | \ > TIM_CCER_CC2P | TIM_CCER_CC2NP) > > +struct stm32_timer_regs { > + u32 cr1; > + u32 cnt; > + u32 smcr; > + u32 arr; > +}; > + > struct stm32_timer_cnt { > struct counter_device counter; > struct regmap *regmap; > struct clk *clk; > u32 ceiling; > + bool enabled; > + struct stm32_timer_regs bak; > }; > > /** > @@ -224,6 +234,9 @@ static ssize_t stm32_count_enable_write(struct counter_device *counter, > clk_disable(priv->clk); > } > > + /* Keep enabled state to properly handle low power states */ > + priv->enabled = enable; > + > return len; > } > > @@ -358,10 +371,59 @@ 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); > + > + /* Only take care of enabled counter: don't disturb other MFD child */ > + if (priv->enabled) { > + /* Backup registers that may get lost in low power mode */ > + regmap_read(priv->regmap, TIM_SMCR, &priv->bak.smcr); > + regmap_read(priv->regmap, TIM_ARR, &priv->bak.arr); > + regmap_read(priv->regmap, TIM_CNT, &priv->bak.cnt); > + regmap_read(priv->regmap, TIM_CR1, &priv->bak.cr1); > + > + /* Disable the counter */ > + regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0); > + clk_disable(priv->clk); > + } > + > + return pinctrl_pm_select_sleep_state(dev); > +} > + > +static int __maybe_unused stm32_timer_cnt_resume(struct device *dev) > +{ > + struct stm32_timer_cnt *priv = dev_get_drvdata(dev); > + int ret; > + > + ret = pinctrl_pm_select_default_state(dev); > + if (ret) > + return ret; > + > + if (priv->enabled) { > + clk_enable(priv->clk); > + > + /* Restore registers that may have been lost */ > + regmap_write(priv->regmap, TIM_SMCR, priv->bak.smcr); > + regmap_write(priv->regmap, TIM_ARR, priv->bak.arr); > + regmap_write(priv->regmap, TIM_CNT, priv->bak.cnt); > + > + /* Also re-enables the counter */ > + regmap_write(priv->regmap, TIM_CR1, priv->bak.cr1); > + } > + > + return 0; > +} > + > +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 +435,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); > -- > 2.7.4 >