From patchwork Tue Jun 11 14:50:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 501 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 AB8AB3F08F for ; Tue, 11 Jun 2019 16:55:12 +0200 (CEST) Received: by mail-pf1-f197.google.com with SMTP id y5sf9745833pfb.20 for ; Tue, 11 Jun 2019 07:55:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1560264911; cv=pass; d=google.com; s=arc-20160816; b=hhBwLuNhcBZEDy7K4ptaoSqpH9Ln71ZMC7ZAeBPJ+DXlAfBPIjgOKpl/SkWvjLKmq5 ABS+YfG309bfrTc9pwysz9pZyz4EalNUFOn8RR1lvguKCMMq3fkawwCZyC3QSYN485jM Z3bHIXHq8nl3O+JEuCxN3GMiq4L/z1Ur55H6VFEzog1CBKBkjeQ1lEct2IQJQv75jGzb XWLR9Crf1mHfjLC8apOBd4K8hHjlDamNBon+dgqLYEQ4ly9pim0fYfq8341yBU1nkXmB k6vXqTOwDL5VkNISl6S0ba2zivc7fEoc0pwn2SJBrQ03xIC/Tf9tSz7oaX8GjciVm4ut yjUw== 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=omod/d1hS1qTSBGjunXepUw0t+uAkVhXn4MypilFja4=; b=vKqnNxlylTTwfOZie1BzdpELXUpR1X02macDT9hNUzLG37C26fC2JI38p/k8E5Uf7i yIHV1/qNaO4f2rGAgG+KexPmnNkdwzaYKOIuDSRM49HtkOozYw1RawhIUQcNY82zVsPR QYSKtgOShbTRO50nNhqaExhlxuluwkIxfY4qIQiRaRmbxytQcBWu+CkFZZs12LjSVKzK w1tXCK7IiEvU5gKP7aoDw1YcCj9oDXmjH3sF65JL8YKtkcG2RQhFMq1SQEgJANkxhkfJ jsb91z0/wBb6cINfG8+40lgLPYW+8n3KHd88AXFnY85x6riNJ1WZSWrgY/6hmBq+BGsZ T3/Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=j5VRfK3i; 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=omod/d1hS1qTSBGjunXepUw0t+uAkVhXn4MypilFja4=; b=LVuXT8gy/hgaIXzO+Rg6dxjUJrEchjcnKaGHGbmjd0PswvIUDSS1euzrsg47wG5ImM GpVl2QMcyK4WBsssjMkALiarviseAdZZeh6gASDko7lnaTZr0nAlRqL2Qgord/eKXAhC dL7FlMevn5Ht/w1X9MuXWQ+zSKxALS0mG8WNg= 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=omod/d1hS1qTSBGjunXepUw0t+uAkVhXn4MypilFja4=; b=P9wqO+D3Czdf+S+UDuI54bpPXeqWeYkcvxZPIl+i0URrjpUqvAKpNZ1AAaNdO769Ok X4Wm5B5v1kFlUyyVrurXMrG80i+NaIT/KUOOt5faQsesz/8bwEquY1H9/ASkQq/XwPe7 L2fJqZGwjPvw6+M8Wy7S12uqFL40xq1/8VFmj1VXumLmlGSm7dTpJTrdTkVhQ+/+GFLY fOdb4RRJSQ8i0a0d1UeTbuynYaGsUfElWT+vISAsa0QYKXc/t38E0qeYrp+HMd4CVUeN LkraN23PZOljH7QRWDr2ZoshInYxtfHiZMaW2WD/eH8jm8wOrngwg3TnKPZ/9JR10gMA 5aEg== X-Gm-Message-State: APjAAAXCFqbKYsIA0iccrl1LOXQhT+22PunlGFlLG/7TEFoiD9svE4sg VciLoC0Az4PYhKWnCqoqQGVGurIx X-Google-Smtp-Source: APXvYqx2+QG1ZmUJeDh5DZQcdALEeCNS9NTH9TvXCKNDwR11Xa11xXjE503L2jeehrn185zDU0cpMA== X-Received: by 2002:a17:902:860c:: with SMTP id f12mr76701256plo.127.1560264911445; Tue, 11 Jun 2019 07:55:11 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a65:5041:: with SMTP id k1ls4510009pgo.16.gmail; Tue, 11 Jun 2019 07:55:11 -0700 (PDT) X-Received: by 2002:a65:64d5:: with SMTP id t21mr21128980pgv.310.1560264910948; Tue, 11 Jun 2019 07:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560264910; cv=none; d=google.com; s=arc-20160816; b=dGevIGJffpV+iPSXqyI3IsmtNlMjYUCB5yXNBdVtBKLu/jrwRW3egq4FLlh/nEYUtV xBq/bygX0NGvjr5gu9/Vj8FzFKBlaOa0SJ9OC6sIV+XvpP2z6BzbSOfDjUvNGy5NnIMj KqrcrPICTSxGzOblnZ5zt+04gMIiopoqu8OpQIftBov0N1eZ0rKrIJTnpsjSx+zZ2pW8 9ap2IbHo8H3D/3QLIJuDQODpkoJxjaX88qEoDoGHL0z0qqILsR8nmnboj1d6wQEJZg1S sGIvAF316xoPNymnS+8Kx3nXtEW5NHd+7O/7y6AmG6NSQCdsDOBOhYfG1llNeqdxorra RtOQ== 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=YWFY8OB8qH64wLMK+dtpSQ0QVPAol0EQVIgUSITRXPQ=; b=WQzdIWkn7R2OrY5dQVnefDy+OooowmzldhBoDqcsYYsksSI4gAUOENhm7KsdJeuoV/ BcnZKLlJClGViWXunX0sh4RWIEGfUYxE5Mu0he4dKnbWcDYXHHxMT2nT7yYpu4jRQFXV J4VcWvhoCMctbWdsbq9ZnA0jVrY9Sfyq6b7ooy+tLTEsanv3nertrBThFPWOD3K5V52v SC3wbvJ+7HkDNXxx0CHN/wv/b/xUbU67WlGSVETyaqQKe9clpWrdUkdlm0q/6xzJJSZR kWC1MsKw5vwxDG7v4biO55t29lSaHW+58NwRLOEG/JqiRBPx9YZfDcJyRFPokMuL3tKL ioeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=j5VRfK3i; 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 m129sor13245430pfb.2.2019.06.11.07.55.10 for (Google Transport Security); Tue, 11 Jun 2019 07:55:10 -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:aa7:8219:: with SMTP id k25mr83108651pfi.38.1560264910594; Tue, 11 Jun 2019 07:55:10 -0700 (PDT) Received: from localhost.localdomain ([115.97.180.18]) by smtp.gmail.com with ESMTPSA id e9sm16206208pfn.154.2019.06.11.07.55.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 07:55:10 -0700 (PDT) From: Jagan Teki To: Simon Glass , Philipp Tomsich , Kever Yang , YouMin Chen , u-boot@lists.denx.de Cc: gajjar04akash@gmail.com, linux-rockchip@lists.infradead.org, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH 50/92] ram: rk3399: Add rank detection support Date: Tue, 11 Jun 2019 20:20:53 +0530 Message-Id: <20190611145135.21399-51-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190611145135.21399-1-jagan@amarulasolutions.com> References: <20190611145135.21399-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=j5VRfK3i; 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: , Right now the rk3399 sdram driver assume that the board has configured with 2 channels, so any possibility to enable single channel on the same driver will encounter channel #1 data training failure. Log: U-Boot TPL board init sdram_init: data training failed rk3399_dmc_init DRAM init failed -5 So, add an algorithm that can capable to compute the active or configured rank with associated channel like a) do rank loop to compute the active rank, with associated channel numbers b) then, succeed the data training only for configured channel c) preserve the rank for given channel d) do channel loop for setting the active channel e) if given rank is zero or inactive on the specific channel, clear the timings for the associated channel f) finally, return error if number of channels is zero Tested in NanoPI-NEO4 since it support single channel sdram configuration. Signed-off-by: Jagan Teki Signed-off-by: YouMin Chen --- drivers/ram/rockchip/sdram_rk3399.c | 112 +++++++++++++++++++++------- 1 file changed, 87 insertions(+), 25 deletions(-) diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index 033b2730a6..b658d7d1ab 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -1257,13 +1257,52 @@ static unsigned char calculate_stride(struct rk3399_sdram_params *sdram_params) return stride; } +static void clear_channel_params(struct rk3399_sdram_params *params, u8 channel) +{ + params->ch[channel].cap_info.rank = 0; + params->ch[channel].cap_info.col = 0; + params->ch[channel].cap_info.bk = 0; + params->ch[channel].cap_info.bw = 32; + params->ch[channel].cap_info.dbw = 32; + params->ch[channel].cap_info.row_3_4 = 0; + params->ch[channel].cap_info.cs0_row = 0; + params->ch[channel].cap_info.cs1_row = 0; + params->ch[channel].cap_info.ddrconfig = 0; +} + +static int pctl_init(struct dram_info *dram, struct rk3399_sdram_params *params) +{ + int channel; + int ret; + + for (channel = 0; channel < 2; channel++) { + const struct chan_info *chan = &dram->chan[channel]; + struct rk3399_cru *cru = dram->cru; + struct rk3399_ddr_publ_regs *publ = chan->publ; + + phy_pctrl_reset(cru, channel); + phy_dll_bypass_set(publ, params->base.ddr_freq); + + ret = pctl_cfg(dram, chan, channel, params); + if (ret < 0) { + printf("%s: pctl config failed\n", __func__); + return ret; + } + + /* start to trigger initialization */ + pctl_start(dram, params, channel); + } + + return 0; +} + static int sdram_init(struct dram_info *dram, struct rk3399_sdram_params *sdram_params) { unsigned char dramtype = sdram_params->base.dramtype; unsigned int ddr_freq = sdram_params->base.ddr_freq; - struct rk3399_cru *cru = dram->cru; - int channel; + u32 training_flag = PI_READ_GATE_TRAINING; + int channel, ch, rank; int ret; debug("Starting SDRAM initialization...\n"); @@ -1275,37 +1314,60 @@ static int sdram_init(struct dram_info *dram, return -E2BIG; } - for (channel = 0; channel < 2; channel++) { - const struct chan_info *chan = &dram->chan[channel]; - struct rk3399_ddr_publ_regs *publ = chan->publ; + for (ch = 0; ch < 2; ch++) { + sdram_params->ch[ch].cap_info.rank = 2; + for (rank = 2; rank != 0; rank--) { + ret = pctl_init(dram, sdram_params); + if (ret < 0) { + printf("%s: pctl init failed\n", __func__); + return ret; + } - phy_pctrl_reset(cru, channel); - phy_dll_bypass_set(publ, ddr_freq); + /* LPDDR2/LPDDR3 need to wait DAI complete, max 10us */ + if (dramtype == LPDDR3) + udelay(10); - if (channel >= sdram_params->base.num_channels) - continue; + sdram_params->ch[ch].cap_info.rank = rank; - ret = pctl_cfg(dram, chan, channel, sdram_params); - if (ret < 0) { - printf("%s: pctl config failed\n", __func__); - return ret; - } + /* + * LPDDR3 CA training msut be trigger before + * other training. + * DDR3 is not have CA training. + */ + if (sdram_params->base.dramtype == LPDDR3) + training_flag |= PI_CA_TRAINING; - /* start to trigger initialization */ - pctl_start(dram, sdram_params, channel); + if (!(data_training(&dram->chan[ch], ch, + sdram_params, training_flag))) + break; + } + /* Computed rank with associated channel number */ + sdram_params->ch[ch].cap_info.rank = rank; + } - /* LPDDR2/LPDDR3 need to wait DAI complete, max 10us */ - if (dramtype == LPDDR3) - udelay(10); + sdram_params->base.num_channels = 0; + for (channel = 0; channel < 2; channel++) { + const struct chan_info *chan = &dram->chan[channel]; + struct sdram_cap_info *cap_info = + &sdram_params->ch[channel].cap_info; - if (data_training(chan, channel, - sdram_params, PI_FULL_TRAINING)) { - printf("%s: data training failed\n", __func__); - return -EIO; + if (cap_info->rank == 0) { + clear_channel_params(sdram_params, channel); + continue; + } else { + sdram_params->base.num_channels++; } - set_ddrconfig(chan, sdram_params, channel, - sdram_params->ch[channel].cap_info.ddrconfig); + debug("Channel "); + debug(channel ? "1: " : "0: "); + + set_ddrconfig(chan, sdram_params, channel, cap_info->ddrconfig); + } + + if (sdram_params->base.num_channels == 0) { + printf("%s: ", __func__); + printf(" - %dMHz failed!\n", sdram_params->base.ddr_freq); + return -EINVAL; } sdram_params->base.stride = calculate_stride(sdram_params);