History

Merge branches 'pm-opp', 'pm-devfreq' and 'powercap'

Merge an operating performance points (OPP) update, devfreq updates and power capping updates for 5.17-rc1: - Update outdated OPP documentation (Tang Yizhou). - Reduce log severity for informative message regarding frequency transition failures in devfreq (Tzung-Bi Shih). - Add DRAM frequency controller devfreq driver for Allwinner sunXi SoCs (Samuel Holland). - Add missing COMMON_CLK dependency to the sun8i devfreq driver (Arnd Bergmann). - Add support for new layout of Psys PowerLimit Register on SPR to the Intel RAPL power capping driver (Zhang Rui). - Fix typo in a comment in idle_inject.c (Jason Wang). - Remove unused function definition from the DTPM (Dynamit Thermal Power Management) power capping framework (Daniel Lezcano). - Reduce DTPM trace verbosity (Daniel Lezcano). * pm-opp: Documentation: power: Update outdated contents in opp.rst * pm-devfreq: PM / devfreq: Reduce log severity for informative message PM / devfreq: sun8i: addd COMMON_CLK dependency PM / devfreq: Add a driver for the sun8i/sun50i MBUS * powercap: powercap/drivers/dtpm: Reduce trace verbosity powercap/drivers/dtpm: Remove unused function definition powercap: fix typo in a comment in idle_inject.c powercap: intel_rapl: support new layout of Psys PowerLimit Register on SPR

Rafael J. Wysocki committed 4 years ago

Commit 78e6e4d4 parents c001a52 ffb9bfa 702f21d 36fd36010 files · +599 −17Browse files

Unified · Split

10 files
  1. Documentation/power/opp.rst +7 −7
  2. drivers/devfreq/Kconfig +9 −0
  3. drivers/devfreq/Makefile +1 −0
  4. drivers/devfreq/devfreq.c +2 −2
  5. drivers/devfreq/sun8i-a33-mbus.c +511 −0
  6. drivers/powercap/dtpm.c +3 −3
  7. drivers/powercap/idle_inject.c +1 −1
  8. drivers/powercap/intel_rapl_common.c +59 −2
  9. include/linux/dtpm.h +0 −2
  10. include/linux/intel_rapl.h +6 −0
