From patchwork Mon Jul 15 18:21:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 724 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 7D6073F0E1 for ; Mon, 15 Jul 2019 20:21:57 +0200 (CEST) Received: by mail-pl1-f198.google.com with SMTP id 91sf8686804pla.7 for ; Mon, 15 Jul 2019 11:21:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1563214916; cv=pass; d=google.com; s=arc-20160816; b=mKaDZTQifMiN7cm0uDbvY69GIQ41Hwj8BbJjo6wQH/cGOwk3bFaW/QWO78Ix3QmHsa euPQBub6uO7lEOKroZHIx8kn/atIDZ/t7rJiSOeRj1szEbHGQAer4LY0+UKopsB0eFD2 m9ewC5V+788Al1wjy+Exn2ZCpiyl56xngVYCC5H0ettloE30OTDM6juOPvWs1f2tx/tB mRazWGV8AUDMvK7TvsjBL/lz0WgLla4nkX4RQrz50sjkVbcBEfIcVe+1gNyAPXyH8U3x uJ23lT/2Nif0W493L2GQ4M1552RW2eHSczkVlky64jgN4BngkeHqkrNvvSOQZnthINDg KrnQ== 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=ivRRJjxArUDORLvpjX6jFg5BYgeXYjD3/KdIdn96GlI=; b=OIZ5mwmjH15JGo+2SmNasv9TCojNldyBt+Y94h62HQIShoY6N1Mwebnql/Sai8qAE/ ++rD+PFQhvWn3WGzV316kx5YcDJTbbXJwWO4jtWBPI/nvIkiIp83QHqhkYkD6ITem5a0 CtsRlilgZv/jfbB/OULXFB3S/BAKreX8tm75U/P2e49rynDtwocVSUoOMIQTqg9gNysw OTNjk3p71Y/t2iDi1rvtIgNPVomFXLp/xMaV0JlsbLSWUAuP/+raNHB/FdSPNyY3Dn2P JTD+5KbvywP7LjEC3O+qNqgLr51DAftdCMHeSt79XfTtqoJoR68K/Jqq5OufTN8hkrKC Noiw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=JUmjZMbz; 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=ivRRJjxArUDORLvpjX6jFg5BYgeXYjD3/KdIdn96GlI=; b=rpCKFmtHf7VlvDBXH630XMgRAZnBLViDFElnoCE8ZPERnj5hnHzEDIwWpN2UGBoTJv j79FtrUHCpkvVH2QjqHboq7QckhXGzIlzrIGfhfO+tDhbmlatjmwNvClpkQqIk2i/qUL OjEnwFad5x5HpNu2+VuQG79Xt1+qF1B1UfPDQ= 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=ivRRJjxArUDORLvpjX6jFg5BYgeXYjD3/KdIdn96GlI=; b=DYWwJuNi0xykvDf+nLeM+AHA0db1jo97p9kIfIY6OMDG85qsiUlBVP8wzL0GSk77Li xI99Xflr51RI6o1yV+xdnukOY6Rb19PVvUGKLMBgmPv0XuJvUXMrpFADklpcsRpuVoxv NMipdYVPzmn2zexOTNOGgf10ZIoUAkyN2ZnimTp/tJYUO1SJWrgOMe+DVK1YLCrQ+h4a wFwypXcGYgL9z8NnX1MdwjISqTRwx+oA9bqYP9B1tGqIY1P5d/qm4h7g6UKmHb9WbfXb cvWfDQB/o36M2caS1CfzQIOKQmU/+q+KZWcDpiyxsATRTJiwDkaJQ1Tunn0bydf7M4jh yQDA== X-Gm-Message-State: APjAAAX7Xkj9FtqUA46uqtiIxnKU3X8iq54g42FfBmHuwPDqBFi7i7yE TYBXyOF694XYt6qfITC99mhcdpa8 X-Google-Smtp-Source: APXvYqweMpREg9ELxW+fsZYyS8C/FNXaa5kaeR/WmtdO28ZGxl7tI8UJtIdCS5GG8SFsoHGYcV16XQ== X-Received: by 2002:a63:2ad5:: with SMTP id q204mr15467723pgq.140.1563214916213; Mon, 15 Jul 2019 11:21:56 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a65:454c:: with SMTP id x12ls2209786pgr.10.gmail; Mon, 15 Jul 2019 11:21:56 -0700 (PDT) X-Received: by 2002:a63:755e:: with SMTP id f30mr28533797pgn.246.1563214915821; Mon, 15 Jul 2019 11:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563214915; cv=none; d=google.com; s=arc-20160816; b=VS5kfd0ylOpoAr+RXSWykyWG6p/vbbNnvuqt2JrdMANQUMYuajMUeEe9hlisq8fdoK DsaYALrclfwhIBmyP5PoiJA+LDTNpJ2PpnH9OvA801YiT27mf6fJn+/Zebcts3eSBp3e PAtFXd948CsTKA8nbI34IKHxuW5yyA/PChN7F4F1IGCGiwdnEeMkoCiM+fDfZlWRAg9U jS8PbN6UNgCskpvKKFkLkP3BNKr/bxX7d9NSHSCJ9ToZko+gzvrnCXcMS5sXxY43v7OZ 5MLf+YnyLO2WgT1E52nF7yxpk0DzTN3lzYD7dLGvXKAmzVNDGmZAdEoGU2gy5SjqtmwW LU5g== 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=+9/anVDS7Q12usMSqx4jEVXDSHZX9ttjNc+q4flrxR8=; b=fwuCB55uONC/mB3sqQopGEDVZ9yMSygKVkYLqtOdhl/Pq+hGguw6t7AeLLukScyKhW 2CYIpMvJRg1xeI3rmyiip6BF5FTMsw9fLoG5RtmEzuOcsnlimwK3bu99z8snuph9vZy3 /nOqPGodxx0w64kUgCB/JdnMvf+8cr6gyPAy/iMouQe3iKfilz5xRm4yXFEGutYjh19s q/F4etGEzOOUXZTPz6oBwfZ3Em0BT1EG3yqMGkAZJIWDTUHFU+DIfk3GA1xRAwwsyNmh cQV/4+4RFd2kIIpKKKVNStfxjc0qygj9koRk3o3Km4F8lbhzEWM0faAtOENu5a/FHB6O 8Vfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=JUmjZMbz; 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 f7sor9254086pgc.20.2019.07.15.11.21.55 for (Google Transport Security); Mon, 15 Jul 2019 11:21:55 -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:9c5:: with SMTP id 188mr3258004pgj.2.1563214915446; Mon, 15 Jul 2019 11:21:55 -0700 (PDT) Received: from localhost.localdomain ([49.206.201.107]) by smtp.gmail.com with ESMTPSA id l15sm18152405pgf.5.2019.07.15.11.21.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Jul 2019 11:21:55 -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 10/15] ram: rockchip: rk3399: Add cap_info structure Date: Mon, 15 Jul 2019 23:51:05 +0530 Message-Id: <20190715182110.21336-11-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190715182110.21336-1-jagan@amarulasolutions.com> References: <20190715182110.21336-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=JUmjZMbz; 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: , Group common ddr attributes like - rank - col - bk - bw - dbw - row_3_4 - cs0_row - cs1_row - ddrconfig into a common cap_info structure for more code readability and extend if possible based on the new features. Signed-off-by: Jagan Teki Reviewed-by: Kever Yang --- .../include/asm/arch-rockchip/sdram_rk3399.h | 6 +- drivers/ram/rockchip/sdram_rk3399.c | 73 ++++++++++--------- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/arch/arm/include/asm/arch-rockchip/sdram_rk3399.h b/arch/arm/include/asm/arch-rockchip/sdram_rk3399.h index c6a260bad8..683093d4ca 100644 --- a/arch/arm/include/asm/arch-rockchip/sdram_rk3399.h +++ b/arch/arm/include/asm/arch-rockchip/sdram_rk3399.h @@ -71,7 +71,7 @@ struct rk3399_ddr_cic_regs { /* DENALI_CTL_274 */ #define MEM_RST_VALID 1 -struct rk3399_sdram_channel { +struct sdram_cap_info { unsigned int rank; /* dram column number, 0 means this channel is invalid */ unsigned int col; @@ -89,6 +89,10 @@ struct rk3399_sdram_channel { unsigned int cs0_row; unsigned int cs1_row; unsigned int ddrconfig; +}; + +struct rk3399_sdram_channel { + struct sdram_cap_info cap_info; struct rk3399_msch_timings noc_timings; }; diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index 043b27737d..492b0975dd 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -121,35 +121,36 @@ static void set_memory_map(const struct chan_info *chan, u32 channel, u32 row; /* Get row number from ddrconfig setting */ - if (sdram_ch->ddrconfig < 2 || sdram_ch->ddrconfig == 4) + if (sdram_ch->cap_info.ddrconfig < 2 || + sdram_ch->cap_info.ddrconfig == 4) row = 16; - else if (sdram_ch->ddrconfig == 3) + else if (sdram_ch->cap_info.ddrconfig == 3) row = 14; else row = 15; - cs_map = (sdram_ch->rank > 1) ? 3 : 1; - reduc = (sdram_ch->bw == 2) ? 0 : 1; + cs_map = (sdram_ch->cap_info.rank > 1) ? 3 : 1; + reduc = (sdram_ch->cap_info.bw == 2) ? 0 : 1; /* Set the dram configuration to ctrl */ - clrsetbits_le32(&denali_ctl[191], 0xF, (12 - sdram_ch->col)); + clrsetbits_le32(&denali_ctl[191], 0xF, (12 - sdram_ch->cap_info.col)); clrsetbits_le32(&denali_ctl[190], (0x3 << 16) | (0x7 << 24), - ((3 - sdram_ch->bk) << 16) | + ((3 - sdram_ch->cap_info.bk) << 16) | ((16 - row) << 24)); clrsetbits_le32(&denali_ctl[196], 0x3 | (1 << 16), cs_map | (reduc << 16)); /* PI_199 PI_COL_DIFF:RW:0:4 */ - clrsetbits_le32(&denali_pi[199], 0xF, (12 - sdram_ch->col)); + clrsetbits_le32(&denali_pi[199], 0xF, (12 - sdram_ch->cap_info.col)); /* PI_155 PI_ROW_DIFF:RW:24:3 PI_BANK_DIFF:RW:16:2 */ clrsetbits_le32(&denali_pi[155], (0x3 << 16) | (0x7 << 24), - ((3 - sdram_ch->bk) << 16) | + ((3 - sdram_ch->cap_info.bk) << 16) | ((16 - row) << 24)); /* PI_41 PI_CS_MAP:RW:24:4 */ clrsetbits_le32(&denali_pi[41], 0xf << 24, cs_map << 24); - if (sdram_ch->rank == 1 && params->base.dramtype == DDR3) + if (sdram_ch->cap_info.rank == 1 && params->base.dramtype == DDR3) writel(0x2EC7FFFF, &denali_pi[34]); } @@ -624,7 +625,7 @@ static int data_training_ca(const struct chan_info *chan, u32 channel, u32 *denali_phy = chan->publ->denali_phy; u32 i, tmp; u32 obs_0, obs_1, obs_2, obs_err = 0; - u32 rank = params->ch[channel].rank; + u32 rank = params->ch[channel].cap_info.rank; for (i = 0; i < rank; i++) { select_per_cs_training_index(chan, i); @@ -678,7 +679,7 @@ static int data_training_wl(const struct chan_info *chan, u32 channel, u32 *denali_phy = chan->publ->denali_phy; u32 i, tmp; u32 obs_0, obs_1, obs_2, obs_3, obs_err = 0; - u32 rank = params->ch[channel].rank; + u32 rank = params->ch[channel].cap_info.rank; for (i = 0; i < rank; i++) { select_per_cs_training_index(chan, i); @@ -737,7 +738,7 @@ static int data_training_rg(const struct chan_info *chan, u32 channel, u32 *denali_phy = chan->publ->denali_phy; u32 i, tmp; u32 obs_0, obs_1, obs_2, obs_3, obs_err = 0; - u32 rank = params->ch[channel].rank; + u32 rank = params->ch[channel].cap_info.rank; for (i = 0; i < rank; i++) { select_per_cs_training_index(chan, i); @@ -796,7 +797,7 @@ static int data_training_rl(const struct chan_info *chan, u32 channel, { u32 *denali_pi = chan->pi->denali_pi; u32 i, tmp; - u32 rank = params->ch[channel].rank; + u32 rank = params->ch[channel].cap_info.rank; for (i = 0; i < rank; i++) { select_per_cs_training_index(chan, i); @@ -841,7 +842,7 @@ static int data_training_wdql(const struct chan_info *chan, u32 channel, { u32 *denali_pi = chan->pi->denali_pi; u32 i, tmp; - u32 rank = params->ch[channel].rank; + u32 rank = params->ch[channel].cap_info.rank; for (i = 0; i < rank; i++) { select_per_cs_training_index(chan, i); @@ -940,14 +941,14 @@ static void set_ddrconfig(const struct chan_info *chan, unsigned int cs0_cap = 0; unsigned int cs1_cap = 0; - cs0_cap = (1 << (params->ch[channel].cs0_row - + params->ch[channel].col - + params->ch[channel].bk - + params->ch[channel].bw - 20)); - if (params->ch[channel].rank > 1) - cs1_cap = cs0_cap >> (params->ch[channel].cs0_row - - params->ch[channel].cs1_row); - if (params->ch[channel].row_3_4) { + cs0_cap = (1 << (params->ch[channel].cap_info.cs0_row + + params->ch[channel].cap_info.col + + params->ch[channel].cap_info.bk + + params->ch[channel].cap_info.bw - 20)); + if (params->ch[channel].cap_info.rank > 1) + cs1_cap = cs0_cap >> (params->ch[channel].cap_info.cs0_row + - params->ch[channel].cap_info.cs1_row); + if (params->ch[channel].cap_info.row_3_4) { cs0_cap = cs0_cap * 3 / 4; cs1_cap = cs1_cap * 3 / 4; } @@ -973,20 +974,26 @@ static void dram_all_config(struct dram_info *dram, struct rk3399_msch_regs *ddr_msch_regs; const struct rk3399_msch_timings *noc_timing; - if (params->ch[channel].col == 0) + if (params->ch[channel].cap_info.col == 0) continue; idx++; - sys_reg |= info->row_3_4 << SYS_REG_ROW_3_4_SHIFT(channel); + sys_reg |= info->cap_info.row_3_4 << + SYS_REG_ROW_3_4_SHIFT(channel); sys_reg |= 1 << SYS_REG_CHINFO_SHIFT(channel); - sys_reg |= (info->rank - 1) << SYS_REG_RANK_SHIFT(channel); - sys_reg |= (info->col - 9) << SYS_REG_COL_SHIFT(channel); - sys_reg |= info->bk == 3 ? 0 : 1 << SYS_REG_BK_SHIFT(channel); - sys_reg |= (info->cs0_row - 13) << + sys_reg |= (info->cap_info.rank - 1) << + SYS_REG_RANK_SHIFT(channel); + sys_reg |= (info->cap_info.col - 9) << + SYS_REG_COL_SHIFT(channel); + sys_reg |= info->cap_info.bk == 3 ? 0 : 1 << + SYS_REG_BK_SHIFT(channel); + sys_reg |= (info->cap_info.cs0_row - 13) << SYS_REG_CS0_ROW_SHIFT(channel); - sys_reg |= (info->cs1_row - 13) << + sys_reg |= (info->cap_info.cs1_row - 13) << SYS_REG_CS1_ROW_SHIFT(channel); - sys_reg |= (2 >> info->bw) << SYS_REG_BW_SHIFT(channel); - sys_reg |= (2 >> info->dbw) << SYS_REG_DBW_SHIFT(channel); + sys_reg |= (2 >> info->cap_info.bw) << + SYS_REG_BW_SHIFT(channel); + sys_reg |= (2 >> info->cap_info.dbw) << + SYS_REG_DBW_SHIFT(channel); ddr_msch_regs = dram->chan[channel].msch; noc_timing = ¶ms->ch[channel].noc_timings; @@ -1002,7 +1009,7 @@ static void dram_all_config(struct dram_info *dram, &ddr_msch_regs->ddrmode); /* rank 1 memory clock disable (dfi_dram_clk_disable = 1) */ - if (params->ch[channel].rank == 1) + if (params->ch[channel].cap_info.rank == 1) setbits_le32(&dram->chan[channel].pctl->denali_ctl[276], 1 << 17); } @@ -1106,7 +1113,7 @@ static int sdram_init(struct dram_info *dram, } set_ddrconfig(chan, params, channel, - params->ch[channel].ddrconfig); + params->ch[channel].cap_info.ddrconfig); } dram_all_config(dram, params); switch_to_phy_index1(dram, params);