Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp53883ybi; Wed, 29 May 2019 16:32:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5iN/djDwvCA8JYwJQHvCHNnK6z8izpSCoojuGel8AA6RK2KPOuIoI5RyFk/q2qb80y8Aa X-Received: by 2002:a17:902:a98b:: with SMTP id bh11mr676571plb.8.1559172742096; Wed, 29 May 2019 16:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559172742; cv=none; d=google.com; s=arc-20160816; b=bY6P1V8FqR9YPSPQu+t6MGZ9zqcc7kshwQCmln58AIexCpeO/VkbxrX1wr04lsityy JVhQmA+y6EjzHyM0Reg9oRiyGhkdVDpFE+yyvCOtscl5saISKYKMRqZzHoTacXpiVaNy wv4lwB910O7aEzUqpn6tVw+aIIiYagHb5ROcSNJ8j6xAfxBxvuej+UuydVODM/VFnQBq gry6NLH1zll2Pid5vjtdW+7ExBCsAOHXaJohaPLNDqAzN8mvDyY8llis8jDJEvE2BDq8 MplCYVLRi1zn2YznVJ/HcT/pAVD0ODpyIpuf5qk0KewSkkQzjUVMlaHQlNpProkZzd5n wO+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:user-agent:subject:from :to:cc:references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=wRb3Q/1cFvQTi9qxeozCpTEB+F40jHVPPhhQsJHTEp8=; b=m75jxHo9rgGInt2dD7DKilm7j/kwAylzop7HhZRomLwxFYrPTC7hwQacsLBjt3jKZJ s2UFyZkRGwGZjsBmMEUZbOCIWnIyv8v2FuPlzfp4MonCE6/XUWhArthwDxBytrKWjAk8 5p+GVJrvTMF7Y/EuvnWh9l9NLyou790FPItYm9HqSBrI+6ujWcdxI6hFHnWpjDuvSvsk kf3VJKznXyyY0yPmYdvbwZZwTCWN/l75nDWAh9AUGdLNn+tiawJVkwOEr/5svt95lz8Y Ihf1O6jAZH9WG+pwtWZo8YCcLAOGiIn0gbI7JRGG2sOZA9IW2MbPSCZ4xXcfcH0J0Tyc Cruw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Wp9wUtgt; 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 l10si1270103pgk.276.2019.05.29.16.32.03; Wed, 29 May 2019 16:32:22 -0700 (PDT) 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=Wp9wUtgt; 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 S1726610AbfE2Xav (ORCPT + 99 others); Wed, 29 May 2019 19:30:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:48304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726240AbfE2Xav (ORCPT ); Wed, 29 May 2019 19:30:51 -0400 Received: from kernel.org (unknown [104.132.0.74]) (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 A7E5924371; Wed, 29 May 2019 23:30:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559172649; bh=LI/SipH9I2k+fGVj863RGRAG5O4wgRHhltiAO+zLezo=; h=In-Reply-To:References:Cc:To:From:Subject:Date:From; b=Wp9wUtgtuKs4M89aPqIkYP3bYXkyWNF0DHHm8tvmzDhDY6pHnpwAa+R5eBW5kYbJo RNNDoQTzrigmV31NWRZrI9ht/hodt3h9VstLMeQU+QTP0ey7QmYJTTljkc9k2PH5On dBK7ZQcYfw4FszlZRVa3C5UGWnq3UFnAu1Pa3Uo8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <1559084936-4610-5-git-send-email-skomatineni@nvidia.com> References: <1559084936-4610-1-git-send-email-skomatineni@nvidia.com> <1559084936-4610-5-git-send-email-skomatineni@nvidia.com> Cc: pdeschrijver@nvidia.com, pgaikwad@nvidia.com, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, jckuo@nvidia.com, josephl@nvidia.com, talho@nvidia.com, skomatineni@nvidia.com, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, mperttunen@nvidia.com, spatra@nvidia.com, robh+dt@kernel.org, devicetree@vger.kernel.org To: Sowjanya Komatineni , jason@lakedaemon.net, jonathanh@nvidia.com, linus.walleij@linaro.org, marc.zyngier@arm.com, mark.rutland@arm.com, stefan@agner.ch, tglx@linutronix.de, thierry.reding@gmail.com From: Stephen Boyd Subject: Re: [PATCH V2 04/12] clk: tegra: add support for peripheral clock suspend and resume User-Agent: alot/0.8.1 Date: Wed, 29 May 2019 16:30:48 -0700 Message-Id: <20190529233049.A7E5924371@mail.kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Sowjanya Komatineni (2019-05-28 16:08:48) > This patch implements peripheral clock context save and restore > to support system suspend and resume operation. Again, why? > diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c > index 6f2862eddad7..08b788766564 100644 > --- a/drivers/clk/tegra/clk.c > +++ b/drivers/clk/tegra/clk.c > @@ -81,6 +81,10 @@ static struct clk **clks; > static int clk_num; > static struct clk_onecell_data clk_data; > =20 > +#ifdef CONFIG_PM_SLEEP > +static u32 *periph_ctx; > +#endif Please move this into the ifdef below. > + > /* Handlers for SoC-specific reset lines */ > static int (*special_reset_assert)(unsigned long); > static int (*special_reset_deassert)(unsigned long); > @@ -210,6 +214,65 @@ const struct tegra_clk_periph_regs *get_reg_bank(int= clkid) > } > } > =20 > +#ifdef CONFIG_PM_SLEEP > +void tegra_clk_periph_suspend(void __iomem *clk_base) > +{ > + int i, idx; > + > + idx =3D 0; > + for (i =3D 0; i < periph_banks; i++, idx++) > + periph_ctx[idx] =3D > + readl_relaxed(clk_base + periph_regs[i].rst_reg); > + > + for (i =3D 0; i < periph_banks; i++, idx++) > + periph_ctx[idx] =3D > + readl_relaxed(clk_base + periph_regs[i].enb_reg); > +} > + > +void tegra_clk_periph_force_on(u32 *clks_on, int count, void __iomem *cl= k_base) > +{ > + int i; > + > + WARN_ON(count !=3D periph_banks); > + > + for (i =3D 0; i < count; i++) > + writel_relaxed(clks_on[i], clk_base + periph_regs[i].enb_= reg); > +} > + > +void tegra_clk_periph_resume(void __iomem *clk_base) > +{ > + int i, idx; > + > + idx =3D 0; > + for (i =3D 0; i < periph_banks; i++, idx++) > + writel_relaxed(periph_ctx[idx], > + clk_base + periph_regs[i].rst_reg); > + > + /* ensure all resets have propagated */ > + fence_udelay(2, clk_base); > + tegra_read_chipid(); > + > + for (i =3D 0; i < periph_banks; i++, idx++) > + writel_relaxed(periph_ctx[idx], > + clk_base + periph_regs[i].enb_reg); > + > + /* ensure all enables have propagated */ > + fence_udelay(2, clk_base); > + tegra_read_chipid(); > +} > + > +static int tegra_clk_suspend_ctx_init(int banks) > +{ > + int err =3D 0; > + > + periph_ctx =3D kzalloc(2 * banks * sizeof(*periph_ctx), GFP_KERNE= L); Is this kcalloc(2 * banks, sizeof(*periph_ctx)... ? > + if (!periph_ctx) > + err =3D -ENOMEM; > + > + return err; > +} > +#endif > + > struct clk ** __init tegra_clk_init(void __iomem *regs, int num, int ban= ks) > { > clk_base =3D regs; > @@ -226,11 +289,20 @@ struct clk ** __init tegra_clk_init(void __iomem *r= egs, int num, int banks) > periph_banks =3D banks; > =20 > clks =3D kcalloc(num, sizeof(struct clk *), GFP_KERNEL); > - if (!clks) > + if (!clks) { > kfree(periph_clk_enb_refcnt); > + return NULL; > + } > =20 > clk_num =3D num; > =20 > +#ifdef CONFIG_PM_SLEEP Can you use if (IS_ENABLED(CONFIG_PM_SLEEP)) here? > + if (tegra_clk_suspend_ctx_init(banks)) { > + kfree(periph_clk_enb_refcnt); > + kfree(clks); > + return NULL; > + } > +#endif > return clks; > } > =20