Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7502802yba; Thu, 2 May 2019 10:59:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNHwzJ1BOVOXnULbmUbf3EF7Z85wk5Ucd5zbACtmlx+I7ioUDjP3whp3KsgLWXDKXk+yUH X-Received: by 2002:a63:c10d:: with SMTP id w13mr5274625pgf.311.1556819985713; Thu, 02 May 2019 10:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556819985; cv=none; d=google.com; s=arc-20160816; b=NPOxnxBt/LvQX5sk/5X3T545Oy3Yznhv3hHQWum5ZS9Drxae9LOCzHcwZYTbGllW9q tIxD++Z2lIlN2syu+eo2wxrxUMHgIn0BggqYXTAvylCWJGfpVWM4C8rmzS7ONT56yZWE 1VMdbDJYbg6i+3ElNZ1PiNfol6bM92rUvY9iQkOQ8VJ6X7mJTxzqd0CnPH4QNZtt15yb dGFEY3fjaE+eEC9HdDmAkxDxSQakxTF8skpsDjfilnPhNDKR8IcbyHvxV1Jb8OffqqVe 1NXHCw5RKVzMwvZD9MPeUd/Q84fBoLd0So72f+ERjosdL9cmninJL45nFj892P5sowy+ hoEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qWDDbIUL1vkx6IYew+jJHkK3emc/iViO9+Tm/iQaewc=; b=q7PZQUs9TozLOhRFpn3Kh5/yMuqbaFvkNEKbYmp78mIMsfx2WCIkf58qWfNpMZ/+s4 osA35I0JrAkJqNJoeso4jyvrcbVT7slth+fS1Vsdy0XAMqwpZgoKE7ZiY13aZPr/9vtE k3ZEssvBoHvh1gfzZUL5xFUZykQCogVxfnlpmsZEXNfb/TUMyTq/ik+U/YvM4aZeQsa2 KVS8q/SCGgg/AISu9RNzLKGbxKJ3e6omAj8G2KeQT5iWJ5uZEnFrblzBeqSfD9FWLF1y cf2ikH2FEFtsWgI60h+nSpgg5VMAH+/O6nltap1k5lRgBxtM6vAQHrHVNkrmByrLCKaY XMOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si4254990plf.398.2019.05.02.10.59.23; Thu, 02 May 2019 10:59:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbfEBR63 (ORCPT + 99 others); Thu, 2 May 2019 13:58:29 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:41862 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfEBR61 (ORCPT ); Thu, 2 May 2019 13:58:27 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: gportay) with ESMTPSA id 13200283428 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Rob Herring , Heiko Stuebner , Enric Balletbo i Serra , Lin Huang , Brian Norris , Douglas Anderson , Klaus Goger , Derek Basehore , Randy Li , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org Cc: Mark Rutland , kernel@collabora.com, =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Subject: [PATCH v5 3/6] devfreq: rk3399_dmc: Pass ODT and auto power down parameters to TF-A. Date: Thu, 2 May 2019 13:58:17 -0400 Message-Id: <20190502175820.25382-4-gael.portay@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502175820.25382-1-gael.portay@collabora.com> References: <20190502175820.25382-1-gael.portay@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Enric Balletbo i Serra Trusted Firmware-A (TF-A) for rk3399 implements a SiP call to get the on-die termination (ODT) and auto power down parameters from kernel, this patch adds the functionality to do this. Also, if DDR clock frequency is lower than the on-die termination (ODT) disable frequency this driver should disable the DDR ODT. Signed-off-by: Enric Balletbo i Serra Reviewed-by: Chanwoo Choi Signed-off-by: Gaël PORTAY Acked-by: MyungJoo Ham --- Changes in v5: None Changes in v4: - [PATCH v3 3/5] Add Acked-by: MyungJoo Ham . Changes in v3: - [PATCH v2 3/5] Add Signed-off-by: Gaël PORTAY . Remove comments. Move pmu dt parsing after dt-parsing of timings to fix data->odt_dis_freq value. Changes in v2: None Changes in v1: - [RFC 3/10] Add an explanation for platform SIP calls. - [RFC 3/10] Change if statement for a switch. - [RFC 3/10] Rename ddr_flag to odt_enable to be more clear. drivers/devfreq/rk3399_dmc.c | 71 ++++++++++++++++++++++++++++- include/soc/rockchip/rockchip_sip.h | 1 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/rk3399_dmc.c b/drivers/devfreq/rk3399_dmc.c index e795ad2b3f6b..daf19e121c99 100644 --- a/drivers/devfreq/rk3399_dmc.c +++ b/drivers/devfreq/rk3399_dmc.c @@ -18,14 +18,17 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include +#include #include struct dram_timing { @@ -69,8 +72,11 @@ struct rk3399_dmcfreq { struct mutex lock; struct dram_timing timing; struct regulator *vdd_center; + struct regmap *regmap_pmu; unsigned long rate, target_rate; unsigned long volt, target_volt; + unsigned int odt_dis_freq; + int odt_pd_arg0, odt_pd_arg1; }; static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq, @@ -80,6 +86,8 @@ static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq, struct dev_pm_opp *opp; unsigned long old_clk_rate = dmcfreq->rate; unsigned long target_volt, target_rate; + struct arm_smccc_res res; + bool odt_enable = false; int err; opp = devfreq_recommended_opp(dev, freq, flags); @@ -95,6 +103,19 @@ static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq, mutex_lock(&dmcfreq->lock); + if (target_rate >= dmcfreq->odt_dis_freq) + odt_enable = true; + + /* + * This makes a SMC call to the TF-A to set the DDR PD (power-down) + * timings and to enable or disable the ODT (on-die termination) + * resistors. + */ + arm_smccc_smc(ROCKCHIP_SIP_DRAM_FREQ, dmcfreq->odt_pd_arg0, + dmcfreq->odt_pd_arg1, + ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD, + odt_enable, 0, 0, 0, &res); + /* * If frequency scaling from low to high, adjust voltage first. * If frequency scaling from high to low, adjust frequency first. @@ -294,11 +315,13 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev) { struct arm_smccc_res res; struct device *dev = &pdev->dev; - struct device_node *np = pdev->dev.of_node; + struct device_node *np = pdev->dev.of_node, *node; struct rk3399_dmcfreq *data; int ret, index, size; uint32_t *timing; struct dev_pm_opp *opp; + u32 ddr_type; + u32 val; data = devm_kzalloc(dev, sizeof(struct rk3399_dmcfreq), GFP_KERNEL); if (!data) @@ -354,10 +377,56 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev) } } + node = of_parse_phandle(np, "rockchip,pmu", 0); + if (node) { + data->regmap_pmu = syscon_node_to_regmap(node); + if (IS_ERR(data->regmap_pmu)) + return PTR_ERR(data->regmap_pmu); + } + + regmap_read(data->regmap_pmu, RK3399_PMUGRF_OS_REG2, &val); + ddr_type = (val >> RK3399_PMUGRF_DDRTYPE_SHIFT) & + RK3399_PMUGRF_DDRTYPE_MASK; + + switch (ddr_type) { + case RK3399_PMUGRF_DDRTYPE_DDR3: + data->odt_dis_freq = data->timing.ddr3_odt_dis_freq; + break; + case RK3399_PMUGRF_DDRTYPE_LPDDR3: + data->odt_dis_freq = data->timing.lpddr3_odt_dis_freq; + break; + case RK3399_PMUGRF_DDRTYPE_LPDDR4: + data->odt_dis_freq = data->timing.lpddr4_odt_dis_freq; + break; + default: + return -EINVAL; + }; + arm_smccc_smc(ROCKCHIP_SIP_DRAM_FREQ, 0, 0, ROCKCHIP_SIP_CONFIG_DRAM_INIT, 0, 0, 0, 0, &res); + /* + * In TF-A there is a platform SIP call to set the PD (power-down) + * timings and to enable or disable the ODT (on-die termination). + * This call needs three arguments as follows: + * + * arg0: + * bit[0-7] : sr_idle + * bit[8-15] : sr_mc_gate_idle + * bit[16-31] : standby idle + * arg1: + * bit[0-11] : pd_idle + * bit[16-27] : srpd_lite_idle + * arg2: + * bit[0] : odt enable + */ + data->odt_pd_arg0 = (data->timing.sr_idle & 0xff) | + ((data->timing.sr_mc_gate_idle & 0xff) << 8) | + ((data->timing.standby_idle & 0xffff) << 16); + data->odt_pd_arg1 = (data->timing.pd_idle & 0xfff) | + ((data->timing.srpd_lite_idle & 0xfff) << 16); + /* * We add a devfreq driver to our parent since it has a device tree node * with operating points. diff --git a/include/soc/rockchip/rockchip_sip.h b/include/soc/rockchip/rockchip_sip.h index 7e28092c4d3d..ad9482c56797 100644 --- a/include/soc/rockchip/rockchip_sip.h +++ b/include/soc/rockchip/rockchip_sip.h @@ -23,5 +23,6 @@ #define ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE 0x05 #define ROCKCHIP_SIP_CONFIG_DRAM_CLR_IRQ 0x06 #define ROCKCHIP_SIP_CONFIG_DRAM_SET_PARAM 0x07 +#define ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD 0x08 #endif -- 2.21.0