Skip to content

Commit 9173c5c

Browse files
Enric Balletbo i Serramyungjoo
authored andcommitted
PM / devfreq: rk3399_dmc: Pass ODT and auto power down parameters to TF-A.
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 <enric.balletbo@collabora.com> Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Gaël PORTAY <gael.portay@collabora.com> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
1 parent adfe3b7 commit 9173c5c

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

‎drivers/devfreq/rk3399_dmc.c‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
#include <linux/devfreq.h>
1919
#include <linux/devfreq-event.h>
2020
#include <linux/interrupt.h>
21+
#include <linux/mfd/syscon.h>
2122
#include <linux/module.h>
2223
#include <linux/of.h>
2324
#include <linux/platform_device.h>
2425
#include <linux/pm_opp.h>
26+
#include <linux/regmap.h>
2527
#include <linux/regulator/consumer.h>
2628
#include <linux/rwsem.h>
2729
#include <linux/suspend.h>
2830

31+
#include <soc/rockchip/rk3399_grf.h>
2932
#include <soc/rockchip/rockchip_sip.h>
3033

3134
struct dram_timing {
@@ -69,8 +72,11 @@ struct rk3399_dmcfreq {
6972
struct mutex lock;
7073
struct dram_timing timing;
7174
struct regulator *vdd_center;
75+
struct regmap *regmap_pmu;
7276
unsigned long rate, target_rate;
7377
unsigned long volt, target_volt;
78+
unsigned int odt_dis_freq;
79+
int odt_pd_arg0, odt_pd_arg1;
7480
};
7581

7682
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,
8086
struct dev_pm_opp *opp;
8187
unsigned long old_clk_rate = dmcfreq->rate;
8288
unsigned long target_volt, target_rate;
89+
struct arm_smccc_res res;
90+
bool odt_enable = false;
8391
int err;
8492

8593
opp = devfreq_recommended_opp(dev, freq, flags);
@@ -95,6 +103,19 @@ static int rk3399_dmcfreq_target(struct device *dev, unsigned long *freq,
95103

96104
mutex_lock(&dmcfreq->lock);
97105

106+
if (target_rate >= dmcfreq->odt_dis_freq)
107+
odt_enable = true;
108+
109+
/*
110+
* This makes a SMC call to the TF-A to set the DDR PD (power-down)
111+
* timings and to enable or disable the ODT (on-die termination)
112+
* resistors.
113+
*/
114+
arm_smccc_smc(ROCKCHIP_SIP_DRAM_FREQ, dmcfreq->odt_pd_arg0,
115+
dmcfreq->odt_pd_arg1,
116+
ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD,
117+
odt_enable, 0, 0, 0, &res);
118+
98119
/*
99120
* If frequency scaling from low to high, adjust voltage first.
100121
* If frequency scaling from high to low, adjust frequency first.
@@ -294,11 +315,13 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev)
294315
{
295316
struct arm_smccc_res res;
296317
struct device *dev = &pdev->dev;
297-
struct device_node *np = pdev->dev.of_node;
318+
struct device_node *np = pdev->dev.of_node, *node;
298319
struct rk3399_dmcfreq *data;
299320
int ret, index, size;
300321
uint32_t *timing;
301322
struct dev_pm_opp *opp;
323+
u32 ddr_type;
324+
u32 val;
302325

303326
data = devm_kzalloc(dev, sizeof(struct rk3399_dmcfreq), GFP_KERNEL);
304327
if (!data)
@@ -354,10 +377,56 @@ static int rk3399_dmcfreq_probe(struct platform_device *pdev)
354377
}
355378
}
356379

380+
node = of_parse_phandle(np, "rockchip,pmu", 0);
381+
if (node) {
382+
data->regmap_pmu = syscon_node_to_regmap(node);
383+
if (IS_ERR(data->regmap_pmu))
384+
return PTR_ERR(data->regmap_pmu);
385+
}
386+
387+
regmap_read(data->regmap_pmu, RK3399_PMUGRF_OS_REG2, &val);
388+
ddr_type = (val >> RK3399_PMUGRF_DDRTYPE_SHIFT) &
389+
RK3399_PMUGRF_DDRTYPE_MASK;
390+
391+
switch (ddr_type) {
392+
case RK3399_PMUGRF_DDRTYPE_DDR3:
393+
data->odt_dis_freq = data->timing.ddr3_odt_dis_freq;
394+
break;
395+
case RK3399_PMUGRF_DDRTYPE_LPDDR3:
396+
data->odt_dis_freq = data->timing.lpddr3_odt_dis_freq;
397+
break;
398+
case RK3399_PMUGRF_DDRTYPE_LPDDR4:
399+
data->odt_dis_freq = data->timing.lpddr4_odt_dis_freq;
400+
break;
401+
default:
402+
return -EINVAL;
403+
};
404+
357405
arm_smccc_smc(ROCKCHIP_SIP_DRAM_FREQ, 0, 0,
358406
ROCKCHIP_SIP_CONFIG_DRAM_INIT,
359407
0, 0, 0, 0, &res);
360408

409+
/*
410+
* In TF-A there is a platform SIP call to set the PD (power-down)
411+
* timings and to enable or disable the ODT (on-die termination).
412+
* This call needs three arguments as follows:
413+
*
414+
* arg0:
415+
* bit[0-7] : sr_idle
416+
* bit[8-15] : sr_mc_gate_idle
417+
* bit[16-31] : standby idle
418+
* arg1:
419+
* bit[0-11] : pd_idle
420+
* bit[16-27] : srpd_lite_idle
421+
* arg2:
422+
* bit[0] : odt enable
423+
*/
424+
data->odt_pd_arg0 = (data->timing.sr_idle & 0xff) |
425+
((data->timing.sr_mc_gate_idle & 0xff) << 8) |
426+
((data->timing.standby_idle & 0xffff) << 16);
427+
data->odt_pd_arg1 = (data->timing.pd_idle & 0xfff) |
428+
((data->timing.srpd_lite_idle & 0xfff) << 16);
429+
361430
/*
362431
* We add a devfreq driver to our parent since it has a device tree node
363432
* with operating points.

‎include/soc/rockchip/rockchip_sip.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
#define ROCKCHIP_SIP_CONFIG_DRAM_GET_RATE 0x05
2424
#define ROCKCHIP_SIP_CONFIG_DRAM_CLR_IRQ 0x06
2525
#define ROCKCHIP_SIP_CONFIG_DRAM_SET_PARAM 0x07
26+
#define ROCKCHIP_SIP_CONFIG_DRAM_SET_ODT_PD 0x08
2627

2728
#endif

0 commit comments

Comments
 (0)