From patchwork Mon Jul 15 18:28:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 746 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 8D9E93F08F for ; Mon, 15 Jul 2019 20:30:06 +0200 (CEST) Received: by mail-pf1-f200.google.com with SMTP id x10sf10716470pfa.23 for ; Mon, 15 Jul 2019 11:30:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1563215405; cv=pass; d=google.com; s=arc-20160816; b=hMLC0+tu+ow3mdwG/1iUeIQc7ywSfEn+AQZ9VkbyagfvMAymwJYGJGK91dUs4qtyTE TWQx1JtMZdfe4rI6YapvoDeeHOTqrqUY60wFPRXYpiGyWGsX2JcO1eQEH4ias2JlXwhT 8xSov6SIRj0QNpppTKg2ycQtwLHxynBF9jshqjEkF1fB21X4/Hb2DGdQgJa+WoRsb2Iz xoxk49Ry5WjezzmXjGM5DJ91WiPYwji5KO4TROtvOvAleRsezp1HFWXt6KFhfMXwxlDI MTGWf5QCQxPS83CUAi37HtF9KH11h2bFX8OFrVfc8QipvreptaTODWUQMKZrH0D6Vigf MIgA== 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=XXRhz+/GoULxurKs7hdXg/O9jkEvABZo88A8tKBtG2M=; b=Ml5ezLQGifLWs5b3Xzt5bkRAOoHjXlDT1ZXNxVLaJj71f2HHTFkExuEcKK8vAKUl6T NE8xMeT6ci6DK/oEZNHiKcs6/Kjh0goayK5Ym6EZw7SGIWPH89C6Onx0M3DRbcVYjNmm yklZMl3TCQRJe1m21BbT46ucpGL5QadqY2064BhlAhZEIujaCOy7D0g62fQ4aJGTbNc3 NK51kbhSm1d2OU3bY14AWLKR3ulvvSzy3O9QeNqUZHbUNiNdvoUcrPRLRMbInA8CdfmI 1JkLI/0NWZyQBKMM7+rRA0n6ObodZgdntij42tBD7ToH57ns10VPyY71P+V6HZjaFdLU XQug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=F9mZj79u; 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=XXRhz+/GoULxurKs7hdXg/O9jkEvABZo88A8tKBtG2M=; b=I1lGNt1mv4jBRGsfivcXk5RYun/eWGtATRJMVW1NoQXrzjPwkUzy2HNNBc2k8m4Ujb ACXnajnSLWAEpIpdpvF3jBJJ7980J51uz8sVigaU3mLIP1UvTQMAA3cCMzr+eqn7YhF5 WyLBd6RbL4VlXFSaOoDbExIluFuoijZ7sWiI4= 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=XXRhz+/GoULxurKs7hdXg/O9jkEvABZo88A8tKBtG2M=; b=qRVeLXBGHPy7YR6aYBHUTvp0Aymlj9OMZa52VUH5Pwz4v8Bf+j67vXDGRiOGJrO66W c4n9rVY9otdFb3be0QLmMUbauDRN+feMRLDGSu/VcsEQgCysk5HFv13BeGi2sG53yaTH +fn9XfexI0c27yfFNYJghK8nfOUB2/kQCG72l0YbkR8EWU2HC33UpAjYuDzDEUo0fp6A g/ict0TEmRy2fwSxNezPiZuPDV0VOAHF62ChuTLmCW2jsRpDh4FlHQU2P1Z3jwDDwRxO d/Ds+3p3Z0igyXTY9yCxBFo85ALir9xfJ+U8sLff+pWkMCldtsTspEQVSmiOJ1hg/WvN lPrQ== X-Gm-Message-State: APjAAAVuI5xvcA8nPw71qFAcPlAcewsrxgRLxffoePx1WIELbFOT6MKh 3gjSNNi7rSCgVW+Wndsghk/8w1xn X-Google-Smtp-Source: APXvYqzjagRQO93k50b2lxk4m5vzsBKOmrj2Cw8Ji/4IMMVfH00/6M7j77ud0vxFP//fSOjvi3w9Ew== X-Received: by 2002:a63:10a:: with SMTP id 10mr28792402pgb.281.1563215405246; Mon, 15 Jul 2019 11:30:05 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90b:905:: with SMTP id bo5ls6201362pjb.0.canary-gmail; Mon, 15 Jul 2019 11:30:05 -0700 (PDT) X-Received: by 2002:a17:902:788f:: with SMTP id q15mr30475998pll.236.1563215404893; Mon, 15 Jul 2019 11:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563215404; cv=none; d=google.com; s=arc-20160816; b=SlOQfAYVPOgE+4GK2DkiufCDe/zbRhIHMMyCf9xmekdmGJwA/4vuTxp1Kx++lfqwUT Oh7rA5Qc1e/YwUNFaXlL+6EbQTxtEPvLiD++9fnGitGluizI7l2b5bUMQXMCyubKV6XC wciQYfvTLe9uAh1h/ixRs3IVd/sXMc2pePQr1VKNgoE/jf0h/pb53Q5t3O5ZElXigejQ 9Y/Jh8/rXb5eHnNbX/R+KJOLcYwezf3eCmT3vADrndm5IxeB3DwWCo5QsI80qqq+THKR aHcw6tuY+SVmqPQM1Exa6wMC2nB6ZjIXJjkjg7Dkq5xa+QtgNvozFRXspvvKsGM1TXZk 6m4g== 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=sqbrOYwvlaoeOAcZLAQeQHRuttDiSnuSC+eoRb7//98=; b=gq9OwB+HcC1Kqzzlowkxybw5sZySjWhVHkL8iLaAzmHns9kH/0ndjHpyyA/StezTDl 0XdLLI/haTSc+KpiwNk4IV3WcH58atdnbLgxqZT9neD0Y5/b49SW8qBZMbbhZwuTFiZp +Ru20wcaEoDyqUAo0b4Aj751Oeub/ouahZBHRla3YuwM9HjNoiamTRIHjf+d7goc1kkV qFffSHjMw82lj2PSN+MbYyN2LxO2M/64jq8w8s7myrvC532Vkha8U3ZDGgUoD6OAgqDI UV2fEktCbICqPM73cC/P7JN843ObzoiaZZnMi4qR5F0e7VKCRWlT0v6eovZQOixTTN2o LErA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=F9mZj79u; 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 g71sor21861218pje.16.2019.07.15.11.30.04 for (Google Transport Security); Mon, 15 Jul 2019 11:30:04 -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:35e6:: with SMTP id r93mr31007925pjb.20.1563215404504; Mon, 15 Jul 2019 11:30:04 -0700 (PDT) Received: from localhost.localdomain ([49.206.201.107]) by smtp.gmail.com with ESMTPSA id y133sm20250075pfb.28.2019.07.15.11.30.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jul 2019 11:30:04 -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 16/18] ram: rk3399: Add rank detection support Date: Mon, 15 Jul 2019 23:58:54 +0530 Message-Id: <20190715182856.21688-17-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=F9mZj79u; 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 Reviewed-by: Kever Yang --- drivers/ram/rockchip/sdram_rk3399.c | 110 ++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 24 deletions(-) diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index 8bbacb5275..b83955f94e 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -1254,13 +1254,52 @@ static unsigned char calculate_stride(struct rk3399_sdram_params *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, channel); + } + + return 0; +} + static int sdram_init(struct dram_info *dram, struct rk3399_sdram_params *params) { unsigned char dramtype = params->base.dramtype; unsigned int ddr_freq = 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"); @@ -1272,36 +1311,59 @@ 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++) { + params->ch[ch].cap_info.rank = 2; + for (rank = 2; rank != 0; rank--) { + ret = pctl_init(dram, 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 >= params->base.num_channels) - continue; + params->ch[ch].cap_info.rank = rank; - ret = pctl_cfg(dram, chan, channel, 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 (params->base.dramtype == LPDDR3) + training_flag |= PI_CA_TRAINING; - /* start to trigger initialization */ - pctl_start(dram, channel); + if (!(data_training(&dram->chan[ch], ch, + params, training_flag))) + break; + } + /* Computed rank with associated channel number */ + params->ch[ch].cap_info.rank = rank; + } - /* LPDDR2/LPDDR3 need to wait DAI complete, max 10us */ - if (dramtype == LPDDR3) - udelay(10); + 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 = ¶ms->ch[channel].cap_info; - if (data_training(chan, channel, params, PI_FULL_TRAINING)) { - printf("%s: data training failed\n", __func__); - return -EIO; + if (cap_info->rank == 0) { + clear_channel_params(params, channel); + continue; + } else { + params->base.num_channels++; } - set_ddrconfig(chan, params, channel, - params->ch[channel].cap_info.ddrconfig); + debug("Channel "); + debug(channel ? "1: " : "0: "); + + set_ddrconfig(chan, params, channel, cap_info->ddrconfig); + } + + if (params->base.num_channels == 0) { + printf("%s: ", __func__); + printf(" - %dMHz failed!\n", params->base.ddr_freq); + return -EINVAL; } params->base.stride = calculate_stride(params);