From patchwork Mon Jul 15 18:28:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 744 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 76F9C3F08F for ; Mon, 15 Jul 2019 20:29:59 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id r142sf10719028pfc.2 for ; Mon, 15 Jul 2019 11:29:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1563215398; cv=pass; d=google.com; s=arc-20160816; b=HwGD1EpEtB7SCPb67Pl/mtIy4TkK+ylEEMdAofKOtabxeiBwTcqYmt+3Y3jMeRNDYn mIN/qWoGNlY2qR8ZGMSVFgciczaE+SZClN1/OS/isHKNQeqZ30Djzl5bWUaQ2nHTi1g0 zOk5eL/gLnXRCVW9RZ9PmdwqKv3YW6/M6dL66iWvDjzZpnpE6LsthjrACOoRDsiIRqWB WUdW7LmcAqgZo81X1k9n0K3DsZrLr5Cu3lguVFCFNCxZycGsBxiVT1Iu7qiW80Y9uO6N hCJj0wywqk51ma34r7mi38eCzgqS/9Cx5axcBFt9UEyoikiE7d3KroltOXMASfirVin+ 8IcA== 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=DTiNFeObNVa3h/AjDpQ2EM+trFnw+zMLe+GK0pGhEsQ=; b=R1pEDNSNy0tk5VV/ldzCESLy+/eMwF6uUMJW8/1hsOXCVegcLGMmz/Xzj+CUaLFKVg yfcEBSiXcDIawzoWrqmaQm1yq2GHf2Q+a3AcRdljOQ6hGdKL5Nz85m/TzyKpMdbrPmkB 8MJtcYcvstkoT1QYs6GdxTMqRBUtwJxHFU+Tqzt4zes8AlqjRcpr8rgEhLP0ElKayyR3 2gRAdpkrx1+CstzzlaFeWXqae1EHiSevyfn0PjYAuTnZxx1xDihVQ0+c2IDmFb9pwXMJ /thPUfqpFs6lin88L9IRFEN6UxRYU4LkVkrAnpKgOGPZpZnSaRkxB8KryBrU9eDxNlvG qDJg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Coa1qETY; 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=DTiNFeObNVa3h/AjDpQ2EM+trFnw+zMLe+GK0pGhEsQ=; b=hDBQzjH/oAqngKZHjYxu90HyNlGEbDEDl4i47bnHjAEhhiLeYV+5W5Jjd/IaMBe6qE Mzb4GDkO2RWhzCj9MRrBJNYaeQizhK5uoS7oYPJLlchbOXTcfQNyJfVmEe3BBcli/6Ji iVumzwvPJ3VKOYp9Sdprj0ahoH2y2Cu7gkE00= 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=DTiNFeObNVa3h/AjDpQ2EM+trFnw+zMLe+GK0pGhEsQ=; b=RXZylyZMmJ2EPQp+LxCfw4K1ve+CuvU4A084Ol/xUZE7yx5mG84kL+O+yPS1/28FvI KpgLGlNjpC2LyCJtngSPTnd6z8Dc3ldQculBymBEx/fy991rkj8r50b2MMpvpbjGZcY+ uK23eP7ONLJR/HIdQMjSrtFTj4dNRx2zC03jMgNmBLyBRhCTX03NMqw8gy2Y8lCosj5y uNKmFaztsuhgiU3e3kDofBRSEDM7Q9uwuGa6TLkXfENUfNPrFxy7zp0UtwPrkXUVBOzL lZ+cx1apdXLjDChRK+LuEBBWBZPzPt3+srDlpIqkHeEX7VN/NkDP0BF+vJilTEUGiUJa SxCw== X-Gm-Message-State: APjAAAUtS4OCDdR1IBx8kOT0BJF1YV19SeVT3irNzN9Sn+pyE3T5HByu wqPPn4bqP0sK3Bz3/4X8fW6ug2GK X-Google-Smtp-Source: APXvYqwO2Qi+qyZoNh51y6cieMsgmPeJNHgtwrdj+ucvZQhpQUgx8fTHElmXqCL5wjtTo9KycDy4UQ== X-Received: by 2002:a63:788a:: with SMTP id t132mr28768999pgc.332.1563215398240; Mon, 15 Jul 2019 11:29:58 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:b08e:: with SMTP id p14ls4706703plr.16.gmail; Mon, 15 Jul 2019 11:29:58 -0700 (PDT) X-Received: by 2002:a17:90a:3651:: with SMTP id s75mr30157605pjb.13.1563215397859; Mon, 15 Jul 2019 11:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563215397; cv=none; d=google.com; s=arc-20160816; b=tJShwHetk5337ItzZFORPM9yYklDSK1pyoVVt/kkEm57HP/2UE+8CTEqZdvpw9Ct2X 866xFebYQXjG0vCk5nr9jqXoZ0X4FP08N2hYOJNelmMY9SsqaDqp9iI9HWwbEVA6RSjf 7TVRCSKRKn9Fyc9AU8Cmmv2t4JCJnAx8A3qezd7QXU6UBLs/4/1iv/sFzvnst+CVq+OT BjFn9gEVxcMtRMDNxVhkHy8ODXqK+ICVFmlqP5bEjNhk9kAbjyT1SD/8IzyAjJxb9PcX 2+Mbq4A6dxcKmsGYWW99NBqJ/HoXpO3dq+6OKefkDSD63W3PF/fqDijCdh2BiRlMXle7 12VA== 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=AsLLPwLnBovdXkNi9P5ImLX7S8wEFQBRTIIMJmHhUWg=; b=EHJGMUI76f2EgU3diJA6saAA5cufbOHI/C0YNbjPRxk1wRA9Yk0522nAmVDAHdLhg2 yq5xK7uYzY+jNCAsvwqrvBMffy/TKW8tRI1VwfoXAQq/l4XSslHNbGQMyltKLC3sJ3n9 JWHyYq29kSGWHMFJggg1U1mk0CRsu7Kzrr5XGDxZsVauqZ6gYTuZ80zPtu0qVCrtj3yd hHJLnyMTfAD07KmxVM84bl7AL79CbqiiD406VOjj6Y6xYzg0Ty+FT074yeJF4HGYv8DO v4pX4c9lY5ydL1Y+SYpX2qZSSB2yjr6QvgA6ERvFzQiJri9AxfZnI4MaNWTNCiaCEc6p bgnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Coa1qETY; 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 a25sor6833762pfi.29.2019.07.15.11.29.57 for (Google Transport Security); Mon, 15 Jul 2019 11:29:57 -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:a63:4845:: with SMTP id x5mr27631710pgk.155.1563215397471; Mon, 15 Jul 2019 11:29:57 -0700 (PDT) Received: from localhost.localdomain ([49.206.201.107]) by smtp.gmail.com with ESMTPSA id y133sm20250075pfb.28.2019.07.15.11.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jul 2019 11:29:57 -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 14/18] ram: rk3399: Compute stride for 2 channels Date: Mon, 15 Jul 2019 23:58:52 +0530 Message-Id: <20190715182856.21688-15-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=Coa1qETY; 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: , stride value from sdram timings can be computed dynamically based on the determined capacity for the given channel. Right now these stride values are taken as part of sdram timings via dtsi, but it possible to use same timings dtsi for given frequency even though the configured board sdram do support single channel with different size by dynamically detect the stride value. Example, NanoPi NEO4 do have DDR3-1866, but with single channel and 1GB size with dynamic stride detection it is possible to use existing rk3399-sdram-ddr3-1866.dtsi whose stride, number of channels and capacity it support is d efferent. So, add initial support to calculate the stride value for 2 channels sdram, which is available by default on existing boards. Signed-off-by: Jagan Teki Signed-off-by: YouMin Chen Reviewed-by: Kever Yang --- drivers/ram/rockchip/sdram_rk3399.c | 71 ++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index 084c949728..c626ef602c 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -1183,8 +1183,75 @@ static int switch_to_phy_index1(struct dram_info *dram, return 0; } +static unsigned char calculate_stride(struct rk3399_sdram_params *params) +{ + unsigned int stride = params->base.stride; + unsigned int channel, chinfo = 0; + unsigned int ch_cap[2] = {0, 0}; + u64 cap; + + for (channel = 0; channel < 2; channel++) { + unsigned int cs0_cap = 0; + unsigned int cs1_cap = 0; + struct sdram_cap_info *cap_info = ¶ms->ch[channel].cap_info; + + if (cap_info->col == 0) + continue; + + cs0_cap = (1 << (cap_info->cs0_row + cap_info->col + + cap_info->bk + cap_info->bw - 20)); + if (cap_info->rank > 1) + cs1_cap = cs0_cap >> (cap_info->cs0_row + - cap_info->cs1_row); + if (cap_info->row_3_4) { + cs0_cap = cs0_cap * 3 / 4; + cs1_cap = cs1_cap * 3 / 4; + } + ch_cap[channel] = cs0_cap + cs1_cap; + chinfo |= 1 << channel; + } + + /* stride calculation for 2 channels, default gstride type is 256B */ + if (ch_cap[0] == ch_cap[1]) { + cap = ch_cap[0] + ch_cap[1]; + switch (cap) { + /* 512MB */ + case 512: + stride = 0; + break; + /* 1GB */ + case 1024: + stride = 0x5; + break; + /* + * 768MB + 768MB same as total 2GB memory + * useful space: 0-768MB 1GB-1792MB + */ + case 1536: + /* 2GB */ + case 2048: + stride = 0x9; + break; + /* 1536MB + 1536MB */ + case 3072: + stride = 0x11; + break; + /* 4GB */ + case 4096: + stride = 0xD; + break; + default: + printf("%s: Unable to calculate stride for ", __func__); + print_size((cap * (1 << 20)), " capacity\n"); + break; + } + } + + return stride; +} + static int sdram_init(struct dram_info *dram, - const struct rk3399_sdram_params *params) + struct rk3399_sdram_params *params) { unsigned char dramtype = params->base.dramtype; unsigned int ddr_freq = params->base.ddr_freq; @@ -1232,6 +1299,8 @@ static int sdram_init(struct dram_info *dram, set_ddrconfig(chan, params, channel, params->ch[channel].cap_info.ddrconfig); } + + params->base.stride = calculate_stride(params); dram_all_config(dram, params); switch_to_phy_index1(dram, params);