From patchwork Mon Jul 15 18:28:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 737 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 281BE3F08F for ; Mon, 15 Jul 2019 20:29:35 +0200 (CEST) Received: by mail-pl1-f200.google.com with SMTP id r7sf8715495plo.6 for ; Mon, 15 Jul 2019 11:29:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1563215374; cv=pass; d=google.com; s=arc-20160816; b=jB2kZO7ytI/3n03lItgAf+fB/HA4LS9XrkIY1L2zYBbpT13yARM6IZGHIAl0pu7C2b rLs9OUaIdXHcJ7r2xCFyOKf2Wc8LeC38ZMxeuyxFNQ14fThcNaQEYAKv0AdLwnNhOhIw HbXRjiFtnPkudieBroiRZXR+yh5QgSGAwFqZ7rKjz6TswIQN7ay9UxhRwLHsnvXtmqoh Mcfrcg2opRLTXGhge3r2MJYWrG1b6crn12pEPeobxUT6Gdx4eHfpWb6muL0Q1ionm79n QgxU2fh66vgse4m7lvB6ev4j+91LJEpCKH1U3aBKlYekRUxr+fgMc74sWbpY3aa87mwe rVCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=JYfBBIvfkJehV+uCiuXk2KTGHftb5jpb8ap228s7rG8=; b=cCN6UlHXd+Eensm86B0yUw4+yn3wZjfAuT4Ep+Vd2BmBcPLyAZlM27vJvPP+VTh7Wx 2R7SscGDss5zBCMg5vJrdH4ds8ZqzyRBGkomxxlv4zuXU0qWD/bplReVrpx5nGb77hNU 3lsU9ifX3FXgURSO/YI8sZzrmESELBZwp98BAzky5UuA/CBuYiNlj6BEr2HuNQ3T3eTR E362HtJSfVBF/y2ysOVz0euUgKEFXeO51VYjOt+hNFw+GF0AlcOueAF9W7ZP0dHjZ3WC fMMM5xNGsBdSXrH/GlcYC81DloFPNZWpFmp2WcjU/QkJT8OgCMfnxwSEYdxSpuErHEQU arDQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ab8ad8He; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=JYfBBIvfkJehV+uCiuXk2KTGHftb5jpb8ap228s7rG8=; b=pmq5JC9vArMK7Ku+pYqYcnXBZyY9PYwYqq88o5NsEjpt42V6TpTUAb2oL42+U2e6QC 4Wu5EfdVJ3YcoLF5Y5LrwfdFWKbBBD5NxunvVkd8636KnHq66IgnA6qJRECPOCBPKMSE Y2gMNAVmgRmqk39lPdLl548MiAdZX8JVrC5d0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=JYfBBIvfkJehV+uCiuXk2KTGHftb5jpb8ap228s7rG8=; b=g/dv4biDc8HNaD5kzpouAXCY4zZSMAOw3EirnGbNrTb3gLvJP1xE8MRubry0WcJEO1 X1L70aII0yeEd6xT9weiewE3MafGqnD/RgWgCzL7bdN1W30LHvYTtpNz+jpLVyvmlW2K svB39r4pblusoEPlDxUYcuCfQP/j03YuZW6JycDdXXD3lxSRjLAo/woy/zV1oUaDr4TT 9uJ/RAXhzO1rpoNldQ77qpc1rUmv0DNZ7qy6sWNQYSJt+4IJzRuNSim0cAPvZLG4unNQ 4DMu5hS2dJyRFs4EThhHcOu+tblAkCv7xBkXRuiXDwgOM5Cd4fvi6AXefmRBqHwBmuAt qbyQ== X-Gm-Message-State: APjAAAWWeqcmc600QvKUMJQiE6xleQmVh9A0DeRntd0rvi+BlgypzIGp mXyM34v1Rix+yn0wVb6mEaMhld56 X-Google-Smtp-Source: APXvYqzH4QAzw4+9Afqa0j1CjL3U56aBCWzXmX+MA5AvZrElPdsLDoNe+25dcYmnrFylunFBuZG+Qg== X-Received: by 2002:a63:fb4b:: with SMTP id w11mr28282413pgj.415.1563215373875; Mon, 15 Jul 2019 11:29:33 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:2acb:: with SMTP id j69ls4714262plb.9.gmail; Mon, 15 Jul 2019 11:29:33 -0700 (PDT) X-Received: by 2002:a17:90b:f0e:: with SMTP id br14mr30720129pjb.117.1563215373523; Mon, 15 Jul 2019 11:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563215373; cv=none; d=google.com; s=arc-20160816; b=vOP1sVFuaB5VCXe8s8NyHFkfVdUp6tvP9zJY0G2MxAO6WTHsX2yHSJT41l+yscDPyA ijjYtdqbQWFhPGZgA7yrEWXla0SADLZZbxTjPSeh3pMV4BUlWgotMPBh5qEKPB1/ZseC Dd+2LywzIY6Z8e34JKMFkh6X2HvzS/0mbDw6kYy5Ewo85vy2TgZGN8Nk0gstlr69K3Qz Rf3lZQHXM8VuEibKismsHNVLDOppnVw/m9mATqgC1IdztWANKTyW1QfTdwJBpGQxATIL +xZ2xAc16uyrM0g+FnkLOedWVeugHUzCz2/JYzzsRItCRr0eWSbADQILUm+oIHwEb4bO CYvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Cdy1dxv9t+oHKqeWpvE9O/P4Jm0ldwmB6m0flnPmlmM=; b=Chfh+FtWUjh1UWeBCIHmqaHdaKZkT25Cg7YlpyV5xZRuoLZpcwpA9oPpNOcW1fdngL jgMfp7MG7w8FYBJQOFis+HyGr3Y+oKRvGyGGDKcA9oopijAf6FnyH3MPtd9gXADNpcdk o35cyYIRxyLy5PAuPOPDNbezDRKryZ7JCFtcQblMiDabUQ3wQ9I7fBahwRsW3nMJfXVq SOC7le1c8WFyfnycX641Jh5EqjhlEA4YnOksEqFxkp+tmAyx0PBhJPvDcA2ZsEXGbaZt 7vuvxCxz8wDxxk7zgQRsIbqjaEiQygJaYjqDP3jC2fWiaTtBx6m4CnLIDaCQxk28yGbE 8Btg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ab8ad8He; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m33sor21897004pjb.4.2019.07.15.11.29.33 for (Google Transport Security); Mon, 15 Jul 2019 11:29:33 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:90a:b387:: with SMTP id e7mr31826321pjr.113.1563215373177; Mon, 15 Jul 2019 11:29:33 -0700 (PDT) Received: from localhost.localdomain ([49.206.201.107]) by smtp.gmail.com with ESMTPSA id y133sm20250075pfb.28.2019.07.15.11.29.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jul 2019 11:29:32 -0700 (PDT) From: Jagan Teki To: Simon Glass , Philipp Tomsich , Kever Yang , YouMin Chen , u-boot@lists.denx.de Cc: Manivannan Sadhasivam , gajjar04akash@gmail.com, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v3 07/18] ram: rk3399: Add pctl start support Date: Mon, 15 Jul 2019 23:58:45 +0530 Message-Id: <20190715182856.21688-8-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190715182856.21688-1-jagan@amarulasolutions.com> References: <20190715182856.21688-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ab8ad8He; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add support for pctl start for both channel 0, 1 control and phy registers. This would also handle pwrup_srefresh_exit init based on the channel number. Signed-off-by: Jagan Teki Signed-off-by: YouMin Chen Reviewed-by: Kever Yang --- drivers/ram/rockchip/sdram_rk3399.c | 75 +++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index 6e944cafd9..084c949728 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -49,10 +49,11 @@ struct chan_info { struct dram_info { #if defined(CONFIG_TPL_BUILD) || \ (!defined(CONFIG_TPL) && defined(CONFIG_SPL_BUILD)) - u32 pwrup_srefresh_exit; + u32 pwrup_srefresh_exit[2]; struct chan_info chan[2]; struct clk ddr_clk; struct rk3399_cru *cru; + struct rk3399_grf_regs *grf; struct rk3399_pmucru *pmucru; struct rk3399_pmusgrf_regs *pmusgrf; struct rk3399_ddr_cic_regs *cic; @@ -73,6 +74,11 @@ struct rockchip_dmc_plat { struct regmap *map; }; +static void *get_ddrc0_con(struct dram_info *dram, u8 channel) +{ + return (channel == 0) ? &dram->grf->ddrc0_con0 : &dram->grf->ddrc0_con1; +} + static void copy_to_reg(u32 *dest, const u32 *src, u32 n) { int i; @@ -328,6 +334,48 @@ static void set_ds_odt(const struct chan_info *chan, clrsetbits_le32(&denali_phy[930], 0x1 << 17, reg_value); } +static void pctl_start(struct dram_info *dram, u8 channel) +{ + const struct chan_info *chan = &dram->chan[channel]; + u32 *denali_ctl = chan->pctl->denali_ctl; + u32 *denali_phy = chan->publ->denali_phy; + u32 *ddrc0_con = get_ddrc0_con(dram, channel); + u32 count = 0; + u32 byte, tmp; + + writel(0x01000000, &ddrc0_con); + + clrsetbits_le32(&denali_phy[957], 0x3 << 24, 0x2 << 24); + + while (!(readl(&denali_ctl[203]) & (1 << 3))) { + if (count > 1000) { + printf("%s: Failed to init pctl for channel %d\n", + __func__, channel); + while (1) + ; + } + + udelay(1); + count++; + } + + writel(0x01000100, &ddrc0_con); + + for (byte = 0; byte < 4; byte++) { + tmp = 0x820; + writel((tmp << 16) | tmp, &denali_phy[53 + (128 * byte)]); + writel((tmp << 16) | tmp, &denali_phy[54 + (128 * byte)]); + writel((tmp << 16) | tmp, &denali_phy[55 + (128 * byte)]); + writel((tmp << 16) | tmp, &denali_phy[56 + (128 * byte)]); + writel((tmp << 16) | tmp, &denali_phy[57 + (128 * byte)]); + + clrsetbits_le32(&denali_phy[58 + (128 * byte)], 0xffff, tmp); + } + + clrsetbits_le32(&denali_ctl[68], PWRUP_SREFRESH_EXIT, + dram->pwrup_srefresh_exit[channel]); +} + static int phy_io_config(const struct chan_info *chan, const struct rk3399_sdram_params *params) { @@ -498,7 +546,6 @@ static int pctl_cfg(struct dram_info *dram, const struct chan_info *chan, const u32 *params_phy = params->phy_regs.denali_phy; u32 tmp, tmp1, tmp2; int ret; - const ulong timeout_ms = 200; /* * work around controller bug: @@ -518,8 +565,8 @@ static int pctl_cfg(struct dram_info *dram, const struct chan_info *chan, writel(params->phy_regs.denali_phy[911], &denali_phy[911]); writel(params->phy_regs.denali_phy[912], &denali_phy[912]); - dram->pwrup_srefresh_exit = readl(&denali_ctl[68]) & - PWRUP_SREFRESH_EXIT; + dram->pwrup_srefresh_exit[channel] = readl(&denali_ctl[68]) & + PWRUP_SREFRESH_EXIT; clrbits_le32(&denali_ctl[68], PWRUP_SREFRESH_EXIT); /* PHY_DLL_RST_EN */ @@ -580,22 +627,6 @@ static int pctl_cfg(struct dram_info *dram, const struct chan_info *chan, if (ret) return ret; - /* PHY_DLL_RST_EN */ - clrsetbits_le32(&denali_phy[957], 0x3 << 24, 0x2 << 24); - - /* Waiting for PHY and DRAM init complete */ - tmp = get_timer(0); - do { - if (get_timer(tmp) > timeout_ms) { - pr_err("DRAM (%s): phy failed to lock within %ld ms\n", - __func__, timeout_ms); - return -ETIME; - } - } while (!(readl(&denali_ctl[203]) & (1 << 3))); - debug("DRAM (%s): phy locked after %ld ms\n", __func__, get_timer(tmp)); - - clrsetbits_le32(&denali_ctl[68], PWRUP_SREFRESH_EXIT, - dram->pwrup_srefresh_exit); return 0; } @@ -1186,6 +1217,9 @@ static int sdram_init(struct dram_info *dram, return ret; } + /* start to trigger initialization */ + pctl_start(dram, channel); + /* LPDDR2/LPDDR3 need to wait DAI complete, max 10us */ if (dramtype == LPDDR3) udelay(10); @@ -1262,6 +1296,7 @@ static int rk3399_dmc_init(struct udevice *dev) #endif priv->cic = syscon_get_first_range(ROCKCHIP_SYSCON_CIC); + priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); priv->pmugrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUGRF); priv->pmusgrf = syscon_get_first_range(ROCKCHIP_SYSCON_PMUSGRF); priv->pmucru = rockchip_get_pmucru();