Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp792714ybh; Sat, 3 Aug 2019 09:54:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEY4BVTqRfB49xwtYsKUrDz2dnu2pE+STkmeZVIyiOgLHyXmXPOTRTCQTiBpGJV15KC0gj X-Received: by 2002:a17:90a:bb01:: with SMTP id u1mr9800829pjr.92.1564851270670; Sat, 03 Aug 2019 09:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564851270; cv=none; d=google.com; s=arc-20160816; b=rnEeAJJBn/0Upw/Cm8sZlbkJ4GUTeqKtkvguTT4HDpCjPUTb/O3L/+qNqLrUUYTKxh 7HrGhBvnCKC4YUo/tGyG8yGvyTkMw5ndRyVb1L/qXVJsmXeB8iX4nDa5g5IHeqxrBXMB qiXBfH9ffiUO/R0tm9w+eYSg+FahZVrLDPyZgcWYMaX4ESwotHwT3Da7i3b/F3Unv0Hs elrw1Kgm/uupRV5QbSe8HnreggPTf8rMeLSd4ohEiWlufBGk2jlzxq6/IsYeYsRMabru 3Wheb9jlyR6UUm7NfM+t5uK46f4JXopu5Jth6nlZYYnsYYZXUIERjrPpjegIoZQ8ymEi 4NCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Kbrh1J6jb4kOgZCg/eEabXhEFnoc7+ZrgplPPRc9fRM=; b=tjP3hadTEmOUg8FTa93o9PKxpjzo9rIaVNyqS1jD4Nnmz5/CbEnSCIuIA5970wJ9qf RMMvJZzdDRzTyKfo5sJi+BMEg+RnRJPWa5En0J3/eYMH7YLXZhf8AK1VAggHBCNmWxs4 p4zGdjZVOdNFBaCZP0sXVXB746+nyq2kAFeCfu31SbRACL4CJaQ0N5Qpw9UjnXBaQZyG /AlDVJUuD1/Prb9z+66AscgRkjC2SqvnOF14i3vrXbNwOvsEL35z3HPcpuWX4FFMNIH4 NHY9TqVkXdYMEhzct7Djc1LgwLyJMRaGfW4BFE4f4Dh6/YVHwQ4wDirpZiNVTmttoFq8 vUhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=oE+GXtGl; 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=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b74si40318070pfb.281.2019.08.03.09.54.15; Sat, 03 Aug 2019 09:54:30 -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=@nvidia.com header.s=n1 header.b=oE+GXtGl; 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726966AbfHBSnl (ORCPT + 99 others); Fri, 2 Aug 2019 14:43:41 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:16223 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725866AbfHBSnk (ORCPT ); Fri, 2 Aug 2019 14:43:40 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 02 Aug 2019 11:43:39 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 02 Aug 2019 11:43:38 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 02 Aug 2019 11:43:38 -0700 Received: from [10.2.165.119] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 2 Aug 2019 18:43:36 +0000 Subject: Re: [PATCH v7 07/20] clk: tegra: clk-periph: Add save and restore support To: Dmitry Osipenko , , , , , , , , CC: , , , , , , , , , , , , , References: <1564532424-10449-1-git-send-email-skomatineni@nvidia.com> <1564532424-10449-8-git-send-email-skomatineni@nvidia.com> From: Sowjanya Komatineni Message-ID: <614e3fec-cfa2-9e49-6130-d6de253acf03@nvidia.com> Date: Fri, 2 Aug 2019 11:43:36 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-US DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1564771419; bh=Kbrh1J6jb4kOgZCg/eEabXhEFnoc7+ZrgplPPRc9fRM=; h=X-PGP-Universal:Subject:To:CC:References:From:Message-ID:Date: User-Agent:MIME-Version:In-Reply-To:X-Originating-IP: X-ClientProxiedBy:Content-Type:Content-Transfer-Encoding: Content-Language; b=oE+GXtGlYqP7gJPYHtFjGyLisqcTTy4TWY28VxBtQ0J/+up/ybowHqzDZNJHT15iZ K/fBFd7mCh7PaV7lLvMstQ1ngVqI+SRLC4cLDYYZMUPQ7dWaYyrGdzxO5B2q74YKti ZTmwl8UOnZU/wQLkjzw/Or4cn3+g9jhJU0n7jnZOyEgBCJW8fgc7137tJ+W9EjhbyU mY0RIMB7Tpcf8IKcSSo7fZsIAEYxf2QqoISAUulaeOAgKXdGFRuQVJv7DK2eilIO2n p/vKcDvNh1eEM4DnyapnpCVIyJWjqbZo8oBQPOVyreqMWLuyGh3eeRI2Hkq1UwNmUv rlK54RzMzDeSg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/2/19 5:32 AM, Dmitry Osipenko wrote: > 31.07.2019 3:20, Sowjanya Komatineni =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >> This patch implements save and restore context for peripheral fixed >> clock ops, peripheral gate clock ops, sdmmc mux clock ops, and >> peripheral clock ops. >> >> During system suspend, core power goes off and looses the settings >> of the Tegra CAR controller registers. >> >> So during suspend entry clock and reset state of peripherals is saved >> and on resume they are restored to have clocks back to same rate and >> state as before suspend. >> >> Acked-by: Thierry Reding >> Signed-off-by: Sowjanya Komatineni >> --- >> drivers/clk/tegra/clk-periph-fixed.c | 33 ++++++++++++++++++++++++++++= ++++ >> drivers/clk/tegra/clk-periph-gate.c | 34 ++++++++++++++++++++++++++++= +++++ >> drivers/clk/tegra/clk-periph.c | 37 ++++++++++++++++++++++++++++= ++++++++ >> drivers/clk/tegra/clk-sdmmc-mux.c | 28 +++++++++++++++++++++++++++ >> drivers/clk/tegra/clk.h | 6 ++++++ >> 5 files changed, 138 insertions(+) >> >> diff --git a/drivers/clk/tegra/clk-periph-fixed.c b/drivers/clk/tegra/cl= k-periph-fixed.c >> index c088e7a280df..21b24530fa00 100644 >> --- a/drivers/clk/tegra/clk-periph-fixed.c >> +++ b/drivers/clk/tegra/clk-periph-fixed.c >> @@ -60,11 +60,44 @@ tegra_clk_periph_fixed_recalc_rate(struct clk_hw *hw= , >> return (unsigned long)rate; >> } >> =20 >> +static int tegra_clk_periph_fixed_save_context(struct clk_hw *hw) >> +{ >> + struct tegra_clk_periph_fixed *fixed =3D to_tegra_clk_periph_fixed(hw)= ; >> + u32 mask =3D 1 << (fixed->num % 32); > This could be BIT(fixed->num % 32). > >> + fixed->enb_ctx =3D readl_relaxed(fixed->base + fixed->regs->enb_reg) & >> + mask; >> + fixed->rst_ctx =3D readl_relaxed(fixed->base + fixed->regs->rst_reg) & >> + mask; > The enb_ctx/rst_ctx are booleans, while you assigning an integer value > here. You're getting away here because bool is an 32bit unsigned int, > but you shouldn't rely on it and always explicitly convert to a bool. > >> + return 0; >> +} >> + >> +static void tegra_clk_periph_fixed_restore_context(struct clk_hw *hw) >> +{ >> + struct tegra_clk_periph_fixed *fixed =3D to_tegra_clk_periph_fixed(hw)= ; >> + u32 mask =3D 1 << (fixed->num % 32); >> + >> + if (fixed->enb_ctx) >> + writel_relaxed(mask, fixed->base + fixed->regs->enb_set_reg); >> + else >> + writel_relaxed(mask, fixed->base + fixed->regs->enb_clr_reg); >> + >> + udelay(2); > Will be better to read out and compare the hardware's state with the > restored one, then bail out if the state is unchanged. > > Shouldn't it be fence_udelay()? > >> + if (!fixed->rst_ctx) { >> + udelay(5); /* reset propogation delay */ > Why delaying is done before the writing to the reset register? During SC7 exit, peripheral reset state is set to POR state. So some=20 peripherals will already be in reset state and making sure of=20 propagation delay before releasing from reset. It should be rst_clr_reg. will fix in next rev > >> + writel_relaxed(mask, fixed->base + fixed->regs->rst_reg); > I'm not quite sure what's going on here, this looks wrong. > > 1. rst_reg points to RST_DEVICES_x > 2. Each bit of RST_DEVICES_x represents the reset-assertion state of > each individual device > 3. By writing to rst_reg, all (!) devices are deasserted, except the one > device which corresponds to the mask > 4. The reset is asserted for a single device, while !fixed->rst_ctx > means that it actually should be deasserted (?) > > Apparently you should use rst_set_reg / rst_clr_reg. Yes, It should be rst_clr_reg. will fix in next rev >> + } > What about the case where rst_ctx=3Dtrue? ON SC7 exit, state of RST_DEV will be POR state where most peripherals=20 will already be in reset state. Few of them which are not in reset state in POR values are those that=20 need to stay de-asserted across the boot states anyway. > >> +} >> @@ -517,6 +517,8 @@ struct tegra_clk_periph_gate { >> int clk_num; >> int *enable_refcnt; >> const struct tegra_clk_periph_regs *regs; >> + bool clk_state_ctx; >> + bool rst_state_ctx; >> }; >> =20 >> #define to_clk_periph_gate(_hw) \ >> @@ -543,6 +545,8 @@ struct tegra_clk_periph_fixed { >> unsigned int mul; >> unsigned int div; >> unsigned int num; >> + bool enb_ctx; >> + bool rst_ctx; >> }; > I'd expect these to be bool:1.