rk3399 support ddr frequency scaling
Subsystems (8)
v2 cover rk3399 support ddr frequency scaling
rk3399 platform have dfi controller can monitor ddr load, and dcf controller to handle ddr register so we can get the right ddr frequency and make ddr controller happy work(which will implement in bl31). So we do ddr frequency scaling with following flow:
kernel bl31 monitor ddr load | | get_target_rate | | pass rate to bl31 clk_set_rate(ddr) --------------------->run dcf flow | | | | wait dcf interrupt<-------------------trigger dcf interrupt | | return
Lin Huang (6):
clk: rockchip: add new clock-type for the ddrclk
clk: rockchip: rk3399: add SCLK_DDRCLK ID for ddrc
clk: rockchip: rk3399: add ddrc clock support
PM / devfreq: event: support rockchip dfi controller PM / devfreq: rockchip: add devfreq driver for rk3399 dmc drm/rockchip: Add dmc notifier in vop driver
drivers/clk/rockchip/Makefile | 1 + drivers/clk/rockchip/clk-ddr.c | 145 ++++++++++++ drivers/clk/rockchip/clk-rk3399.c | 18 ++ drivers/clk/rockchip/clk.c | 9 + drivers/clk/rockchip/clk.h | 27 +++ drivers/devfreq/Kconfig | 1 + drivers/devfreq/Makefile | 1 + drivers/devfreq/event/Kconfig | 7 + drivers/devfreq/event/Makefile | 1 + drivers/devfreq/event/rockchip-dfi.c | 253 +++++++++++++++++++++ drivers/devfreq/rockchip/Kconfig | 15 ++ drivers/devfreq/rockchip/Makefile | 2 + drivers/devfreq/rockchip/rk3399_dmc.c | 337 ++++++++++++++++++++++++++++ drivers/devfreq/rockchip/rockchip_dmc.c | 143 ++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 43 +++- include/dt-bindings/clock/rk3399-cru.h | 1 + include/soc/rockchip/rockchip_dmc.h | 45 ++++ 17 files changed, 1047 insertions(+), 2 deletions(-) create mode 100644 drivers/clk/rockchip/clk-ddr.c create mode 100644 drivers/devfreq/event/rockchip-dfi.c create mode 100644 drivers/devfreq/rockchip/Kconfig create mode 100644 drivers/devfreq/rockchip/Makefile create mode 100644 drivers/devfreq/rockchip/rk3399_dmc.c create mode 100644 drivers/devfreq/rockchip/rockchip_dmc.c create mode 100644 include/soc/rockchip/rockchip_dmc.h
Signature · 1 line
1.9.1
RFC PATCH v2 1/6 clk: rockchip: add new clock-type for the ddrclk
On new rockchip platform(rk3399 etc), there have dcf controller to do ddr frequency scaling, and this controller will implement in arm-trust-firmware. We add a special clock-type to handle that.
---
Changes in v2:
- use GENMASK instead val_mask
- use divider_recalc_rate() instead DIV_ROUND_UP_ULL
- cleanup code
Changes in v1:
- None
drivers/clk/rockchip/Makefile | 1 + drivers/clk/rockchip/clk-ddr.c | 145 +++++++++++++++++++++++++++++++++++++++++ drivers/clk/rockchip/clk.c | 9 +++ drivers/clk/rockchip/clk.h | 27 ++++++++ 4 files changed, 182 insertions(+) create mode 100644 drivers/clk/rockchip/clk-ddr.c
drivers/clk/rockchip/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-y += clk-pll.o obj-y += clk-cpu.o obj-y += clk-inverter.o obj-y += clk-mmc-phase.o +obj-y += clk-ddr.o obj-$(CONFIG_RESET_CONTROLLER) += softrst.o obj-y += clk-rk3036.o
drivers/clk/rockchip/clk-ddr.c new file +145 -0
145 lines not on this page · raw message
drivers/clk/rockchip/clk.c +9 -0
@@ -484,6 +484,15 @@ void __init rockchip_clk_register_branches( list->gate_offset, list->gate_shift, list->gate_flags, flags, &ctx->lock);break ; +case branch_ddrc: + clk =rockchip_clk_register_ddrclk ( + list->name, list->flags, + list->parent_names, list->num_parents, + list->muxdiv_offset, list->mux_shift, + list->mux_width, list->mux_flags, + list->div_shift, list->div_width, + list->div_flags, ctx->reg_base, &ctx->lock); +break ; }/* none of the cases above matched */
drivers/clk/rockchip/clk.h +27 -0
@@ -281,6 +281,13 @@ struct clk *rockchip_clk_register_mmc(const char *name, const char *const *parent_names, u8 num_parents, void __iomem *reg, int shift); +struct clk *rockchip_clk_register_ddrclk (const char *name,int flags, +const char *const *parent_names,u8 num_parents, +int mux_offset,int mux_shift,int mux_width, +int mux_flag,int div_shift,int div_width, +int div_flag,void __iomem *reg_base, +spinlock_t *lock); +#define ROCKCHIP_INVERTER_HIWORD_MASK BIT(0) struct clk *rockchip_clk_register_inverter(const char *name,
@@ -299,6 +306,7 @@ enum rockchip_clk_branch_type { branch_mmc, branch_inverter, branch_factor, + branch_ddrc, }; struct rockchip_clk_branch {
@@ -488,6 +496,25 @@ struct rockchip_clk_branch { .child = ch, \ } +#define COMPOSITE_DDRC (_id, cname, pnames, f, mo, ms, mw, mf, \ + ds, dw, df) \ + { \ + .id = _id, \ + .branch_type = branch_ddrc, \ + .name = cname, \ + .parent_names = pnames, \ + .num_parents = ARRAY_SIZE(pnames), \ + .flags = f, \ + .muxdiv_offset = mo, \ + .mux_shift = ms, \ + .mux_width = mw, \ + .mux_flags = mf, \ + .div_shift = ds, \ + .div_width = dw, \ + .div_flags = df, \ + .gate_offset = -1, \ + } +#define MUX (_id, cname, pnames, f, o, s, w, mf) \ { \ .id = _id, \
Signature · 1 line
1.9.1
RFC PATCH v2 2/6 clk: rockchip: rk3399: add SCLK_DDRCLK ID for ddrc
In reply to Lin Huang---
Changes in v2:
- None
Changes in v1:
- None
include/dt-bindings/clock/rk3399-cru.h | 1 + 1 file changed, 1 insertion(+)
include/dt-bindings/clock/rk3399-cru.h +1 -0
@@ -131,6 +131,7 @@#define SCLK_DPHY_RX0_CFG 165#define SCLK_RMII_SRC 166#define SCLK_PCIEPHY_REF100M 167 +#define SCLK_DDRCLK 168#define DCLK_VOP0 180#define DCLK_VOP1 181
Signature · 1 line
1.9.1
RFC PATCH v2 3/6 clk: rockchip: rk3399: add ddrc clock support
In reply to Lin Huangadd ddrc clock setting, so we can do ddr frequency scaling on rk3399 platform in future.
---
Changes in v2:
- remove clk_ddrc_dpll_src from critical clock list
Changes in v1:
- remove ddrc source CLK_IGNORE_UNUSED flag
- move clk_ddrc and clk_ddrc_dpll_src to critical
drivers/clk/rockchip/clk-rk3399.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/clk/rockchip/clk-rk3399.c +17 -0
@@ -118,6 +118,10 @@ PNAME(mux_armclkb_p) = { "clk_core_b_lpll_src","clk_core_b_bpll_src" ,"clk_core_b_dpll_src" , "clk_core_b_gpll_src" }; +PNAME (mux_ddrclk_p) = {"clk_ddrc_lpll_src" , +"clk_ddrc_bpll_src" , +"clk_ddrc_dpll_src" , +"clk_ddrc_gpll_src" };PNAME (mux_aclk_cci_p) = {"cpll_aclk_cci_src" ,"gpll_aclk_cci_src" , "npll_aclk_cci_src",
@@ -1377,6 +1381,18 @@ static struct rockchip_clk_branch rk3399_clk_branches[] __initdata = {COMPOSITE_NOMUX (0 ,"clk_test" ,"clk_test_pre" ,CLK_IGNORE_UNUSED ,RK3368_CLKSEL_CON (58 ),0 ,5 ,DFLAGS ,RK3368_CLKGATE_CON (13 ),11 ,GFLAGS ), + +/* ddrc */ +GATE (0 ,"clk_ddrc_lpll_src" ,"lpll" ,0 ,RK3399_CLKGATE_CON (3 ), +0 ,GFLAGS ), +GATE (0 ,"clk_ddrc_bpll_src" ,"bpll" ,0 ,RK3399_CLKGATE_CON (3 ), +1 ,GFLAGS ), +GATE (0 ,"clk_ddrc_dpll_src" ,"dpll" ,0 ,RK3399_CLKGATE_CON (3 ), +2 ,GFLAGS ), +GATE (0 ,"clk_ddrc_gpll_src" ,"gpll" ,0 ,RK3399_CLKGATE_CON (3 ), +3 ,GFLAGS ), +COMPOSITE_DDRC (SCLK_DDRCLK ,"clk_ddrc" , mux_ddrclk_p,0 , + RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 3, DFLAGS), }; static struct rockchip_clk_branch rk3399_clk_pmu_branches[] __initdata = {
@@ -1487,6 +1503,8 @@ static const char *const rk3399_cru_critical_clocks[] __initconst = {"gpll_hclk_perilp1_src" ,"gpll_aclk_perilp0_src" ,"gpll_aclk_perihp_src" , + "clk_ddrc", }; static const char *const rk3399_pmucru_critical_clocks[] __initconst = {
Signature · 1 line
1.9.1
RFC PATCH v2 4/6 PM / devfreq: event: support rockchip dfi controller
In reply to Lin Huangon rk3399 platform, there is dfi conroller can monitor ddr load, base on this result, we can do ddr freqency scaling.
---
Changes in v2:
- use clk_disable_unprepare and clk_enable_prepare
- remove clk_enable_prepare in probe
- remove rockchip_dfi_remove function
Changes in v1:
- None
drivers/devfreq/event/Kconfig | 7 + drivers/devfreq/event/Makefile | 1 + drivers/devfreq/event/rockchip-dfi.c | 253 +++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 drivers/devfreq/event/rockchip-dfi.c
drivers/devfreq/event/Kconfig +7 -0
@@ -30,4 +30,11 @@ config DEVFREQ_EVENT_EXYNOS_PPMU (Platform Performance Monitoring Unit) counters to estimate the utilization of each module. +config DEVFREQ_EVENT_ROCKCHIP_DFI + bool "ROCKCHIP DFI DEVFREQ event Driver" + depends on ARCH_ROCKCHIP + help + This add the devfreq-event driver for Rockchip SoC. It provides DFI + (DDR Monitor Module) driver to count ddr load. + endif # PM_DEVFREQ_EVENT
drivers/devfreq/event/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_DEVFREQ_EVENT_EXYNOS_NOCP) += exynos-nocp.o obj-$(CONFIG_DEVFREQ_EVENT_EXYNOS_PPMU) += exynos-ppmu.o +obj-$(CONFIG_DEVFREQ_EVENT_ROCKCHIP_DFI) += rockchip-dfi.o
drivers/devfreq/event/rockchip-dfi.c new file +253 -0
253 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH v2 5/6 PM / devfreq: rockchip: add devfreq driver for rk3399 dmc
In reply to Lin Huangbase on dfi result, we do ddr frequency scaling, register dmc driver to devfreq framework, and use simple-ondemand policy.
---
Changes in v2:
- None
Changes in v1:
- move dfi controller to event
- fix set voltage sequence when set rate fail
- change Kconfig type from tristate to bool
- move unuse EXPORT_SYMBOL_GPL()
drivers/devfreq/Kconfig | 1 + drivers/devfreq/Makefile | 1 + drivers/devfreq/rockchip/Kconfig | 15 ++ drivers/devfreq/rockchip/Makefile | 2 + drivers/devfreq/rockchip/rk3399_dmc.c | 337 ++++++++++++++++++++++++++++++++ drivers/devfreq/rockchip/rockchip_dmc.c | 143 ++++++++++++++ include/soc/rockchip/rockchip_dmc.h | 45 +++++ 7 files changed, 544 insertions(+) create mode 100644 drivers/devfreq/rockchip/Kconfig create mode 100644 drivers/devfreq/rockchip/Makefile create mode 100644 drivers/devfreq/rockchip/rk3399_dmc.c create mode 100644 drivers/devfreq/rockchip/rockchip_dmc.c create mode 100644 include/soc/rockchip/rockchip_dmc.h
drivers/devfreq/Kconfig +1 -0
@@ -101,5 +101,6 @@ config ARM_TEGRA_DEVFREQ operating frequencies and voltages with OPP support. source "drivers/devfreq/event/Kconfig" +source "drivers/devfreq/rockchip/Kconfig" endif # PM_DEVFREQ
drivers/devfreq/Makefile +1 -0
@@ -9,6 +9,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o # DEVFREQ Drivers obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra-devfreq.o +obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ # DEVFREQ Event Drivers obj-$(CONFIG_PM_DEVFREQ_EVENT) += event/
drivers/devfreq/rockchip/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +config ARM_ROCKCHIP_DMC_DEVFREQ + bool "ARM ROCKCHIP DMC DEVFREQ Driver" + depends on ARCH_ROCKCHIP + help + This adds the DEVFREQ driver framework for the rockchip dmc. + +config ARM_RK3399_DMC_DEVFREQ + bool "ARM RK3399 DMC DEVFREQ Driver" + depends on ARM_ROCKCHIP_DMC_DEVFREQ + select PM_OPP + select DEVFREQ_GOV_SIMPLE_ONDEMAND + help + This adds the DEVFREQ driver for the RK3399 dmc. It sets the frequency + for the memory controller and reads the usage counts from hardware. +
drivers/devfreq/rockchip/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_ARM_ROCKCHIP_DMC_DEVFREQ) += rockchip_dmc.o +obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o
drivers/devfreq/rockchip/rk3399_dmc.c new file +337 -0
337 lines not on this page · raw message
drivers/devfreq/rockchip/rockchip_dmc.c new file +143 -0
143 lines not on this page · raw message
include/soc/rockchip/rockchip_dmc.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH v2 6/6 drm/rockchip: Add dmc notifier in vop driver
In reply to Lin Huangwhen in ddr frequency scaling process, vop can not do enable or disable operate, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled. So need register to dmc notifier, and we can get the dmc status.
---
Changes in v2:
- None
Changes in v1:
- use wait_event instead usleep
drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +41 -2
@@ -31,6 +31,8 @@#include <linux/reset.h> #include <linux/delay.h> +#include <soc/rockchip/rockchip_dmc.h> +#include "rockchip_drm_drv.h" #include "rockchip_drm_gem.h" #include "rockchip_drm_fb.h"
@@ -116,6 +118,10 @@ struct vop {const struct vop_data *data; +struct notifier_block dmc_nb; +int dmc_in_process; +wait_queue_head_t wait_dmc_queue; +uint32_t *regsbak;void __iomem *regs;
@@ -426,6 +432,21 @@ static void vop_dsp_hold_valid_irq_disable(struct vop *vop)spin_unlock_irqrestore (&vop->irq_lock, flags); } +static int dmc_notify (struct notifier_block *nb,unsigned long event, +void *data) +{ + struct vop *vop = container_of(nb, struct vop, dmc_nb); + +if (event ==DMCFREQ_ADJUST ) { + vop->dmc_in_process =1 ; + }else if (event ==DMCFREQ_FINISH ) { + vop->dmc_in_process =0 ; +wake_up (&vop->wait_dmc_queue); + } + +return NOTIFY_OK ; +} +static void vop_enable (struct drm_crtc *crtc) {struct vop *vop =to_vop (crtc);
@@ -434,6 +455,13 @@ static void vop_enable(struct drm_crtc *crtc)if (vop->is_enabled)return ; +/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + ret =pm_runtime_get_sync (vop->dev);if (ret <0 ) {dev_err (vop->dev,"failed to get pm runtime: %d\n" , ret);
@@ -485,6 +513,7 @@ static void vop_enable(struct drm_crtc *crtc)enable_irq (vop->irq);drm_crtc_vblank_on (crtc); +rockchip_dmc_get (&vop->dmc_nb);return ;
@@ -505,6 +534,13 @@ static void vop_crtc_disable(struct drm_crtc *crtc)return ;/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + +/* * We need to make sure that all windows are disabled before we * disable that crtc. Otherwise we might try to scan from a destroyed * buffer later.
@@ -517,7 +553,7 @@ static void vop_crtc_disable(struct drm_crtc *crtc)VOP_WIN_SET (vop, win, enable,0 );spin_unlock (&vop->reg_lock); } - +rockchip_dmc_put (&vop->dmc_nb);drm_crtc_vblank_off (crtc);/*
@@ -1243,7 +1279,7 @@ static int vop_create_crtc(struct vop *vop) ret = -ENOENT ; goto err_cleanup_crtc; } - + vop->dmc_nb.notifier_call = dmc_notify;init_completion (&vop->dsp_hold_completion);init_completion (&vop->wait_update_complete); crtc->port = port;
@@ -1465,6 +1501,9 @@ static int vop_bind(struct device *dev, struct device *master, void *data)/* IRQ is initially disabled; it gets enabled in power_on */ disable_irq (vop->irq); +init_waitqueue_head (&vop->wait_dmc_queue); + vop->dmc_in_process =0 ; + ret =vop_create_crtc (vop);if (ret)return ret;
Signature · 1 line
1.9.1
Re: [RFC PATCH v2 4/6] PM / devfreq: event: support rockchip dfi controller
In reply to Lin HuangQuoted 3 lines · Lin Huang
on rk3399 platform, there is dfi conroller can monitor ddr load, base on this result, we can do ddr freqency scaling.
Hi Lin,
isn't the DDRMON in this SoC capable of raising interrupts when the programmed utilization thresholds have been trespassed?
If so, then I think it would be more appropriate to do it similarly to tegra-devfreq, instead of using devfreq-event and polling the hardware at given intervals.
Regards,
Tomeu
Quoted 305 lines
Signed-off-by Lin Huang <[email protected]>Acked-by Chanwoo Choi <[email protected]>---
Changes in v2:
- useclk_disable_unprepareandclk_enable_prepare
- removeclk_enable_preparein probe
- removerockchip_dfi_removefunctionChanges in v1:
- Nonedrivers/devfreq/event/Kconfig | 7 + drivers/devfreq/event/Makefile | 1 + drivers/devfreq/event/rockchip-dfi.c | 253 +++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 drivers/devfreq/event/rockchip-dfi.cdrivers/devfreq/event/Kconfig +7
-0@@ -30,4 +30,11 @@ config DEVFREQ_EVENT_EXYNOS_PPMU (Platform Performance Monitoring Unit) counters to estimate the utilization of each module. +config DEVFREQ_EVENT_ROCKCHIP_DFI + bool "ROCKCHIP DFI DEVFREQ event Driver" + depends on ARCH_ROCKCHIP + help + This add the devfreq-event driver for Rockchip SoC. It provides DFI + (DDR Monitor Module) driver to count ddr load. + endif # PM_DEVFREQ_EVENTdrivers/devfreq/event/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_DEVFREQ_EVENT_EXYNOS_NOCP) += exynos-nocp.o obj-$(CONFIG_DEVFREQ_EVENT_EXYNOS_PPMU) += exynos-ppmu.o +obj-$(CONFIG_DEVFREQ_EVENT_ROCKCHIP_DFI) += rockchip-dfi.odrivers/devfreq/event/rockchip-dfi.c new file +253
-1@@ -0,0 +1,253 @@ +/* +* Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd +* Author: Lin Huang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ + +#include <linux/clk.h> +#include <linux/devfreq-event.h> +#include <linux/kernel.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/mfd/syscon.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/slab.h> +#include <linux/list.h> +#include <linux/of.h> + +#define RK3399_DMC_NUM_CH 2 + +/* DDRMON_CTRL */ +#define DDRMON_CTRL 0x04 +#define CLR_DDRMON_CTRL (0x1f0000 << 0) +#define LPDDR4_EN (0x10001 << 4) +#define HARDWARE_EN (0x10001 << 3) +#define LPDDR3_EN (0x10001 << 2) +#define SOFTWARE_EN (0x10001 << 1) +#define TIME_CNT_EN (0x10001 << 0) + +#define DDRMON_CH0_COUNT_NUM 0x28 +#define DDRMON_CH0_DFI_ACCESS_NUM 0x2c +#define DDRMON_CH1_COUNT_NUM 0x3c +#define DDRMON_CH1_DFI_ACCESS_NUM 0x40 + +/* pmu grf */ +#define PMUGRF_OS_REG2 0x308 +#define DDRTYPE_SHIFT 13 +#define DDRTYPE_MASK 7 + +enum { +DDR3 =3 , +LPDDR3 =6 , +LPDDR4 =7 , +UNUSED =0xFF +}; + +struct dmc_usage { +u32 access; +u32 total; +}; + +struct rockchip_dfi { +struct devfreq_event_dev *edev; +struct devfreq_event_desc *desc; +struct dmc_usage ch_usage[RK3399_DMC_NUM_CH ]; +struct device *dev; +void __iomem *regs; +struct regmap *regmap_pmu; +struct clk *clk; +}; + +static void rockchip_dfi_start_hardware_counter (struct devfreq_event_dev *edev) +{ +struct rockchip_dfi *info =devfreq_event_get_drvdata (edev); +void __iomem *dfi_regs = info->regs; +u32 val; +u32 ddr_type; + +/* get ddr type */ +regmap_read (info->regmap_pmu,PMUGRF_OS_REG2 , &val); + ddr_type = (val >>DDRTYPE_SHIFT ) &DDRTYPE_MASK ; + +/* clear DDRMON_CTRL setting */ +writel_relaxed (CLR_DDRMON_CTRL , dfi_regs +DDRMON_CTRL ); + +/* set ddr type to dfi */ +if (ddr_type ==LPDDR3 ) +writel_relaxed (LPDDR3_EN , dfi_regs +DDRMON_CTRL ); +else if (ddr_type ==LPDDR4 ) +writel_relaxed (LPDDR4_EN , dfi_regs +DDRMON_CTRL ); + +/* enable count, use software mode */ +writel_relaxed (SOFTWARE_EN , dfi_regs +DDRMON_CTRL ); +} + +static void rockchip_dfi_stop_hardware_counter (struct devfreq_event_dev *edev) +{ +struct rockchip_dfi *info =devfreq_event_get_drvdata (edev); +void __iomem *dfi_regs = info->regs; +u32 val; + + val =readl_relaxed (dfi_regs +DDRMON_CTRL ); + val &= ~SOFTWARE_EN ; +writel_relaxed (val, dfi_regs +DDRMON_CTRL ); +} + +static int rockchip_dfi_get_busier_ch (struct devfreq_event_dev *edev) +{ +struct rockchip_dfi *info =devfreq_event_get_drvdata (edev); +u32 tmp, max =0 ; +u32 i, busier_ch =0 ; +void __iomem *dfi_regs = info->regs; + +rockchip_dfi_stop_hardware_counter (edev); + +/* Find out which channel is busier */ +for (i =0 ; i <RK3399_DMC_NUM_CH ; i++) { + info->ch_usage[i].access =readl_relaxed (dfi_regs + +DDRMON_CH0_DFI_ACCESS_NUM + i *20 ); + info->ch_usage[i].total =readl_relaxed (dfi_regs + +DDRMON_CH0_COUNT_NUM + i *20 ); + tmp = info->ch_usage[i].access; +if (tmp > max) { + busier_ch = i; + max = tmp; + } + } +rockchip_dfi_start_hardware_counter (edev); + +return busier_ch; +} + +static int rockchip_dfi_disable (struct devfreq_event_dev *edev) +{ +struct rockchip_dfi *info =devfreq_event_get_drvdata (edev); + +rockchip_dfi_stop_hardware_counter (edev); +clk_disable_unprepare (info->clk); + +return 0 ; +} + +static int rockchip_dfi_enable (struct devfreq_event_dev *edev) +{ +struct rockchip_dfi *info =devfreq_event_get_drvdata (edev); +int ret; + + ret =clk_prepare_enable (info->clk); +if (ret) { +dev_err (&edev->dev,"failed to enable dfi clk: %d\n" , ret); +return ret; + } + +rockchip_dfi_start_hardware_counter (edev); +return 0 ; +} + +static int rockchip_dfi_set_event (struct devfreq_event_dev *edev) +{ +return 0 ; +} + +static int rockchip_dfi_get_event (struct devfreq_event_dev *edev, +struct devfreq_event_data *edata) +{ +struct rockchip_dfi *info =devfreq_event_get_drvdata (edev); +int busier_ch; + + busier_ch =rockchip_dfi_get_busier_ch (edev); + + edata->load_count = info->ch_usage[busier_ch].access; + edata->total_count = info->ch_usage[busier_ch].total; + +return 0 ; +} + +static const struct devfreq_event_ops rockchip_dfi_ops = { + .disable = rockchip_dfi_disable, + .enable = rockchip_dfi_enable, + .get_event = rockchip_dfi_get_event, + .set_event = rockchip_dfi_set_event, +}; + +static const struct of_device_id rockchip_dfi_id_match[] = { + { .compatible ="rockchip,rk3399-dfi" }, + { }, +}; + +static int rockchip_dfi_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct rockchip_dfi *data; +struct resource *res; +struct devfreq_event_desc *desc; +struct device_node *np = pdev->dev.of_node, *node; + + data =devm_kzalloc (dev,sizeof (struct rockchip_dfi ),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + data->regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (data->regs)) +return PTR_ERR (data->regs); + + data->clk =devm_clk_get (dev,"pclk_ddr_mon" ); +if (IS_ERR (data->clk)) { +dev_err (dev,"Cannot get the clk dmc_clk\n" ); +return PTR_ERR (data->clk); + }; + +/* try to find the optional reference to the pmu syscon */ + 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); + } + data->dev = dev; + + desc =devm_kzalloc (dev,sizeof (*desc),GFP_KERNEL ); +if (!desc) +return -ENOMEM ; + + desc->ops = &rockchip_dfi_ops; + desc->driver_data = data; + desc->name = np->name; + data->desc = desc; + + data->edev =devm_devfreq_event_add_edev (&pdev->dev, desc); +if (IS_ERR (data->edev)) { +dev_err (&pdev->dev, +"failed to add devfreq-event device\n" ); +return PTR_ERR (data->edev); + } + +platform_set_drvdata (pdev, data); + +return 0 ; +} + +static struct platform_driver rockchip_dfi_driver = { + .probe = rockchip_dfi_probe, + .driver = { + .name ="rockchip-dfi" , + .of_match_table = rockchip_dfi_id_match, + }, +}; +module_platform_driver (rockchip_dfi_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Lin Huang <[email protected]>" ); +MODULE_DESCRIPTION ("Rockchip dfi driver" ); --1.9.1
Chanwoo Choi
maintainerRe: [RFC PATCH v2 6/6] drm/rockchip: Add dmc notifier in vop driver
In reply to Lin HuangHi,
Quoted 5 lines · Lin Huang
when in ddr frequency scaling process, vop can not do enable or disable operate, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled. So need register to dmc notifier, and we can get the dmc status.
If you want to know when ddr frequency is chanaged,
you can use the DEVFREQ_TRANSITION_NOTIFIER notifier[1] (merged to v4.7-rc1) which includes the following notification:
- DEVFREQ_PRECHANGE
- DEVFREQ_POSTCHANGE
[1] "PM / devfreq: Add new DEVFREQ_TRANSITION_NOTIFIER notifier"
- https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0fe3a66410a3ba96679be903f1e287d7a0a264a9
Thanks,
Chanwoo Choi
Quoted 124 lines
Signed-off-by Lin Huang <[email protected]>---
Changes in v2:
- NoneChanges in v1:
- usewait_eventinstead usleepdrivers/gpu/drm/rockchip/rockchip_drm_vop.c | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-)drivers/gpu/drm/rockchip/rockchip_drm_vop.c +41
-2@@ -31,6 +31,8 @@#include <linux/reset.h> #include <linux/delay.h> +#include <soc/rockchip/rockchip_dmc.h> +#include "rockchip_drm_drv.h" #include "rockchip_drm_gem.h" #include "rockchip_drm_fb.h" @@ -116,6 +118,10 @@ struct vop {const struct vop_data *data; +struct notifier_block dmc_nb; +int dmc_in_process; +wait_queue_head_t wait_dmc_queue; +uint32_t *regsbak;void __iomem *regs;@@ -426,6 +432,21 @@ static void vop_dsp_hold_valid_irq_disable(struct vop *vop)spin_unlock_irqrestore (&vop->irq_lock, flags); } +static int dmc_notify (struct notifier_block *nb,unsigned long event, +void *data) +{ + struct vop *vop = container_of(nb, struct vop, dmc_nb); + +if (event ==DMCFREQ_ADJUST ) { + vop->dmc_in_process =1 ; + }else if (event ==DMCFREQ_FINISH ) { + vop->dmc_in_process =0 ; +wake_up (&vop->wait_dmc_queue); + } + +return NOTIFY_OK ; +} +static void vop_enable (struct drm_crtc *crtc) {struct vop *vop =to_vop (crtc);@@ -434,6 +455,13 @@ static void vop_enable(struct drm_crtc *crtc)if (vop->is_enabled)return ; +/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + ret =pm_runtime_get_sync (vop->dev);if (ret <0 ) {dev_err (vop->dev,"failed to get pm runtime: %d\n" , ret);@@ -485,6 +513,7 @@ static void vop_enable(struct drm_crtc *crtc)enable_irq (vop->irq);drm_crtc_vblank_on (crtc); +rockchip_dmc_get (&vop->dmc_nb);return ;@@ -505,6 +534,13 @@ static void vop_crtc_disable(struct drm_crtc *crtc)return ;/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + +/* * We need to make sure that all windows are disabled before we * disable that crtc. Otherwise we might try to scan from a destroyed * buffer later. @@ -517,7 +553,7 @@ static void vop_crtc_disable(struct drm_crtc *crtc)VOP_WIN_SET (vop, win, enable,0 );spin_unlock (&vop->reg_lock); } - +rockchip_dmc_put (&vop->dmc_nb);drm_crtc_vblank_off (crtc);/* @@ -1243,7 +1279,7 @@ static int vop_create_crtc(struct vop *vop) ret = -ENOENT ; goto err_cleanup_crtc; } - + vop->dmc_nb.notifier_call = dmc_notify;init_completion (&vop->dsp_hold_completion);init_completion (&vop->wait_update_complete); crtc->port = port;@@ -1465,6 +1501,9 @@ static int vop_bind(struct device *dev, struct device *master, void *data)/* IRQ is initially disabled; it gets enabled in power_on */ disable_irq (vop->irq); +init_waitqueue_head (&vop->wait_dmc_queue); + vop->dmc_in_process =0 ; + ret =vop_create_crtc (vop);if (ret)return ret;
Re: [RFC PATCH v2 6/6] drm/rockchip: Add dmc notifier in vop driver
Hi Chanwoo Choi,
Quoted 8 lines · Chanwoo Choi
Hi,
Quoted 5 lines · Lin Huang
when in ddr frequency scaling process, vop can not do enable or disable operate, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled. So need register to dmc notifier, and we can get the dmc status.
Quoted 8 lines
If you want to know when ddr frequency is chanaged,
you can use theDEVFREQ_TRANSITION_NOTIFIERnotifier[1] (merged to v4.7-rc1) which includes the following notification:
-DEVFREQ_PRECHANGE
-DEVFREQ_POSTCHANGE[1] "PM / devfreq: Add new
DEVFREQ_TRANSITION_NOTIFIERnotifier"
- https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0fe3a66410a3ba96679be903f1e287d7a0a264a9
Check the code, if the set target fail, it will not send DEVFREQ_POSTCHANGE, but in our case, whether the target setting sucess or fail, it should send message to vop driver, tell vop driver dmc have finish frequency setting.
Quoted 130 lines
Thanks,
Chanwoo ChoiQuoted 123 lines
Signed-off-by Lin Huang <[email protected]>---
Changes in v2:
- NoneChanges in v1:
- usewait_eventinstead usleepdrivers/gpu/drm/rockchip/rockchip_drm_vop.c | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-)drivers/gpu/drm/rockchip/rockchip_drm_vop.c +41
-2@@ -31,6 +31,8 @@#include <linux/reset.h> #include <linux/delay.h> +#include <soc/rockchip/rockchip_dmc.h> +#include "rockchip_drm_drv.h" #include "rockchip_drm_gem.h" #include "rockchip_drm_fb.h" @@ -116,6 +118,10 @@ struct vop {const struct vop_data *data; +struct notifier_block dmc_nb; +int dmc_in_process; +wait_queue_head_t wait_dmc_queue; +uint32_t *regsbak;void __iomem *regs;@@ -426,6 +432,21 @@ static void vop_dsp_hold_valid_irq_disable(struct vop *vop)spin_unlock_irqrestore (&vop->irq_lock, flags); } +static int dmc_notify (struct notifier_block *nb,unsigned long event, +void *data) +{ + struct vop *vop = container_of(nb, struct vop, dmc_nb); + +if (event ==DMCFREQ_ADJUST ) { + vop->dmc_in_process =1 ; + }else if (event ==DMCFREQ_FINISH ) { + vop->dmc_in_process =0 ; +wake_up (&vop->wait_dmc_queue); + } + +return NOTIFY_OK ; +} +static void vop_enable (struct drm_crtc *crtc) {struct vop *vop =to_vop (crtc);@@ -434,6 +455,13 @@ static void vop_enable(struct drm_crtc *crtc)if (vop->is_enabled)return ; +/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + ret =pm_runtime_get_sync (vop->dev);if (ret <0 ) {dev_err (vop->dev,"failed to get pm runtime: %d\n" , ret);@@ -485,6 +513,7 @@ static void vop_enable(struct drm_crtc *crtc)enable_irq (vop->irq);drm_crtc_vblank_on (crtc); +rockchip_dmc_get (&vop->dmc_nb);return ;@@ -505,6 +534,13 @@ static void vop_crtc_disable(struct drm_crtc *crtc)return ;/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + +/* * We need to make sure that all windows are disabled before we * disable that crtc. Otherwise we might try to scan from a destroyed * buffer later. @@ -517,7 +553,7 @@ static void vop_crtc_disable(struct drm_crtc *crtc)VOP_WIN_SET (vop, win, enable,0 );spin_unlock (&vop->reg_lock); } - +rockchip_dmc_put (&vop->dmc_nb);drm_crtc_vblank_off (crtc);/* @@ -1243,7 +1279,7 @@ static int vop_create_crtc(struct vop *vop) ret = -ENOENT ; goto err_cleanup_crtc; } - + vop->dmc_nb.notifier_call = dmc_notify;init_completion (&vop->dsp_hold_completion);init_completion (&vop->wait_update_complete); crtc->port = port;@@ -1465,6 +1501,9 @@ static int vop_bind(struct device *dev, struct device *master, void *data)/* IRQ is initially disabled; it gets enabled in power_on */ disable_irq (vop->irq); +init_waitqueue_head (&vop->wait_dmc_queue); + vop->dmc_in_process =0 ; + ret =vop_create_crtc (vop);if (ret)return ret;
Signature · 1 line
Lin Huang
Chanwoo Choi
maintainerRe: [RFC PATCH v2 6/6] drm/rockchip: Add dmc notifier in vop driver
Hi Lin,
Quoted 17 lines · hl
Hi Chanwoo Choi,
Quoted 14 lines · Chanwoo Choi
Hi,
Quoted 5 lines · Lin Huang
when in ddr frequency scaling process, vop can not do enable or disable operate, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled. So need register to dmc notifier, and we can get the dmc status.
If you want to know when ddr frequency is chanaged,
you can use theDEVFREQ_TRANSITION_NOTIFIERnotifier[1] (merged to v4.7-rc1) which includes the following notification:
-DEVFREQ_PRECHANGE
-DEVFREQ_POSTCHANGE
Quoted 4 lines
Quoted 2 lines
[1] "PM / devfreq: Add new
DEVFREQ_TRANSITION_NOTIFIERnotifier"
- https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=0fe3a66410a3ba96679be903f1e287d7a0a264a9Check the code, if the set target fail, it will not send
DEVFREQ_POSTCHANGE, but in our case, whether the target setting sucess or fail, it should send message to vop driver, tell vop driver dmc have finish frequency setting.
I check the code when target function is failed. DEVFREQ_TRANSITION_NOTIFIER notifier[1] is missing the error case as you mentioned. So, we would add following patches to fix the problem.
drivers/devfreq/devfreq.c +4 -1
@@ -268,8 +268,10 @@ int update_devfreq(struct devfreq *devfreq)devfreq_notify_transition (devfreq, &freqs,DEVFREQ_PRECHANGE ); err = devfreq->profile->target (devfreq->dev.parent, &freq, flags); -if (err) +if (err) { + freqs.new = cur_freq; +devfreq_notify_transition (devfreq, &freqs,DEVFREQ_POSTCHANGE );return err; + } freqs.new = freq;
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_POSTCHANGE);
Thanks,
Chanwoo Choi
Quoted 134 lines
Quoted 130 lines
Thanks,
Chanwoo ChoiQuoted 123 lines
Signed-off-by Lin Huang <[email protected]>---
Changes in v2:
- NoneChanges in v1:
- usewait_eventinstead usleepdrivers/gpu/drm/rockchip/rockchip_drm_vop.c | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-)drivers/gpu/drm/rockchip/rockchip_drm_vop.c +41
-2@@ -31,6 +31,8 @@#include <linux/reset.h> #include <linux/delay.h> +#include <soc/rockchip/rockchip_dmc.h> +#include "rockchip_drm_drv.h" #include "rockchip_drm_gem.h" #include "rockchip_drm_fb.h" @@ -116,6 +118,10 @@ struct vop {const struct vop_data *data; +struct notifier_block dmc_nb; +int dmc_in_process; +wait_queue_head_t wait_dmc_queue; +uint32_t *regsbak;void __iomem *regs;@@ -426,6 +432,21 @@ static void vop_dsp_hold_valid_irq_disable(struct vop *vop)spin_unlock_irqrestore (&vop->irq_lock, flags); } +static int dmc_notify (struct notifier_block *nb,unsigned long event, +void *data) +{ + struct vop *vop = container_of(nb, struct vop, dmc_nb); + +if (event ==DMCFREQ_ADJUST ) { + vop->dmc_in_process =1 ; + }else if (event ==DMCFREQ_FINISH ) { + vop->dmc_in_process =0 ; +wake_up (&vop->wait_dmc_queue); + } + +return NOTIFY_OK ; +} +static void vop_enable (struct drm_crtc *crtc) {struct vop *vop =to_vop (crtc);@@ -434,6 +455,13 @@ static void vop_enable(struct drm_crtc *crtc)if (vop->is_enabled)return ; +/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + ret =pm_runtime_get_sync (vop->dev);if (ret <0 ) {dev_err (vop->dev,"failed to get pm runtime: %d\n" , ret);@@ -485,6 +513,7 @@ static void vop_enable(struct drm_crtc *crtc)enable_irq (vop->irq);drm_crtc_vblank_on (crtc); +rockchip_dmc_get (&vop->dmc_nb);return ;@@ -505,6 +534,13 @@ static void vop_crtc_disable(struct drm_crtc *crtc)return ;/* +* if in dmc scaling frequency process, wait until it finish +* use 100ms as timeout time. +*/ +wait_event_timeout (vop->wait_dmc_queue, + !vop->dmc_in_process,HZ /10 ); + +/* * We need to make sure that all windows are disabled before we * disable that crtc. Otherwise we might try to scan from a destroyed * buffer later. @@ -517,7 +553,7 @@ static void vop_crtc_disable(struct drm_crtc *crtc)VOP_WIN_SET (vop, win, enable,0 );spin_unlock (&vop->reg_lock); } - +rockchip_dmc_put (&vop->dmc_nb);drm_crtc_vblank_off (crtc);/* @@ -1243,7 +1279,7 @@ static int vop_create_crtc(struct vop *vop) ret = -ENOENT ; goto err_cleanup_crtc; } - + vop->dmc_nb.notifier_call = dmc_notify;init_completion (&vop->dsp_hold_completion);init_completion (&vop->wait_update_complete); crtc->port = port;@@ -1465,6 +1501,9 @@ static int vop_bind(struct device *dev, struct device *master, void *data)/* IRQ is initially disabled; it gets enabled in power_on */ disable_irq (vop->irq); +init_waitqueue_head (&vop->wait_dmc_queue); + vop->dmc_in_process =0 ; + ret =vop_create_crtc (vop);if (ret)return ret;Signature · 1 line
Lin Huang