From patchwork Mon Jun 17 07:32:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 622 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 797AC3F353 for ; Mon, 17 Jun 2019 09:39:13 +0200 (CEST) Received: by mail-pl1-f199.google.com with SMTP id q6sf5506359pll.22 for ; Mon, 17 Jun 2019 00:39:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1560757152; cv=pass; d=google.com; s=arc-20160816; b=xnrEGNFLRDcnhZ3dQybcCmGaUFMu8IrryESIpULw2Dapc1g3yVcM1ctOyzt9YuGmT8 NbvghaP3UlX/77ACy9Sx+FPBoqD8EjLUQiBh609wSsqqSTQRef7zNjGolretlyLbF90p n7JO6LlTzWls/8lfyvqwWIGeIedWVb4yPiohQ7u4h1wywzaB0SeVu9OJQWdsl9MsRQf3 qOng25lTk2mRjEgUX1G3R7KMHEmTZKw6TsyIafDp3apK8wrAkyhLIrEWe3b1978HyGUH bM9n7bSfLQzkZCNuTJpY8ax4Xrwnf5GSra87mygR3LWnWgjPubbM71cvcMDAaje5gbvb 76GA== 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=d5rz63fvwMQf4F7UJleKFN5ERiJAP+C3uMx/N4UXZ54=; b=MeYa1rGal3q9TYb/n0Ss9CkuSBQINEI+tjFtDsXqHX/46U1CabA9+jv8/0JSAru0JD aWmNHXmq9zhzni6DeVC1n+u6cbH5Sx3/f68ZT/wUN+XKezAamHjWRxEWdJelhiFkFSq0 1H2taC1yFncsdSWcOYRuIsJ4qlDhEhgCUyHuMViqtMTc+79nIlklsO3B5MaRGc8isyym 0sdoNKBwxh+Vval1Dq07lB6f8KthcUIi3liFfbBqeF7yjQ33IJbTXxUBx407YKqu38OA QFtTMCP1zpLg3c/valnmNAIoovX4bbiO8wAIVpgvYq9uYiOeK0QqZy1qVx2CmNvJkncN Euqg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=J0g3tHVA; 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=d5rz63fvwMQf4F7UJleKFN5ERiJAP+C3uMx/N4UXZ54=; b=JJd/7x7X00Rpk4oe7G4vaZhFawSTsOxUjDHTBbrfleZA3US3ta2OAEQnYVg8t8GeAW aZUwKhfqQjIdPfoQnQ9pxtr970zXCjWf2YtXTcuM9s1aReWSl1J0e3S2zTXUhFs+l2Ci V4tKMVsH+ZqlLoTedT1aMhmppba8LYYF52hfY= 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=d5rz63fvwMQf4F7UJleKFN5ERiJAP+C3uMx/N4UXZ54=; b=oVvaV2wx3TxkFN9+C4Jff64cYf1MpKxCAs6mjhDakx/97Chx6We2FVHXYzCYp9NiiB pG0GSQovWK3S1cyHfAHwYsdSxWkGU81IL8MxJxpp9cZ1dN2FpAfFJYhbMTo4HeqiB/Yo AbkkMHJMgE6Kakq06T/dEEj1dO8MIQHUWFq+QqMNvlfSITPukN0CWNgvIxw/NSG8S2WT dRj6zt1U/xYJMQ4xteS2KZiBdA/Obo0eWx8DJQZ6HQDwZpLb+1XybeC7IgmGQ+F9LomR fJaZXfNIENZT1Tnox6e9m5UPsRVMZEj4/w1D1EwlXYpMGrG23priqema6vwUKMd1gOCe 9UiA== X-Gm-Message-State: APjAAAVbEJMbm1FnYXz1M4HPpRYpMGZ+0X7kjaxJsFePkqq9LGKAzqDn qUWlcUvZH3gbWmikYK8IefNMmIzc X-Google-Smtp-Source: APXvYqzTe370X5ymntvaKYEYaEebiB1xJ2pypkHLSOf2CcWX5db8TP97ez8AUJ8M0ieDPbJIvFJntg== X-Received: by 2002:a62:d149:: with SMTP id t9mr92534661pfl.173.1560757152284; Mon, 17 Jun 2019 00:39:12 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:52d2:: with SMTP id g201ls556782pfb.9.gmail; Mon, 17 Jun 2019 00:39:12 -0700 (PDT) X-Received: by 2002:a63:c106:: with SMTP id w6mr48489367pgf.422.1560757151872; Mon, 17 Jun 2019 00:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560757151; cv=none; d=google.com; s=arc-20160816; b=R8nsQ9D87L/SH1gWIIuUGwQn7bYiBmWXOuFA54ULaCflX0uYHfGWnglTBYx+jir/iF aCnh+lNmluXHTsHnuu8AQ41dRuzHe8pimC99j6FCKSdOzmrm+dHuBWmvmmi1Pk+ouw+k 43woCQ+xslecKGBCNcbpWVQfqpVleNXItSYafDrSMvcBDORJGcc/fWG5ndm+2GuINgP+ OWdHTrXUBk+9K91p/TZR7Ia8G5W+ltHHENJ05Au+xsfuh41RWLU1cqEjoyD1QAdUiAYr sNNqroQlJ4z+76gVCLWJpyjccWpHww4hh6N3HDcJOCRjkW/gytV5kfAHoqsZVZ6QzVs/ cF/A== 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=nxs5FOM4waY6g+1f/+R0EuUrDWb9KbY56RwcjoNKzrM=; b=ig543UXeHIBUDWF3IbMihI8DzkLF+cvLDHW/4nraZJyhalsp5YnzRsCrNCQtmO6mLi 1jhem2gf8ZMld61y8GSC2qhsxz6/4LnB82mw0cDdgjp/LTLUu1YRnKazXKmEXJUs59H8 5PQQ6orxOLV6f+p1CHZQ9M9CcqJIQh4zz2FZ3yB9FuCLFmtdj+KSeVYpWqCcBVW9IjP9 vsGPZ8vv506ch5mvCX15oDYzElNs3Yuuhh6M/W/tlTz5Y55YRs+OkxrLCz1iNgmXR8H8 7rw/fOcYIoK72kR4gW1qMHvwTZEz8Ba8A/lXrQl8sr6Ge23U+rBhpraL52z/TUghDpHO reUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=J0g3tHVA; 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 t6sor4598492plo.20.2019.06.17.00.39.11 for (Google Transport Security); Mon, 17 Jun 2019 00:39:11 -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:902:2006:: with SMTP id n6mr49800458pla.232.1560757151574; Mon, 17 Jun 2019 00:39:11 -0700 (PDT) Received: from localhost.localdomain ([49.206.203.245]) by smtp.gmail.com with ESMTPSA id m41sm15205998pje.18.2019.06.17.00.39.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Jun 2019 00:39:10 -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 v2 51/99] ram: rk3399: Add rank detection support Date: Mon, 17 Jun 2019 13:02:04 +0530 Message-Id: <20190617073252.27810-52-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190617073252.27810-1-jagan@amarulasolutions.com> References: <20190617073252.27810-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=J0g3tHVA; 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 | 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 87eda06055..a3acb75dba 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -1251,13 +1251,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"); @@ -1269,36 +1308,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);