Skip to content

Commit 63dcf38

Browse files
saschahauerchanwoochoi
authored andcommitted
PM / devfreq: rockchip-dfi: introduce channel mask
Different Rockchip SoC variants have a different number of channels. Introduce a channel mask to make the number of channels configurable from SoC initialization code. Link: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Sebastian Reichel <[email protected]> Signed-off-by: Sascha Hauer <[email protected]> Signed-off-by: Chanwoo Choi <[email protected]>
1 parent 9991166 commit 63dcf38

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

drivers/devfreq/event/rockchip-dfi.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
#include <linux/list.h>
1919
#include <linux/of.h>
2020
#include <linux/of_device.h>
21+
#include <linux/bits.h>
2122

2223
#include <soc/rockchip/rk3399_grf.h>
2324

24-
#define RK3399_DMC_NUM_CH 2
25+
#define DMC_MAX_CHANNELS 2
2526

2627
/* DDRMON_CTRL */
2728
#define DDRMON_CTRL 0x04
@@ -44,7 +45,7 @@ struct dmc_count_channel {
4445
};
4546

4647
struct dmc_count {
47-
struct dmc_count_channel c[RK3399_DMC_NUM_CH];
48+
struct dmc_count_channel c[DMC_MAX_CHANNELS];
4849
};
4950

5051
/*
@@ -61,6 +62,8 @@ struct rockchip_dfi {
6162
struct regmap *regmap_pmu;
6263
struct clk *clk;
6364
u32 ddr_type;
65+
unsigned int channel_mask;
66+
unsigned int max_channels;
6467
};
6568

6669
static void rockchip_dfi_start_hardware_counter(struct devfreq_event_dev *edev)
@@ -95,7 +98,9 @@ static void rockchip_dfi_read_counters(struct devfreq_event_dev *edev, struct dm
9598
u32 i;
9699
void __iomem *dfi_regs = dfi->regs;
97100

98-
for (i = 0; i < RK3399_DMC_NUM_CH; i++) {
101+
for (i = 0; i < dfi->max_channels; i++) {
102+
if (!(dfi->channel_mask & BIT(i)))
103+
continue;
99104
count->c[i].access = readl_relaxed(dfi_regs +
100105
DDRMON_CH0_DFI_ACCESS_NUM + i * 20);
101106
count->c[i].total = readl_relaxed(dfi_regs +
@@ -145,9 +150,14 @@ static int rockchip_dfi_get_event(struct devfreq_event_dev *edev,
145150
rockchip_dfi_read_counters(edev, &count);
146151

147152
/* We can only report one channel, so find the busiest one */
148-
for (i = 0; i < RK3399_DMC_NUM_CH; i++) {
149-
u32 a = count.c[i].access - last->c[i].access;
150-
u32 t = count.c[i].total - last->c[i].total;
153+
for (i = 0; i < dfi->max_channels; i++) {
154+
u32 a, t;
155+
156+
if (!(dfi->channel_mask & BIT(i)))
157+
continue;
158+
159+
a = count.c[i].access - last->c[i].access;
160+
t = count.c[i].total - last->c[i].total;
151161

152162
if (a > access) {
153163
access = a;
@@ -185,6 +195,9 @@ static int rk3399_dfi_init(struct rockchip_dfi *dfi)
185195
dfi->ddr_type = (val >> RK3399_PMUGRF_DDRTYPE_SHIFT) &
186196
RK3399_PMUGRF_DDRTYPE_MASK;
187197

198+
dfi->channel_mask = GENMASK(1, 0);
199+
dfi->max_channels = 2;
200+
188201
return 0;
189202
};
190203

0 commit comments

Comments
 (0)