Documentation/power/opp.rst+7−7
@@ -48,9 +48,9 @@ We can represent these as three OPPs as the following {Hz, uV} tuples: · 47 unmodified lines
48OPP library provides a set of helper functions to organize and query the OPP48OPP library provides a set of helper functions to organize and query the OPP
49information. The library is located in drivers/opp/ directory and the header49information. The library is located in drivers/opp/ directory and the header
50is located in include/linux/pm_opp.h. OPP library can be enabled by enabling50is located in include/linux/pm_opp.h. OPP library can be enabled by enabling
51CONFIG_PM_OPP from power management menuconfig menu. OPP library depends on51CONFIG_PM_OPP from power management menuconfig menu. Certain SoCs such as Texas
52CONFIG_PM as certain SoCs such as Texas Instrument's OMAP framework allows to52Instrument's OMAP framework allows to optionally boot at a certain OPP without
53optionally boot at a certain OPP without needing cpufreq.53needing cpufreq.
54 54
55Typical usage of the OPP library is as follows::55Typical usage of the OPP library is as follows::
56 56
@@ -75,8 +75,8 @@ operations until that OPP could be re-enabled if possible. · 18 unmodified lines
75 75
76OPP library facilitates this concept in its implementation. The following76OPP library facilitates this concept in its implementation. The following
77operational functions operate only on available opps:77operational functions operate only on available opps:
78opp_find_freq_{ceil, floor}, dev_pm_opp_get_voltage, dev_pm_opp_get_freq,78dev_pm_opp_find_freq_{ceil, floor}, dev_pm_opp_get_voltage, dev_pm_opp_get_freq,
79dev_pm_opp_get_opp_count79dev_pm_opp_get_opp_count.
80 80
81dev_pm_opp_find_freq_exact is meant to be used to find the opp pointer81dev_pm_opp_find_freq_exact is meant to be used to find the opp pointer
82which can then be used for dev_pm_opp_enable/disable functions to make an82which can then be used for dev_pm_opp_enable/disable functions to make an
@@ -103,7 +103,7 @@ dev_pm_opp_add · 20 unmodified lines
103 The OPP is defined using the frequency and voltage. Once added, the OPP103 The OPP is defined using the frequency and voltage. Once added, the OPP
104 is assumed to be available and control of its availability can be done104 is assumed to be available and control of its availability can be done
105 with the dev_pm_opp_enable/disable functions. OPP library105 with the dev_pm_opp_enable/disable functions. OPP library
106 internally stores and manages this information in the opp struct.106 internally stores and manages this information in the dev_pm_opp struct.
107 This function may be used by SoC framework to define a optimal list107 This function may be used by SoC framework to define a optimal list
108 as per the demands of SoC usage environment.108 as per the demands of SoC usage environment.
109 109
@@ -247,7 +247,7 @@ dev_pm_opp_disable · 137 unmodified lines
2475. OPP Data Retrieval Functions2475. OPP Data Retrieval Functions
248===============================248===============================
249Since OPP library abstracts away the OPP information, a set of functions to pull249Since OPP library abstracts away the OPP information, a set of functions to pull
250information from the OPP structure is necessary. Once an OPP pointer is250information from the dev_pm_opp structure is necessary. Once an OPP pointer is
251retrieved using the search functions, the following functions can be used by SoC251retrieved using the search functions, the following functions can be used by SoC
252framework to retrieve the information represented inside the OPP layer.252framework to retrieve the information represented inside the OPP layer.
253 253
drivers/devfreq/Kconfig+9−0
@@ -132,6 +132,15 @@ config ARM_RK3399_DMC_DEVFREQ · 131 unmodified lines
132 It sets the frequency for the memory controller and reads the usage counts132 It sets the frequency for the memory controller and reads the usage counts
133 from hardware.133 from hardware.
134 134
135config ARM_SUN8I_A33_MBUS_DEVFREQ
136 tristate "sun8i/sun50i MBUS DEVFREQ Driver"
137 depends on ARCH_SUNXI || COMPILE_TEST
138 depends on COMMON_CLK
139 select DEVFREQ_GOV_SIMPLE_ONDEMAND
140 help
141 This adds the DEVFREQ driver for the MBUS controller in some
142 Allwinner sun8i (A33 through H3) and sun50i (A64 and H5) SoCs.
143
135source "drivers/devfreq/event/Kconfig"144source "drivers/devfreq/event/Kconfig"
136 145
137endif # PM_DEVFREQ146endif # PM_DEVFREQ
drivers/devfreq/Makefile+1−0
@@ -12,6 +12,7 @@ obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o · 11 unmodified lines
12obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o12obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o
13obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.o13obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.o
14obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o14obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o
15obj-$(CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ) += sun8i-a33-mbus.o
15obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o16obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o
16 17
17# DEVFREQ Event Drivers18# DEVFREQ Event Drivers
drivers/devfreq/devfreq.c+2−2
@@ -382,8 +382,8 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq, · 381 unmodified lines
382 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);382 devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
383 383
384 if (devfreq_update_status(devfreq, new_freq))384 if (devfreq_update_status(devfreq, new_freq))
385 dev_err(&devfreq->dev,385 dev_warn(&devfreq->dev,
386 "Couldn't update frequency transition information.\n");386 "Couldn't update frequency transition information.\n");
387 387
388 devfreq->previous_freq = new_freq;388 devfreq->previous_freq = new_freq;
389 389
drivers/devfreq/sun8i-a33-mbus.c+511−0
@@ -0,0 +1,511 @@
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (C) 2020-2021 Samuel Holland <samuel@sholland.org>
4//
5
6#include <linux/clk.h>
7#include <linux/devfreq.h>
8#include <linux/err.h>
9#include <linux/io.h>
10#include <linux/iopoll.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/platform_device.h>
14#include <linux/property.h>
15
16#define MBUS_CR 0x0000
17#define MBUS_CR_GET_DRAM_TYPE(x) (((x) >> 16) & 0x7)
18#define MBUS_CR_DRAM_TYPE_DDR2 2
19#define MBUS_CR_DRAM_TYPE_DDR3 3
20#define MBUS_CR_DRAM_TYPE_DDR4 4
21#define MBUS_CR_DRAM_TYPE_LPDDR2 6
22#define MBUS_CR_DRAM_TYPE_LPDDR3 7
23
24#define MBUS_TMR 0x000c
25#define MBUS_TMR_PERIOD(x) ((x) - 1)
26
27#define MBUS_PMU_CFG 0x009c
28#define MBUS_PMU_CFG_PERIOD(x) (((x) - 1) << 16)
29#define MBUS_PMU_CFG_UNIT (0x3 << 1)
30#define MBUS_PMU_CFG_UNIT_B (0x0 << 1)
31#define MBUS_PMU_CFG_UNIT_KB (0x1 << 1)
32#define MBUS_PMU_CFG_UNIT_MB (0x2 << 1)
33#define MBUS_PMU_CFG_ENABLE (0x1 << 0)
34
35#define MBUS_PMU_BWCR(n) (0x00a0 + (0x04 * (n)))
36
37#define MBUS_TOTAL_BWCR MBUS_PMU_BWCR(5)
38#define MBUS_TOTAL_BWCR_H616 MBUS_PMU_BWCR(13)
39
40#define MBUS_MDFSCR 0x0100
41#define MBUS_MDFSCR_BUFFER_TIMING (0x1 << 15)
42#define MBUS_MDFSCR_PAD_HOLD (0x1 << 13)
43#define MBUS_MDFSCR_BYPASS (0x1 << 4)
44#define MBUS_MDFSCR_MODE (0x1 << 1)
45#define MBUS_MDFSCR_MODE_DFS (0x0 << 1)
46#define MBUS_MDFSCR_MODE_CFS (0x1 << 1)
47#define MBUS_MDFSCR_START (0x1 << 0)
48
49#define MBUS_MDFSMRMR 0x0108
50
51#define DRAM_PWRCTL 0x0004
52#define DRAM_PWRCTL_SELFREF_EN (0x1 << 0)
53
54#define DRAM_RFSHTMG 0x0090
55#define DRAM_RFSHTMG_TREFI(x) ((x) << 16)
56#define DRAM_RFSHTMG_TRFC(x) ((x) << 0)
57
58#define DRAM_VTFCR 0x00b8
59#define DRAM_VTFCR_VTF_ENABLE (0x3 << 8)
60
61#define DRAM_ODTMAP 0x0120
62
63#define DRAM_DX_MAX 4
64
65#define DRAM_DXnGCR0(n) (0x0344 + 0x80 * (n))
66#define DRAM_DXnGCR0_DXODT (0x3 << 4)
67#define DRAM_DXnGCR0_DXODT_DYNAMIC (0x0 << 4)
68#define DRAM_DXnGCR0_DXODT_ENABLED (0x1 << 4)
69#define DRAM_DXnGCR0_DXODT_DISABLED (0x2 << 4)
70#define DRAM_DXnGCR0_DXEN (0x1 << 0)
71
72struct sun8i_a33_mbus_variant {
73 u32 min_dram_divider;
74 u32 max_dram_divider;
75 u32 odt_freq_mhz;
76};
77
78struct sun8i_a33_mbus {
79 const struct sun8i_a33_mbus_variant *variant;
80 void __iomem *reg_dram;
81 void __iomem *reg_mbus;
82 struct clk *clk_bus;
83 struct clk *clk_dram;
84 struct clk *clk_mbus;
85 struct devfreq *devfreq_dram;
86 struct devfreq_simple_ondemand_data gov_data;
87 struct devfreq_dev_profile profile;
88 u32 data_width;
89 u32 nominal_bw;
90 u32 odtmap;
91 u32 tREFI_ns;
92 u32 tRFC_ns;
93 unsigned long freq_table[];
94};
95
96/*
97 * The unit for this value is (MBUS clock cycles / MBUS_TMR_PERIOD). When
98 * MBUS_TMR_PERIOD is programmed to match the MBUS clock frequency in MHz, as
99 * it is during DRAM init and during probe, the resulting unit is microseconds.
100 */
101static int pmu_period = 50000;
102module_param(pmu_period, int, 0644);
103MODULE_PARM_DESC(pmu_period, "Bandwidth measurement period (microseconds)");
104
105static u32 sun8i_a33_mbus_get_peak_bw(struct sun8i_a33_mbus *priv)
106{
107 /* Returns the peak transfer (in KiB) during any single PMU period. */
108 return readl_relaxed(priv->reg_mbus + MBUS_TOTAL_BWCR);
109}
110
111static void sun8i_a33_mbus_restart_pmu_counters(struct sun8i_a33_mbus *priv)
112{
113 u32 pmu_cfg = MBUS_PMU_CFG_PERIOD(pmu_period) | MBUS_PMU_CFG_UNIT_KB;
114
115 /* All PMU counters are cleared on a disable->enable transition. */
116 writel_relaxed(pmu_cfg,
117 priv->reg_mbus + MBUS_PMU_CFG);
118 writel_relaxed(pmu_cfg | MBUS_PMU_CFG_ENABLE,
119 priv->reg_mbus + MBUS_PMU_CFG);
120
121}
122
123static void sun8i_a33_mbus_update_nominal_bw(struct sun8i_a33_mbus *priv,
124 u32 ddr_freq_mhz)
125{
126 /*
127 * Nominal bandwidth (KiB per PMU period):
128 *
129 * DDR transfers microseconds KiB
130 * ------------- * ------------ * --------
131 * microsecond PMU period transfer
132 */
133 priv->nominal_bw = ddr_freq_mhz * pmu_period * priv->data_width / 1024;
134}
135
136static int sun8i_a33_mbus_set_dram_freq(struct sun8i_a33_mbus *priv,
137 unsigned long freq)
138{
139 u32 ddr_freq_mhz = freq / USEC_PER_SEC; /* DDR */
140 u32 dram_freq_mhz = ddr_freq_mhz / 2; /* SDR */
141 u32 mctl_freq_mhz = dram_freq_mhz / 2; /* HDR */
142 u32 dxodt, mdfscr, pwrctl, vtfcr;
143 u32 i, tREFI_32ck, tRFC_ck;
144 int ret;
145
146 /* The rate change is not effective until the MDFS process runs. */
147 ret = clk_set_rate(priv->clk_dram, freq);
148 if (ret)
149 return ret;
150
151 /* Disable automatic self-refesh and VTF before starting MDFS. */
152 pwrctl = readl_relaxed(priv->reg_dram + DRAM_PWRCTL) &
153 ~DRAM_PWRCTL_SELFREF_EN;
154 writel_relaxed(pwrctl, priv->reg_dram + DRAM_PWRCTL);
155 vtfcr = readl_relaxed(priv->reg_dram + DRAM_VTFCR);
156 writel_relaxed(vtfcr & ~DRAM_VTFCR_VTF_ENABLE,
157 priv->reg_dram + DRAM_VTFCR);
158
159 /* Set up MDFS and enable double buffering for timing registers. */
160 mdfscr = MBUS_MDFSCR_MODE_DFS |
161 MBUS_MDFSCR_BYPASS |
162 MBUS_MDFSCR_PAD_HOLD |
163 MBUS_MDFSCR_BUFFER_TIMING;
164 writel(mdfscr, priv->reg_mbus + MBUS_MDFSCR);
165
166 /* Update the buffered copy of RFSHTMG. */
167 tREFI_32ck = priv->tREFI_ns * mctl_freq_mhz / 1000 / 32;
168 tRFC_ck = DIV_ROUND_UP(priv->tRFC_ns * mctl_freq_mhz, 1000);
169 writel(DRAM_RFSHTMG_TREFI(tREFI_32ck) | DRAM_RFSHTMG_TRFC(tRFC_ck),
170 priv->reg_dram + DRAM_RFSHTMG);
171
172 /* Enable ODT if needed, or disable it to save power. */
173 if (priv->odtmap && dram_freq_mhz > priv->variant->odt_freq_mhz) {
174 dxodt = DRAM_DXnGCR0_DXODT_DYNAMIC;
175 writel(priv->odtmap, priv->reg_dram + DRAM_ODTMAP);
176 } else {
177 dxodt = DRAM_DXnGCR0_DXODT_DISABLED;
178 writel(0, priv->reg_dram + DRAM_ODTMAP);
179 }
180 for (i = 0; i < DRAM_DX_MAX; ++i) {
181 void __iomem *reg = priv->reg_dram + DRAM_DXnGCR0(i);
182
183 writel((readl(reg) & ~DRAM_DXnGCR0_DXODT) | dxodt, reg);
184 }
185
186 dev_dbg(priv->devfreq_dram->dev.parent,
187 "Setting DRAM to %u MHz, tREFI=%u, tRFC=%u, ODT=%s\n",
188 dram_freq_mhz, tREFI_32ck, tRFC_ck,
189 dxodt == DRAM_DXnGCR0_DXODT_DYNAMIC ? "dynamic" : "disabled");
190
191 /* Trigger hardware MDFS. */
192 writel(mdfscr | MBUS_MDFSCR_START, priv->reg_mbus + MBUS_MDFSCR);
193 ret = readl_poll_timeout_atomic(priv->reg_mbus + MBUS_MDFSCR, mdfscr,
194 !(mdfscr & MBUS_MDFSCR_START), 10, 1000);
195 if (ret)
196 return ret;
197
198 /* Disable double buffering. */
199 writel(0, priv->reg_mbus + MBUS_MDFSCR);
200
201 /* Restore VTF configuration. */
202 writel_relaxed(vtfcr, priv->reg_dram + DRAM_VTFCR);
203
204 /* Enable automatic self-refresh at the lowest frequency only. */
205 if (freq == priv->freq_table[0])
206 pwrctl |= DRAM_PWRCTL_SELFREF_EN;
207 writel_relaxed(pwrctl, priv->reg_dram + DRAM_PWRCTL);
208
209 sun8i_a33_mbus_restart_pmu_counters(priv);
210 sun8i_a33_mbus_update_nominal_bw(priv, ddr_freq_mhz);
211
212 return 0;
213}
214
215static int sun8i_a33_mbus_set_dram_target(struct device *dev,
216 unsigned long *freq, u32 flags)
217{
218 struct sun8i_a33_mbus *priv = dev_get_drvdata(dev);
219 struct devfreq *devfreq = priv->devfreq_dram;
220 struct dev_pm_opp *opp;
221 int ret;
222
223 opp = devfreq_recommended_opp(dev, freq, flags);
224 if (IS_ERR(opp))
225 return PTR_ERR(opp);
226
227 dev_pm_opp_put(opp);
228
229 if (*freq == devfreq->previous_freq)
230 return 0;
231
232 ret = sun8i_a33_mbus_set_dram_freq(priv, *freq);
233 if (ret) {
234 dev_warn(dev, "failed to set DRAM frequency: %d\n", ret);
235 *freq = devfreq->previous_freq;
236 }
237
238 return ret;
239}
240
241static int sun8i_a33_mbus_get_dram_status(struct device *dev,
242 struct devfreq_dev_status *stat)
243{
244 struct sun8i_a33_mbus *priv = dev_get_drvdata(dev);
245
246 stat->busy_time = sun8i_a33_mbus_get_peak_bw(priv);
247 stat->total_time = priv->nominal_bw;
248 stat->current_frequency = priv->devfreq_dram->previous_freq;
249
250 sun8i_a33_mbus_restart_pmu_counters(priv);
251
252 dev_dbg(dev, "Using %lu/%lu (%lu%%) at %lu MHz\n",
253 stat->busy_time, stat->total_time,
254 DIV_ROUND_CLOSEST(stat->busy_time * 100, stat->total_time),
255 stat->current_frequency / USEC_PER_SEC);
256
257 return 0;
258}
259
260static int sun8i_a33_mbus_hw_init(struct device *dev,
261 struct sun8i_a33_mbus *priv,
262 unsigned long ddr_freq)
263{
264 u32 i, mbus_cr, mbus_freq_mhz;
265
266 /* Choose tREFI and tRFC to match the configured DRAM type. */
267 mbus_cr = readl_relaxed(priv->reg_mbus + MBUS_CR);
268 switch (MBUS_CR_GET_DRAM_TYPE(mbus_cr)) {
269 case MBUS_CR_DRAM_TYPE_DDR2:
270 case MBUS_CR_DRAM_TYPE_DDR3:
271 case MBUS_CR_DRAM_TYPE_DDR4:
272 priv->tREFI_ns = 7800;
273 priv->tRFC_ns = 350;
274 break;
275 case MBUS_CR_DRAM_TYPE_LPDDR2:
276 case MBUS_CR_DRAM_TYPE_LPDDR3:
277 priv->tREFI_ns = 3900;
278 priv->tRFC_ns = 210;
279 break;
280 default:
281 return -EINVAL;
282 }
283
284 /* Save ODTMAP so it can be restored when raising the frequency. */
285 priv->odtmap = readl_relaxed(priv->reg_dram + DRAM_ODTMAP);
286
287 /* Compute the DRAM data bus width by counting enabled DATx8 blocks. */
288 for (i = 0; i < DRAM_DX_MAX; ++i) {
289 void __iomem *reg = priv->reg_dram + DRAM_DXnGCR0(i);
290
291 if (!(readl_relaxed(reg) & DRAM_DXnGCR0_DXEN))
292 break;
293 }
294 priv->data_width = i;
295
296 dev_dbg(dev, "Detected %u-bit %sDDRx with%s ODT\n",
297 priv->data_width * 8,
298 MBUS_CR_GET_DRAM_TYPE(mbus_cr) > 4 ? "LP" : "",
299 priv->odtmap ? "" : "out");
300
301 /* Program MBUS_TMR such that the PMU period unit is microseconds. */
302 mbus_freq_mhz = clk_get_rate(priv->clk_mbus) / USEC_PER_SEC;
303 writel_relaxed(MBUS_TMR_PERIOD(mbus_freq_mhz),
304 priv->reg_mbus + MBUS_TMR);
305
306 /* "Master Ready Mask Register" bits must be set or MDFS will block. */
307 writel_relaxed(0xffffffff, priv->reg_mbus + MBUS_MDFSMRMR);
308
309 sun8i_a33_mbus_restart_pmu_counters(priv);
310 sun8i_a33_mbus_update_nominal_bw(priv, ddr_freq / USEC_PER_SEC);
311
312 return 0;
313}
314
315static int __maybe_unused sun8i_a33_mbus_suspend(struct device *dev)
316{
317 struct sun8i_a33_mbus *priv = dev_get_drvdata(dev);
318
319 clk_disable_unprepare(priv->clk_bus);
320
321 return 0;
322}
323
324static int __maybe_unused sun8i_a33_mbus_resume(struct device *dev)
325{
326 struct sun8i_a33_mbus *priv = dev_get_drvdata(dev);
327
328 return clk_prepare_enable(priv->clk_bus);
329}
330
331static int sun8i_a33_mbus_probe(struct platform_device *pdev)
332{
333 const struct sun8i_a33_mbus_variant *variant;
334 struct device *dev = &pdev->dev;
335 struct sun8i_a33_mbus *priv;
336 unsigned long base_freq;
337 unsigned int max_state;
338 const char *err;
339 int i, ret;
340
341 variant = device_get_match_data(dev);
342 if (!variant)
343 return -EINVAL;
344
345 max_state = variant->max_dram_divider - variant->min_dram_divider + 1;
346
347 priv = devm_kzalloc(dev, struct_size(priv, freq_table, max_state), GFP_KERNEL);
348 if (!priv)
349 return -ENOMEM;
350
351 platform_set_drvdata(pdev, priv);
352
353 priv->variant = variant;
354
355 priv->reg_dram = devm_platform_ioremap_resource_byname(pdev, "dram");
356 if (IS_ERR(priv->reg_dram))
357 return PTR_ERR(priv->reg_dram);
358
359 priv->reg_mbus = devm_platform_ioremap_resource_byname(pdev, "mbus");
360 if (IS_ERR(priv->reg_mbus))
361 return PTR_ERR(priv->reg_mbus);
362
363 priv->clk_bus = devm_clk_get(dev, "bus");
364 if (IS_ERR(priv->clk_bus))
365 return dev_err_probe(dev, PTR_ERR(priv->clk_bus),
366 "failed to get bus clock\n");
367
368 priv->clk_dram = devm_clk_get(dev, "dram");
369 if (IS_ERR(priv->clk_dram))
370 return dev_err_probe(dev, PTR_ERR(priv->clk_dram),
371 "failed to get dram clock\n");
372
373 priv->clk_mbus = devm_clk_get(dev, "mbus");
374 if (IS_ERR(priv->clk_mbus))
375 return dev_err_probe(dev, PTR_ERR(priv->clk_mbus),
376 "failed to get mbus clock\n");
377
378 ret = clk_prepare_enable(priv->clk_bus);
379 if (ret)
380 return dev_err_probe(dev, ret,
381 "failed to enable bus clock\n");
382
383 /* Lock the DRAM clock rate to keep priv->nominal_bw in sync. */
384 ret = clk_rate_exclusive_get(priv->clk_dram);
385 if (ret) {
386 err = "failed to lock dram clock rate\n";
387 goto err_disable_bus;
388 }
389
390 /* Lock the MBUS clock rate to keep MBUS_TMR_PERIOD in sync. */
391 ret = clk_rate_exclusive_get(priv->clk_mbus);
392 if (ret) {
393 err = "failed to lock mbus clock rate\n";
394 goto err_unlock_dram;
395 }
396
397 priv->gov_data.upthreshold = 10;
398 priv->gov_data.downdifferential = 5;
399
400 priv->profile.initial_freq = clk_get_rate(priv->clk_dram);
401 priv->profile.polling_ms = 1000;
402 priv->profile.target = sun8i_a33_mbus_set_dram_target;
403 priv->profile.get_dev_status = sun8i_a33_mbus_get_dram_status;
404 priv->profile.freq_table = priv->freq_table;
405 priv->profile.max_state = max_state;
406
407 ret = devm_pm_opp_set_clkname(dev, "dram");
408 if (ret) {
409 err = "failed to add OPP table\n";
410 goto err_unlock_mbus;
411 }
412
413 base_freq = clk_get_rate(clk_get_parent(priv->clk_dram));
414 for (i = 0; i < max_state; ++i) {
415 unsigned int div = variant->max_dram_divider - i;
416
417 priv->freq_table[i] = base_freq / div;
418
419 ret = dev_pm_opp_add(dev, priv->freq_table[i], 0);
420 if (ret) {
421 err = "failed to add OPPs\n";
422 goto err_remove_opps;
423 }
424 }
425
426 ret = sun8i_a33_mbus_hw_init(dev, priv, priv->profile.initial_freq);
427 if (ret) {
428 err = "failed to init hardware\n";
429 goto err_remove_opps;
430 }
431
432 priv->devfreq_dram = devfreq_add_device(dev, &priv->profile,
433 DEVFREQ_GOV_SIMPLE_ONDEMAND,
434 &priv->gov_data);
435 if (IS_ERR(priv->devfreq_dram)) {
436 ret = PTR_ERR(priv->devfreq_dram);
437 err = "failed to add devfreq device\n";
438 goto err_remove_opps;
439 }
440
441 /*
442 * This must be set manually after registering the devfreq device,
443 * because there is no way to select a dynamic OPP as the suspend OPP.
444 */
445 priv->devfreq_dram->suspend_freq = priv->freq_table[0];
446
447 return 0;
448
449err_remove_opps:
450 dev_pm_opp_remove_all_dynamic(dev);
451err_unlock_mbus:
452 clk_rate_exclusive_put(priv->clk_mbus);
453err_unlock_dram:
454 clk_rate_exclusive_put(priv->clk_dram);
455err_disable_bus:
456 clk_disable_unprepare(priv->clk_bus);
457
458 return dev_err_probe(dev, ret, err);
459}
460
461static int sun8i_a33_mbus_remove(struct platform_device *pdev)
462{
463 struct sun8i_a33_mbus *priv = platform_get_drvdata(pdev);
464 unsigned long initial_freq = priv->profile.initial_freq;
465 struct device *dev = &pdev->dev;
466 int ret;
467
468 devfreq_remove_device(priv->devfreq_dram);
469
470 ret = sun8i_a33_mbus_set_dram_freq(priv, initial_freq);
471 if (ret)
472 dev_warn(dev, "failed to restore DRAM frequency: %d\n", ret);
473
474 dev_pm_opp_remove_all_dynamic(dev);
475 clk_rate_exclusive_put(priv->clk_mbus);
476 clk_rate_exclusive_put(priv->clk_dram);
477 clk_disable_unprepare(priv->clk_bus);
478
479 return 0;
480}
481
482static const struct sun8i_a33_mbus_variant sun50i_a64_mbus = {
483 .min_dram_divider = 1,
484 .max_dram_divider = 4,
485 .odt_freq_mhz = 400,
486};
487
488static const struct of_device_id sun8i_a33_mbus_of_match[] = {
489 { .compatible = "allwinner,sun50i-a64-mbus", .data = &sun50i_a64_mbus },
490 { .compatible = "allwinner,sun50i-h5-mbus", .data = &sun50i_a64_mbus },
491 { },
492};
493MODULE_DEVICE_TABLE(of, sun8i_a33_mbus_of_match);
494
495static SIMPLE_DEV_PM_OPS(sun8i_a33_mbus_pm_ops,
496 sun8i_a33_mbus_suspend, sun8i_a33_mbus_resume);
497
498static struct platform_driver sun8i_a33_mbus_driver = {
499 .probe = sun8i_a33_mbus_probe,
500 .remove = sun8i_a33_mbus_remove,
501 .driver = {
502 .name = "sun8i-a33-mbus",
503 .of_match_table = sun8i_a33_mbus_of_match,
504 .pm = pm_ptr(&sun8i_a33_mbus_pm_ops),
505 },
506};
507module_platform_driver(sun8i_a33_mbus_driver);
508
509MODULE_AUTHOR("Samuel Holland <samuel@sholland.org>");
510MODULE_DESCRIPTION("Allwinner sun8i/sun50i MBUS DEVFREQ Driver");
511MODULE_LICENSE("GPL v2");
drivers/powercap/dtpm.c+3−3
@@ -382,7 +382,7 @@ void dtpm_unregister(struct dtpm *dtpm) · 381 unmodified lines
382{382{
383 powercap_unregister_zone(pct, &dtpm->zone);383 powercap_unregister_zone(pct, &dtpm->zone);
384 384
385 pr_info("Unregistered dtpm node '%s'\n", dtpm->zone.name);385 pr_debug("Unregistered dtpm node '%s'\n", dtpm->zone.name);
386}386}
387 387
388/**388/**
@@ -453,8 +453,8 @@ int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent) · 64 unmodified lines
453 dtpm->power_limit = dtpm->power_max;453 dtpm->power_limit = dtpm->power_max;
454 }454 }
455 455
456 pr_info("Registered dtpm node '%s' / %llu-%llu uW, \n",456 pr_debug("Registered dtpm node '%s' / %llu-%llu uW, \n",
457 dtpm->zone.name, dtpm->power_min, dtpm->power_max);457 dtpm->zone.name, dtpm->power_min, dtpm->power_max);
458 458
459 mutex_unlock(&dtpm_lock);459 mutex_unlock(&dtpm_lock);
460 460
drivers/powercap/idle_inject.c+1−1
@@ -12,7 +12,7 @@ · 11 unmodified lines
12 *12 *
13 * All of the kthreads used for idle injection are created at init time.13 * All of the kthreads used for idle injection are created at init time.
14 *14 *
15 * Next, the users of the the idle injection framework provide a cpumask via15 * Next, the users of the idle injection framework provide a cpumask via
16 * its register function. The kthreads will be synchronized with respect to16 * its register function. The kthreads will be synchronized with respect to
17 * this cpumask.17 * this cpumask.
18 *18 *
drivers/powercap/intel_rapl_common.c+59−2
@@ -61,6 +61,20 @@ · 60 unmodified lines
61#define PERF_STATUS_THROTTLE_TIME_MASK 0xffffffff61#define PERF_STATUS_THROTTLE_TIME_MASK 0xffffffff
62#define PP_POLICY_MASK 0x1F62#define PP_POLICY_MASK 0x1F
63 63
64/*
65 * SPR has different layout for Psys Domain PowerLimit registers.
66 * There are 17 bits of PL1 and PL2 instead of 15 bits.
67 * The Enable bits and TimeWindow bits are also shifted as a result.
68 */
69#define PSYS_POWER_LIMIT1_MASK 0x1FFFF
70#define PSYS_POWER_LIMIT1_ENABLE BIT(17)
71
72#define PSYS_POWER_LIMIT2_MASK (0x1FFFFULL<<32)
73#define PSYS_POWER_LIMIT2_ENABLE BIT_ULL(49)
74
75#define PSYS_TIME_WINDOW1_MASK (0x7FULL<<19)
76#define PSYS_TIME_WINDOW2_MASK (0x7FULL<<51)
77
64/* Non HW constants */78/* Non HW constants */
65#define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */79#define RAPL_PRIMITIVE_DERIVED BIT(1) /* not from raw data */
66#define RAPL_PRIMITIVE_DUMMY BIT(2)80#define RAPL_PRIMITIVE_DUMMY BIT(2)
@@ -97,6 +111,7 @@ struct rapl_defaults { · 30 unmodified lines
97 bool to_raw);111 bool to_raw);
98 unsigned int dram_domain_energy_unit;112 unsigned int dram_domain_energy_unit;
99 unsigned int psys_domain_energy_unit;113 unsigned int psys_domain_energy_unit;
114 bool spr_psys_bits;
100};115};
101static struct rapl_defaults *rapl_defaults;116static struct rapl_defaults *rapl_defaults;
102 117
@@ -669,12 +684,51 @@ static struct rapl_primitive_info rpi[] = { · 566 unmodified lines
669 RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),684 RAPL_DOMAIN_REG_PERF, TIME_UNIT, 0),
670 PRIMITIVE_INFO_INIT(PRIORITY_LEVEL, PP_POLICY_MASK, 0,685 PRIMITIVE_INFO_INIT(PRIORITY_LEVEL, PP_POLICY_MASK, 0,
671 RAPL_DOMAIN_REG_POLICY, ARBITRARY_UNIT, 0),686 RAPL_DOMAIN_REG_POLICY, ARBITRARY_UNIT, 0),
687 PRIMITIVE_INFO_INIT(PSYS_POWER_LIMIT1, PSYS_POWER_LIMIT1_MASK, 0,
688 RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
689 PRIMITIVE_INFO_INIT(PSYS_POWER_LIMIT2, PSYS_POWER_LIMIT2_MASK, 32,
690 RAPL_DOMAIN_REG_LIMIT, POWER_UNIT, 0),
691 PRIMITIVE_INFO_INIT(PSYS_PL1_ENABLE, PSYS_POWER_LIMIT1_ENABLE, 17,
692 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
693 PRIMITIVE_INFO_INIT(PSYS_PL2_ENABLE, PSYS_POWER_LIMIT2_ENABLE, 49,
694 RAPL_DOMAIN_REG_LIMIT, ARBITRARY_UNIT, 0),
695 PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW1, PSYS_TIME_WINDOW1_MASK, 19,
696 RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
697 PRIMITIVE_INFO_INIT(PSYS_TIME_WINDOW2, PSYS_TIME_WINDOW2_MASK, 51,
698 RAPL_DOMAIN_REG_LIMIT, TIME_UNIT, 0),
672 /* non-hardware */699 /* non-hardware */
673 PRIMITIVE_INFO_INIT(AVERAGE_POWER, 0, 0, 0, POWER_UNIT,700 PRIMITIVE_INFO_INIT(AVERAGE_POWER, 0, 0, 0, POWER_UNIT,
674 RAPL_PRIMITIVE_DERIVED),701 RAPL_PRIMITIVE_DERIVED),
675 {NULL, 0, 0, 0},702 {NULL, 0, 0, 0},
676};703};
677 704
705static enum rapl_primitives
706prim_fixups(struct rapl_domain *rd, enum rapl_primitives prim)
707{
708 if (!rapl_defaults->spr_psys_bits)
709 return prim;
710
711 if (rd->id != RAPL_DOMAIN_PLATFORM)
712 return prim;
713
714 switch (prim) {
715 case POWER_LIMIT1:
716 return PSYS_POWER_LIMIT1;
717 case POWER_LIMIT2:
718 return PSYS_POWER_LIMIT2;
719 case PL1_ENABLE:
720 return PSYS_PL1_ENABLE;
721 case PL2_ENABLE:
722 return PSYS_PL2_ENABLE;
723 case TIME_WINDOW1:
724 return PSYS_TIME_WINDOW1;
725 case TIME_WINDOW2:
726 return PSYS_TIME_WINDOW2;
727 default:
728 return prim;
729 }
730}
731
678/* Read primitive data based on its related struct rapl_primitive_info.732/* Read primitive data based on its related struct rapl_primitive_info.
679 * if xlate flag is set, return translated data based on data units, i.e.733 * if xlate flag is set, return translated data based on data units, i.e.
680 * time, energy, and power.734 * time, energy, and power.
@@ -692,7 +746,8 @@ static int rapl_read_data_raw(struct rapl_domain *rd, · 11 unmodified lines
692 enum rapl_primitives prim, bool xlate, u64 *data)746 enum rapl_primitives prim, bool xlate, u64 *data)
693{747{
694 u64 value;748 u64 value;
695 struct rapl_primitive_info *rp = &rpi[prim];749 enum rapl_primitives prim_fixed = prim_fixups(rd, prim);
750 struct rapl_primitive_info *rp = &rpi[prim_fixed];
696 struct reg_action ra;751 struct reg_action ra;
697 int cpu;752 int cpu;
698 753
@@ -738,7 +793,8 @@ static int rapl_write_data_raw(struct rapl_domain *rd, · 39 unmodified lines
738 enum rapl_primitives prim,793 enum rapl_primitives prim,
739 unsigned long long value)794 unsigned long long value)
740{795{
741 struct rapl_primitive_info *rp = &rpi[prim];796 enum rapl_primitives prim_fixed = prim_fixups(rd, prim);
797 struct rapl_primitive_info *rp = &rpi[prim_fixed];
742 int cpu;798 int cpu;
743 u64 bits;799 u64 bits;
744 struct reg_action ra;800 struct reg_action ra;
@@ -981,6 +1037,7 @@ static const struct rapl_defaults rapl_defaults_spr_server = { · 236 unmodified lines
981 .compute_time_window = rapl_compute_time_window_core,1037 .compute_time_window = rapl_compute_time_window_core,
982 .dram_domain_energy_unit = 15300,1038 .dram_domain_energy_unit = 15300,
983 .psys_domain_energy_unit = 1000000000,1039 .psys_domain_energy_unit = 1000000000,
1040 .spr_psys_bits = true,
984};1041};
985 1042
986static const struct rapl_defaults rapl_defaults_byt = {1043static const struct rapl_defaults rapl_defaults_byt = {
include/linux/dtpm.h+0−2
@@ -70,6 +70,4 @@ void dtpm_unregister(struct dtpm *dtpm); · 69 unmodified lines
70 70
71int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent);71int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent);
72 72
73int dtpm_register_cpu(struct dtpm *parent);
74
75#endif73#endif
include/linux/intel_rapl.h+6−0
@@ -58,6 +58,12 @@ enum rapl_primitives { · 57 unmodified lines
58 THROTTLED_TIME,58 THROTTLED_TIME,
59 PRIORITY_LEVEL,59 PRIORITY_LEVEL,
60 60
61 PSYS_POWER_LIMIT1,
62 PSYS_POWER_LIMIT2,
63 PSYS_PL1_ENABLE,
64 PSYS_PL2_ENABLE,
65 PSYS_TIME_WINDOW1,
66 PSYS_TIME_WINDOW2,
61 /* below are not raw primitive data */67 /* below are not raw primitive data */
62 AVERAGE_POWER,68 AVERAGE_POWER,
63 NR_RAPL_PRIMITIVES,69 NR_RAPL_PRIMITIVES,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t