18
18
#include <linux/list.h>
19
19
#include <linux/of.h>
20
20
#include <linux/of_device.h>
21
+ #include <linux/bits.h>
21
22
22
23
#include <soc/rockchip/rk3399_grf.h>
23
24
24
- #define RK3399_DMC_NUM_CH 2
25
+ #define DMC_MAX_CHANNELS 2
25
26
26
27
/* DDRMON_CTRL */
27
28
#define DDRMON_CTRL 0x04
@@ -44,7 +45,7 @@ struct dmc_count_channel {
44
45
};
45
46
46
47
struct dmc_count {
47
- struct dmc_count_channel c [RK3399_DMC_NUM_CH ];
48
+ struct dmc_count_channel c [DMC_MAX_CHANNELS ];
48
49
};
49
50
50
51
/*
@@ -61,6 +62,8 @@ struct rockchip_dfi {
61
62
struct regmap * regmap_pmu ;
62
63
struct clk * clk ;
63
64
u32 ddr_type ;
65
+ unsigned int channel_mask ;
66
+ unsigned int max_channels ;
64
67
};
65
68
66
69
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
95
98
u32 i ;
96
99
void __iomem * dfi_regs = dfi -> regs ;
97
100
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 ;
99
104
count -> c [i ].access = readl_relaxed (dfi_regs +
100
105
DDRMON_CH0_DFI_ACCESS_NUM + i * 20 );
101
106
count -> c [i ].total = readl_relaxed (dfi_regs +
@@ -145,9 +150,14 @@ static int rockchip_dfi_get_event(struct devfreq_event_dev *edev,
145
150
rockchip_dfi_read_counters (edev , & count );
146
151
147
152
/* 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 ;
151
161
152
162
if (a > access ) {
153
163
access = a ;
@@ -185,6 +195,9 @@ static int rk3399_dfi_init(struct rockchip_dfi *dfi)
185
195
dfi -> ddr_type = (val >> RK3399_PMUGRF_DDRTYPE_SHIFT ) &
186
196
RK3399_PMUGRF_DDRTYPE_MASK ;
187
197
198
+ dfi -> channel_mask = GENMASK (1 , 0 );
199
+ dfi -> max_channels = 2 ;
200
+
188
201
return 0 ;
189
202
};
190
203
0 commit comments