Skip to contentSkip to conversation

rk3399 support ddr frequency scaling

PATCH Superseded Lin Huang 4 participants 20 messages Aug 16, 2016 – Aug 23, 2016

Subsystems (8)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Lin Huang

author
#0 lore raw

v6 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 (8):
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
Documentation: bindings: add dt documentation for dfi controller PM / devfreq: event: support rockchip dfi controller
Documentation: bindings: add dt documentation for rk3399 dmc PM / devfreq: rockchip: add devfreq driver for rk3399 dmc drm/rockchip: Add dmc notifier in vop driver

 .../bindings/devfreq/event/rockchip-dfi.txt        |  20 +
 .../devicetree/bindings/devfreq/rk3399_dmc.txt     |  84 ++++
 drivers/clk/rockchip/Makefile                      |   1 +
 drivers/clk/rockchip/clk-ddr.c                     | 150 +++++++
 drivers/clk/rockchip/clk-rk3399.c                  |  19 +
 drivers/clk/rockchip/clk.c                         |   9 +
 drivers/clk/rockchip/clk.h                         |  33 ++
 drivers/devfreq/Kconfig                            |  11 +
 drivers/devfreq/Makefile                           |   1 +
 drivers/devfreq/event/Kconfig                      |   7 +
 drivers/devfreq/event/Makefile                     |   1 +
 drivers/devfreq/event/rockchip-dfi.c               | 253 +++++++++++
 drivers/devfreq/rk3399_dmc.c                       | 497 +++++++++++++++++++++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c        | 121 ++++-
 include/dt-bindings/clock/rk3399-cru.h             |   1 +
 include/soc/rockchip/rockchip_sip.h                |  27 ++
 16 files changed, 1233 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt
 create mode 100644 Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
 create mode 100644 drivers/clk/rockchip/clk-ddr.c
 create mode 100644 drivers/devfreq/event/rockchip-dfi.c
 create mode 100644 drivers/devfreq/rk3399_dmc.c
 create mode 100644 include/soc/rockchip/rockchip_sip.h
Signature · 2 lines
2.6.6
*
author
#1 lore raw

PATCH v6 1/8 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 v6:
- none

Changes in v5:
- delete unuse mux_flag
- use div_flag to distinguish sip call and other operate

Changes in v4:
- use arm_smccc_smc() to set/read ddr rate

Changes in v3:
- use sip call to set/read ddr rate

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      | 150 ++++++++++++++++++++++++++++++++++++
 drivers/clk/rockchip/clk.c          |   9 +++
 drivers/clk/rockchip/clk.h          |  33 ++++++++
 include/soc/rockchip/rockchip_sip.h |  27 +++++++
 5 files changed, 220 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-ddr.c
 create mode 100644 include/soc/rockchip/rockchip_sip.h
drivers/clk/rockchip/Makefile +1 -0
index f47a2fa..b5f2c8e 100644
@@ -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 +150 -0

150 lines not on this page · raw message

drivers/clk/rockchip/clk.c +9 -0
index 1f1c74f..99baa5d 100644
@@ -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->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 +33 -0
index 3747de5..62c67f2 100644
@@ -112,6 +112,12 @@ struct clk;
 #define RK3399_PMU_CLKGATE_CON(x)	((x) * 0x4 + 0x100)
 #define RK3399_PMU_SOFTRST_CON(x)	((x) * 0x4 + 0x110)
 
+/*
+ * for COMPOSITE_DDRCLK div_flag
+ * it means set use sip call to set ddr clock in bl31
+ */
+#define ROCKCHIP_DDRCLK_SIP		0x01
+
 enum rockchip_pll_type {
 	pll_rk3036,
 	pll_rk3066,
@@ -281,6 +287,14 @@ 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 div_shift, int div_width,
+					 int ddr_flags, 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 +313,7 @@ enum rockchip_clk_branch_type {
 	branch_mmc,
 	branch_inverter,
 	branch_factor,
+	branch_ddrc,
 };
 
 struct rockchip_clk_branch {
@@ -488,6 +503,24 @@ struct rockchip_clk_branch {
 		.child		= ch,				\
 	}
 
+#define COMPOSITE_DDRCLK(_id, cname, pnames, f, mo, ms, mw,	\
+			 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,                           \
+		.div_shift      = ds,                           \
+		.div_width      = dw,                           \
+		.div_flags	= df,				\
+		.gate_offset    = -1,                           \
+	}
+
 #define MUX(_id, cname, pnames, f, o, s, w, mf)			\
 	{							\
 		.id		= _id,				\
include/soc/rockchip/rockchip_sip.h new file +27 -0
new file mode 100644
index 0000000..422ea36
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+#ifndef __SOC_ROCKCHIP_SIP_H
+#define __SOC_ROCKCHIP_SIP_H
+
+#define SIP_DRAM_FREQ		0x82000008
+#define CONFIG_DRAM_INIT	0x00
+#define CONFIG_DRAM_SET_RATE	0x01
+#define CONFIG_DRAM_ROUND_RATE	0x02
+#define CONFIG_DRAM_SET_AT_SR	0x03
+#define CONFIG_DRAM_GET_BW	0x04
+#define CONFIG_DRAM_GET_RATE	0x05
+#define CONFIG_DRAM_CLR_IRQ	0x06
+#define CONFIG_DRAM_SET_PARAM	0x07
+
+#endif
Signature · 1 line
2.6.6
maintainer
#2 lore raw

Re: [PATCH v6 1/8] clk: rockchip: add new clock-type for the ddrclk

Hi Lin,

Am Mittwoch, 17. August 2016, 06:36:22 CEST schrieb Lin Huang:

Quoted 119 lines

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 v6:
- none

Changes in v5:
- delete unuse mux_flag
- use div_flag to distinguish sip call and other operate

Changes in v4:
- use arm_smccc_smc() to set/read ddr rate

Changes in v3:
- use sip call to set/read ddr rate

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      | 150
++++++++++++++++++++++++++++++++++++ drivers/clk/rockchip/clk.c          | 
 9 +++
 drivers/clk/rockchip/clk.h          |  33 ++++++++
 include/soc/rockchip/rockchip_sip.h |  27 +++++++
 5 files changed, 220 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-ddr.c
 create mode 100644 include/soc/rockchip/rockchip_sip.h
drivers/clk/rockchip/Makefile +1 -0
index f47a2fa..b5f2c8e 100644
@@ -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 +38 -0
new file mode 100644
index 0000000..7dbe8bff
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2016 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 of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that 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/arm-smccc.h>
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/slab.h>
+#include <soc/rockchip/rockchip_sip.h>
+
+#include "clk.h"
+
+struct rockchip_ddrclk {
+	struct clk_hw	hw;
+	void __iomem	*reg_base;
+	int		mux_offset;
+	int		mux_shift;
+	int		mux_width;
+	int		div_shift;
+	int		div_width;
+	int		ddr_flag;
+	spinlock_t	*lock;
+};
+
+#define to_rockchip_ddrclk_hw(hw) container_of(hw, struct rockchip_ddrclk,

hw) +

drivers/clk/rockchip/clk-ddr.c new file +25 -0
+static int rockchip_ddrclk_set_rate(struct clk_hw *hw, unsigned long drate,
+				    unsigned long prate)
+{
+	struct rockchip_ddrclk *ddrclk = to_rockchip_ddrclk_hw(hw);
+	unsigned long flags;
+	struct arm_smccc_res res;
+
+	spin_lock_irqsave(ddrclk->lock, flags);
+	if (ddrclk->ddr_flag == ROCKCHIP_DDRCLK_SIP) {
+		arm_smccc_smc(SIP_DRAM_FREQ, drate, 0, CONFIG_DRAM_SET_RATE,
+			      0, 0, 0, 0, &res);
+		return res.a0;
+	}
+	spin_unlock_irqrestore(ddrclk->lock, flags);
+
+	return 0;
+}
+
+static unsigned long
+rockchip_ddrclk_recalc_rate(struct clk_hw *hw,
+			    unsigned long parent_rate)
+{
+	struct rockchip_ddrclk *ddrclk = to_rockchip_ddrclk_hw(hw);
+	struct arm_smccc_res res;
+

drivers/clk/rockchip/clk-ddr.c line 74

Quoted 10 lines
drivers/clk/rockchip/clk-ddr.c new file +10 -0
+	if (ddrclk->ddr_flag == ROCKCHIP_DDRCLK_SIP) {
+		arm_smccc_smc(SIP_DRAM_FREQ, 0, 0, CONFIG_DRAM_GET_RATE,
+			      0, 0, 0, 0, &res);
+		return res.a0;
+	}
+
+	return 0;
+}
+
+static long clk_ddrclk_round_rate(struct clk_hw *hw, unsigned long rate,

missing a Rockchip prefix

can't you also introduce a SIP method that returns the rounded rate - aka the ATF telling you which rate will be actually set, so that you can return a real round_rate value?

Quoted 17 lines
drivers/clk/rockchip/clk-ddr.c new file +17 -0
+				  unsigned long *prate)
+{
+	return rate;
+}
+
+static u8 rockchip_ddrclk_get_parent(struct clk_hw *hw)
+{
+	struct rockchip_ddrclk *ddrclk = to_rockchip_ddrclk_hw(hw);
+	int num_parents = clk_hw_get_num_parents(hw);
+	u32 val;
+
+	val = clk_readl(ddrclk->reg_base +
+			ddrclk->mux_offset) >> ddrclk->mux_shift;
+	val &= GENMASK(ddrclk->mux_width - 1, 0);
+
+	if (val >= num_parents)
+		return -EINVAL;

drivers/clk/rockchip/clk-ddr.c line 101

Quoted 10 lines
drivers/clk/rockchip/clk-ddr.c new file +10 -0
+
+	return val;
+}
+
+static const struct clk_ops rockchip_ddrclk_ops = {
+	.recalc_rate = rockchip_ddrclk_recalc_rate,
+	.set_rate = rockchip_ddrclk_set_rate,
+	.round_rate = clk_ddrclk_round_rate,
+	.get_parent = rockchip_ddrclk_get_parent,
+};

please make method-specific clock ops, like

static const struct clk_ops rockchip_ddrclk_sip_ops = {
.recalc_rate = rockchip_ddrclk_sip_recalc_rate, .set_rate = rockchip_ddrclk_sip_set_rate, .round_rate = clk_ddrclk_round_rate, .get_parent = rockchip_ddrclk_get_parent,
};

and in rockchip_clk_register_ddrclk simply do

...
switch(ddr_flag) {
case ROCKCHIP_DDRCLK_SIP:

	init.ops = &rockchip_ddrclk_sip_ops;
	break;
default:
	pr_err("%s: unsupported ddrclk type %d\n", __func__, ddr_flag);
	return ERR_PTR("-EINVAL);
}

...

That way you save all the ifs in the functions ... essentially how the plls also handle the different types.

Quoted 73 lines
drivers/clk/rockchip/clk-ddr.c new file +48 -0
+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 div_shift, int div_width,
+					 int ddr_flag, void __iomem *reg_base,
+					 spinlock_t *lock)
+{
+	struct rockchip_ddrclk *ddrclk;
+	struct clk_init_data init;
+	struct clk *clk;
+
+	ddrclk = kzalloc(sizeof(*ddrclk), GFP_KERNEL);
+	if (!ddrclk)
+		return ERR_PTR(-ENOMEM);
+
+	init.name = name;
+	init.parent_names = parent_names;
+	init.num_parents = num_parents;
+	init.ops = &rockchip_ddrclk_ops;
+
+	init.flags = flags;
+	init.flags |= CLK_SET_RATE_NO_REPARENT;
+	init.flags |= CLK_GET_RATE_NOCACHE;
+
+	ddrclk->reg_base = reg_base;
+	ddrclk->lock = lock;
+	ddrclk->hw.init = &init;
+	ddrclk->mux_offset = mux_offset;
+	ddrclk->mux_shift = mux_shift;
+	ddrclk->mux_width = mux_width;
+	ddrclk->div_shift = div_shift;
+	ddrclk->div_width = div_width;
+	ddrclk->ddr_flag = ddr_flag;
+
+	clk = clk_register(NULL, &ddrclk->hw);
+	if (IS_ERR(clk)) {
+		pr_err("%s: could not register ddrclk %s\n", __func__,	name);
+		goto free_ddrclk;
+	}
+
+	return clk;
+
+free_ddrclk:
+	kfree(ddrclk);
+
+	return NULL;
+}
drivers/clk/rockchip/clk.c +9 -0
index 1f1c74f..99baa5d 100644
@@ -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->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 +0 -0
index 3747de5..62c67f2 100644

drivers/clk/rockchip/clk.h struct clk; · line 118

Quoted 7 lines
drivers/clk/rockchip/clk.h +4 -0
@@ -112,6 +112,12 @@ struct clk;
 #define RK3399_PMU_CLKGATE_CON(x)	((x) * 0x4 + 0x100)
 #define RK3399_PMU_SOFTRST_CON(x)	((x) * 0x4 + 0x110)
 
+/*
+ * for COMPOSITE_DDRCLK div_flag
+ * it means set use sip call to set ddr clock in bl31
+ */

please shorten that comment a bit, like
/* use SIP call to firmware to change ddrclk rate */

drivers/clk/rockchip/clk.h struct clk *rockchip_clk_register_mmc(const char *name, · line 289

Quoted 9 lines
drivers/clk/rockchip/clk.h +2 -0
+#define ROCKCHIP_DDRCLK_SIP		0x01
+
 enum rockchip_pll_type {
 	pll_rk3036,
 	pll_rk3066,
@@ -281,6 +287,14 @@ struct clk *rockchip_clk_register_mmc(const char *name,
 const char *const *parent_names, u8 num_parents,
 				void __iomem *reg, int shift);
 

and move that constant here please

Quoted 65 lines
drivers/clk/rockchip/clk.h +27 -0
+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 div_shift, int div_width,
+					 int ddr_flags, 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 +313,7 @@ enum rockchip_clk_branch_type {
 	branch_mmc,
 	branch_inverter,
 	branch_factor,
+	branch_ddrc,
 };
 
 struct rockchip_clk_branch {
@@ -488,6 +503,24 @@ struct rockchip_clk_branch {
 		.child		= ch,				\
 	}
 
+#define COMPOSITE_DDRCLK(_id, cname, pnames, f, mo, ms, mw,	\
+			 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,                           \
+		.div_shift      = ds,                           \
+		.div_width      = dw,                           \
+		.div_flags	= df,				\
+		.gate_offset    = -1,                           \
+	}
+
 #define MUX(_id, cname, pnames, f, o, s, w, mf)			\
 	{							\
 		.id		= _id,				\
(quoted diff) +0 -0

b/include/soc/rockchip/rockchip_sip.h new file mode 100644 index 0000000..422ea36

include/soc/rockchip/rockchip_sip.h new file +11 -0
@@ -0,0 +1,27 @@
+/*
+ * 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/soc/rockchip/rockchip_sip.h new file +2 -0
+#ifndef __SOC_ROCKCHIP_SIP_H
+#define __SOC_ROCKCHIP_SIP_H

include/soc/rockchip/rockchip_sip.h line 25

Quoted 10 lines
include/soc/rockchip/rockchip_sip.h new file +10 -0
+
+#define SIP_DRAM_FREQ		0x82000008
+#define CONFIG_DRAM_INIT	0x00
+#define CONFIG_DRAM_SET_RATE	0x01
+#define CONFIG_DRAM_ROUND_RATE	0x02
+#define CONFIG_DRAM_SET_AT_SR	0x03
+#define CONFIG_DRAM_GET_BW	0x04
+#define CONFIG_DRAM_GET_RATE	0x05
+#define CONFIG_DRAM_CLR_IRQ	0x06
+#define CONFIG_DRAM_SET_PARAM	0x07

this is a public header, so please give the constants a more specific name (ROCKCHIP_SIP_*, ROCKCHIP_SIP_CONFIG_*) so that it doesn't produce collisions later on.

Apart from that stuff above, this looks really nice now.

Heiko

author
#3 lore raw

PATCH v6 2/8 clk: rockchip: rk3399: add SCLK_DDRCLK ID for ddrc

In reply to Lin Huang

---
Changes in v6:
-None

Changes in v5:
-None
Changes in v4:
-None

Changes in v3:
-None

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
index 50a44cf..ce5f3e9 100644
@@ -131,6 +131,7 @@
 #define SCLK_DPHY_RX0_CFG		165
 #define SCLK_RMII_SRC			166
 #define SCLK_PCIEPHY_REF100M		167
+#define SCLK_DDRC			168
 
 #define DCLK_VOP0			180
 #define DCLK_VOP1			181
Signature · 1 line
2.6.6
author
#4 lore raw

PATCH v6 3/8 clk: rockchip: rk3399: add ddrc clock support

In reply to Lin Huang

add ddrc clock setting, so we can do ddr frequency scaling on rk3399 platform in future.

---
Changes in v6:
- None

Changes in v5:
- fit for the ddr type

Changes in v4:
- None

Changes in v3:
- None

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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/clk/rockchip/clk-rk3399.c +19 -0
index e445cd6..01d4945 100644
@@ -120,6 +120,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",
@@ -1379,6 +1383,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_DDRCLK(SCLK_DDRC, "clk_ddrc", mux_ddrclk_p, 0,
+		       RK3399_CLKSEL_CON(6), 4, 2, 0, 0, ROCKCHIP_DDRCLK_SIP),
 };
 
 static struct rockchip_clk_branch rk3399_clk_pmu_branches[] __initdata = {
@@ -1493,6 +1509,9 @@ static const char *const rk3399_cru_critical_clocks[] __initconst = {
 	"gpll_aclk_perilp0_src",
 	"gpll_aclk_perihp_src",
 	"aclk_vio_noc",
+
+	/* ddrc */
+	"clk_ddrc"
 };
 
 static const char *const rk3399_pmucru_critical_clocks[] __initconst = {
Signature · 1 line
2.6.6
maintainer
#5 lore raw

Re: [PATCH v6 3/8] clk: rockchip: rk3399: add ddrc clock support

Am Mittwoch, 17. August 2016, 06:36:24 CEST schrieb Lin Huang:

drivers/clk/rockchip/clk-rk3399.c PNAME(mux_armclkb_p) = {

Quoted 32 lines

add ddrc clock setting, so we can do ddr frequency scaling on rk3399 platform in future.

---
Changes in v6:
- None

Changes in v5:
- fit for the ddr type

Changes in v4:
- None

Changes in v3:
- None

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 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
(quoted diff) +0 -0

b/drivers/clk/rockchip/clk-rk3399.c index e445cd6..01d4945 100644

drivers/clk/rockchip/clk-rk3399.c +0 -0
@@ -120,6 +120,10 @@ PNAME(mux_armclkb_p)				= { 

"clk_core_b_lpll_src",

Quoted 15 lines
drivers/clk/rockchip/clk-rk3399.c +5 -0
 						    "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",
@@ -1379,6 +1383,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),
+

drivers/clk/rockchip/clk-rk3399.c static struct rockchip_clk_branch · line 1396

Quoted 10 lines
drivers/clk/rockchip/clk-rk3399.c +10 -0
+	/* 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_DDRCLK(SCLK_DDRC, "clk_ddrc", mux_ddrclk_p, 0,

I think I'd like to have the clock also named sclk_ddrc :-)

Otherwise that looks fine

Heiko

author
#6 lore raw

PATCH v6 4/8 Documentation: bindings: add dt documentation for dfi controller

In reply to Lin Huang

This patch adds the documentation for rockchip dfi devfreq-event driver.

---
Changes in v6:
-None

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:
-None

 .../bindings/devfreq/event/rockchip-dfi.txt          | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt
Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt new file +20 -0
new file mode 100644
index 0000000..bf42255
@@ -0,0 +1,20 @@
+
+* Rockchip rk3399 DFI device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dfi".
+- reg: physical base address of each DFI and length of memory mapped region
+- rockchip,pmu: phandle to the syscon managing the "pmu general register files"
+- clocks: phandles for clock specified in "clock-names" property
+- clock-names : the name of clock used by the DFI, must be "pclk_ddr_mon";
+
+Example:
+	dfi: dfi@0xff630000 {
+		reg = <0x00 0xff630000 0x00 0x4000>;
+		compatible = "rockchip,rk3399-dfi";
+		rockchip,pmu = <&pmugrf>;
+		clocks = <&cru PCLK_DDR_MON>;
+		clock-names = "pclk_ddr_mon";
+		status = "disabled";
+	};
+
Signature · 1 line
2.6.6
maintainer Acked-by on v6 4/8
#7 lore raw

Re: [PATCH v6 4/8] Documentation: bindings: add dt documentation for dfi controller

Hi Lin,

I add one minor comment.

After fixing it, looks good to me.

Quoted 42 lines · Lin Huang

This patch adds the documentation for rockchip dfi devfreq-event driver.

---
Changes in v6:
-None

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:

(quoted diff) +0 -1
-None
 
 .../bindings/devfreq/event/rockchip-dfi.txt          | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt
Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt new file +10 -0
new file mode 100644
index 0000000..bf42255
@@ -0,0 +1,20 @@
+
+* Rockchip rk3399 DFI device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dfi".
+- reg: physical base address of each DFI and length of memory mapped region
+- rockchip,pmu: phandle to the syscon managing the "pmu general register files"
+- clocks: phandles for clock specified in "clock-names" property
+- clock-names : the name of clock used by the DFI, must be "pclk_ddr_mon";
+

Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt line 20

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt new file +10 -0
+Example:
+	dfi: dfi@0xff630000 {
+		reg = <0x00 0xff630000 0x00 0x4000>;
+		compatible = "rockchip,rk3399-dfi";
+		rockchip,pmu = <&pmugrf>;
+		clocks = <&cru PCLK_DDR_MON>;
+		clock-names = "pclk_ddr_mon";
+		status = "disabled";
+	};
+

Remove the blank line.

Thanks,
Chanwoo Choi

maintainer
#8 lore raw

Re: [PATCH v6 4/8] Documentation: bindings: add dt documentation for dfi controller

Hi Lin,

I add the additional comment.

Quoted 46 lines · Chanwoo Choi

Hi Lin,

I add one minor comment.

After fixing it, looks good to me.

Quoted 38 lines · Lin Huang

This patch adds the documentation for rockchip dfi devfreq-event driver.

---
Changes in v6:
-None

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:

(quoted diff) +0 -1
-None
 
 .../bindings/devfreq/event/rockchip-dfi.txt          | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt
Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt new file +6 -0
new file mode 100644
index 0000000..bf42255
@@ -0,0 +1,20 @@
+
+* Rockchip rk3399 DFI device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dfi".
+- reg: physical base address of each DFI and length of memory mapped region
Quoted 8 lines

Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt line 14

Quoted 8 lines
Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt new file +8 -0
+- rockchip,pmu: phandle to the syscon managing the "pmu general register files"
+- clocks: phandles for clock specified in "clock-names" property
+- clock-names : the name of clock used by the DFI, must be "pclk_ddr_mon";
+
+Example:
+	dfi: dfi@0xff630000 {
+		reg = <0x00 0xff630000 0x00 0x4000>;
+		compatible = "rockchip,rk3399-dfi";

As I said on previous mail-thread, the 'compatible' property is first usually. You better to change the order as following:

		compatible = "rockchip,rk3399-dfi";
		reg = <0x00 0xff630000 0x00 0x4000>;
Quoted 11 lines

Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt line 20

Quoted 6 lines
Documentation/devicetree/bindings/devfreq/event/rockchip-dfi.txt new file +6 -0
+		rockchip,pmu = <&pmugrf>;
+		clocks = <&cru PCLK_DDR_MON>;
+		clock-names = "pclk_ddr_mon";
+		status = "disabled";
+	};
+

Remove the blank line.

Thanks,
Chanwoo Choi

Thanks,
Chanwoo Choi

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author
#9 lore raw

PATCH v6 5/8 PM / devfreq: event: support rockchip dfi controller

In reply to Lin Huang

on rk3399 platform, there is dfi conroller can monitor ddr load, base on this result, we can do ddr freqency scaling.

---
Changes in v6:
-None

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

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
index eb6f74a..20d82c2 100644
@@ -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
+	tristate "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
index 3d6afd3..dda7090 100644
@@ -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
2.6.6
author
#10 lore raw

PATCH v6 6/8 Documentation: bindings: add dt documentation for rk3399 dmc

In reply to Lin Huang

This patch adds the documentation for rockchip rk3399 dmc driver.

---
Changes in v6:
-Add more detail in Documentation

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:
-None

 .../devicetree/bindings/devfreq/rk3399_dmc.txt     | 84 ++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +84 -0
new file mode 100644
index 0000000..e73067c
@@ -0,0 +1,84 @@
+* Rockchip rk3399 DMC(Dynamic Memory Controller) device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dmc".
+- devfreq-events: Node to get ddr loading, Refer to
+		  Documentation/devicetree/bindings/devfreq/rockchip-dif.txt
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+	      depends on the interrupt controller. it should be dcf interrupts,
+	      when ddr dvfs finish, it will happen.
+- clocks: Phandles for clock specified in "clock-names" property
+- clock-names : The name of clock used by the DFI, must be "pclk_ddr_mon";
+- operating-points-v2: Refer to Documentation/devicetree/bindings/power/opp.txt
+		       for details.
+- center-supply: Dmc supply node.
+- status: Marks the node enabled/disabled.
+
+Optional properties:
+- ddr_timing: ddr timing need to pass to arm trust firmware
+- upthreshold: the upthreshold to simpleondeamnd policy
+- downdifferential: The downdifferential to simpleondeamnd policy
+
+Example:
+	ddr_timing: ddr_timing {
+		compatible = "rockchip,ddr-timing";
+		ddr3_speed_bin = <21>;
+		pd_idle = <0>;
+		sr_idle = <0>;
+		sr_mc_gate_idle = <0>;
+		srpd_lite_idle	= <0>;
+		standby_idle = <0>;
+		dram_dll_dis_freq = <300>;
+		phy_dll_dis_freq = <125>;
+
+		ddr3_odt_dis_freq = <333>;
+		ddr3_drv = <DDR3_DS_40ohm>;
+		ddr3_odt = <DDR3_ODT_120ohm>;
+		phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
+		phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
+		phy_ddr3_odt = <PHY_DRV_ODT_240>;
+
+		lpddr3_odt_dis_freq = <333>;
+		lpddr3_drv = <LP3_DS_34ohm>;
+		lpddr3_odt = <LP3_ODT_240ohm>;
+		phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr3_odt = <PHY_DRV_ODT_240>;
+
+		lpddr4_odt_dis_freq = <333>;
+		lpddr4_drv = <LP4_PDDS_60ohm>;
+		lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
+		lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
+		phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
+		phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
+		phy_lpddr4_odt = <PHY_DRV_ODT_60>;
+	};
+
+	dmc_opp_table: dmc_opp_table {
+		compatible = "operating-points-v2";
+
+		opp00 {
+			opp-hz = /bits/ 64 <300000000>;
+			opp-microvolt = <900000>;
+		};
+		opp01 {
+			opp-hz = /bits/ 64 <666000000>;
+			opp-microvolt = <900000>;
+		};
+	};
+
+	dmc: dmc {
+		compatible = "rockchip,rk3399-dmc";
+		devfreq-events = <&dfi>;
+		interrupts = <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_DDRCLK>;
+		clock-names = "dmc_clk";
+		ddr_timing = <&ddr_timing>;
+		operating-points-v2 = <&dmc_opp_table>;
+		center-supply = <&ppvar_centerlogic>;
+		upthreshold = <15>;
+		downdifferential = <10>;
+		status = "disabled";
+	};
+
Signature · 1 line
2.6.6
maintainer
#11 lore raw

Re: [PATCH v6 6/8] Documentation: bindings: add dt documentation for rk3399 dmc

Hi Lin,

Quoted 31 lines · Lin Huang

This patch adds the documentation for rockchip rk3399 dmc driver.

---
Changes in v6:
-Add more detail in Documentation

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:

(quoted diff) +0 -1
-None
 .../devicetree/bindings/devfreq/rk3399_dmc.txt     | 84 ++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +0 -0
new file mode 100644
index 0000000..e73067c

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +9 -0
@@ -0,0 +1,84 @@
+* Rockchip rk3399 DMC(Dynamic Memory Controller) device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dmc".
+- devfreq-events: Node to get ddr loading, Refer to
+		  Documentation/devicetree/bindings/devfreq/rockchip-dif.txt
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+	      depends on the interrupt controller. it should be dcf interrupts,
+	      when ddr dvfs finish, it will happen.

If possible, you better to keep the indentation with other properties. s/it->It, dcf->DCF, ddr->DDR

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 13

Quoted 4 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +4 -0
+- clocks: Phandles for clock specified in "clock-names" property
+- clock-names : The name of clock used by the DFI, must be "pclk_ddr_mon";
+- operating-points-v2: Refer to Documentation/devicetree/bindings/power/opp.txt
+		       for details.

ditto.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +1 -0
+- center-supply: Dmc supply node.

s/Dmc/DMC becaue DMC an abbreviation.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 24

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+- status: Marks the node enabled/disabled.
+
+Optional properties:
+- ddr_timing: ddr timing need to pass to arm trust firmware
+- upthreshold: the upthreshold to simpleondeamnd policy
+- downdifferential: The downdifferential to simpleondeamnd policy
+
+Example:
+	ddr_timing: ddr_timing {
+		compatible = "rockchip,ddr-timing";

I can't find the 'rockchip,ddr-timing' driver on linux-next git repo (20160816). If ddr_timing includes the only properties for ddr_timing,
I recommend you make the separate a .dtsi file including
the ddr timing configuration. I add the reference and an example on below.

Quoted 43 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +43 -0
+		ddr3_speed_bin = <21>;
+		pd_idle = <0>;
+		sr_idle = <0>;
+		sr_mc_gate_idle = <0>;
+		srpd_lite_idle	= <0>;
+		standby_idle = <0>;
+		dram_dll_dis_freq = <300>;
+		phy_dll_dis_freq = <125>;
+
+		ddr3_odt_dis_freq = <333>;
+		ddr3_drv = <DDR3_DS_40ohm>;
+		ddr3_odt = <DDR3_ODT_120ohm>;
+		phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
+		phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
+		phy_ddr3_odt = <PHY_DRV_ODT_240>;
+
+		lpddr3_odt_dis_freq = <333>;
+		lpddr3_drv = <LP3_DS_34ohm>;
+		lpddr3_odt = <LP3_ODT_240ohm>;
+		phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr3_odt = <PHY_DRV_ODT_240>;
+
+		lpddr4_odt_dis_freq = <333>;
+		lpddr4_drv = <LP4_PDDS_60ohm>;
+		lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
+		lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
+		phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
+		phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
+		phy_lpddr4_odt = <PHY_DRV_ODT_60>;
+	};
+
+	dmc_opp_table: dmc_opp_table {
+		compatible = "operating-points-v2";
+
+		opp00 {
+			opp-hz = /bits/ 64 <300000000>;
+			opp-microvolt = <900000>;
+		};
+		opp01 {
+			opp-hz = /bits/ 64 <666000000>;
+			opp-microvolt = <900000>;

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 77

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+		};
+	};
+
+	dmc: dmc {
+		compatible = "rockchip,rk3399-dmc";
+		devfreq-events = <&dfi>;
+		interrupts = <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_DDRCLK>;
+		clock-names = "dmc_clk";
+		ddr_timing = <&ddr_timing>;

You can use the following '#include' instead of 'ddr_timing' because the ddr_timing is not a device driver. Instead, the rk3399-dmc must need the ddr timing configuration.

		#include "rk3399-dmc-timing-conf.dtsi"

You can refer the similar usage case[1].
The *.conf.dtsi is used on exynos3250 tmu dt node[2].

[1] arch/arm/boot/dts/exynos4412-tmu-sensor-conf.dtsi
[2] arch/arm/boot/dts/exynos3250.dtsi, 224 line.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 84

Quoted 8 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +7 -0
+		operating-points-v2 = <&dmc_opp_table>;
+		center-supply = <&ppvar_centerlogic>;
+		upthreshold = <15>;
+		downdifferential = <10>;
+		status = "disabled";
+	};
+

For example,
I think that you can add the following timing .dtsi file.
- arch/arm/boot/dts/rk3399-dmc-timing-conf.dtsi

/*
* Device tree sources for RK3399 DDR timing configuration
*
* Copyright (c) 2016 Lin Huang <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

rockchip,ddr3_speed_bin = <21>;
rockchip,pd_idle = <0>;
rockchip,sr_idle = <0>;
rockchip,sr_mc_gate_idle = <0>;
rockchip,srpd_lite_idle = <0>;
rockchip,standby_idle = <0>;
rockchip,dram_dll_dis_freq = <300>;
rockchip,phy_dll_dis_freq = <125>;

rockchip,ddr3_odt_dis_freq = <333>;
rockchip,ddr3_drv = <DDR3_DS_40ohm>;
rockchip,ddr3_odt = <DDR3_ODT_120ohm>;
rockchip,phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_odt = <PHY_DRV_ODT_240>;

rockchip,lpddr3_odt_dis_freq = <333>;
rockchip,lpddr3_drv = <LP3_DS_34ohm>;
rockchip,lpddr3_odt = <LP3_ODT_240ohm>;
rockchip,phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_odt = <PHY_DRV_ODT_240>;

rockchip,lpddr4_odt_dis_freq = <333>;
rockchip,lpddr4_drv = <LP4_PDDS_60ohm>;
rockchip,lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
rockchip,lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
rockchip,phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_odt = <PHY_DRV_ODT_60>;

Regards,
Chanwoo Choi

author
#12 lore raw

Re: [PATCH v6 6/8] Documentation: bindings: add dt documentation for rk3399 dmc

Hi Chanwoo Choi,

Quoted 181 lines · Chanwoo Choi

Hi Lin,

Quoted 31 lines · Lin Huang

This patch adds the documentation for rockchip rk3399 dmc driver.

---
Changes in v6:
-Add more detail in Documentation

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:

(quoted diff) +0 -1
-None
  .../devicetree/bindings/devfreq/rk3399_dmc.txt     | 84 ++++++++++++++++++++++
  1 file changed, 84 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +0 -0
new file mode 100644
index 0000000..e73067c

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +9 -0
@@ -0,0 +1,84 @@
+* Rockchip rk3399 DMC(Dynamic Memory Controller) device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dmc".
+- devfreq-events: Node to get ddr loading, Refer to
+		  Documentation/devicetree/bindings/devfreq/rockchip-dif.txt
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+	      depends on the interrupt controller. it should be dcf interrupts,
+	      when ddr dvfs finish, it will happen.

If possible, you better to keep the indentation with other properties. s/it->It, dcf->DCF, ddr->DDR

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 13

Quoted 4 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +4 -0
+- clocks: Phandles for clock specified in "clock-names" property
+- clock-names : The name of clock used by the DFI, must be "pclk_ddr_mon";
+- operating-points-v2: Refer to Documentation/devicetree/bindings/power/opp.txt
+		       for details.

ditto.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +1 -0
+- center-supply: Dmc supply node.

s/Dmc/DMC becaue DMC an abbreviation.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 24

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+- status: Marks the node enabled/disabled.
+
+Optional properties:
+- ddr_timing: ddr timing need to pass to arm trust firmware
+- upthreshold: the upthreshold to simpleondeamnd policy
+- downdifferential: The downdifferential to simpleondeamnd policy
+
+Example:
+	ddr_timing: ddr_timing {
+		compatible = "rockchip,ddr-timing";

I can't find the 'rockchip,ddr-timing' driver on linux-next git repo (20160816). If ddr_timing includes the only properties for ddr_timing,
I recommend you make the separate a .dtsi file including
the ddr timing configuration. I add the reference and an example on below.

Quoted 43 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +43 -0
+		ddr3_speed_bin = <21>;
+		pd_idle = <0>;
+		sr_idle = <0>;
+		sr_mc_gate_idle = <0>;
+		srpd_lite_idle	= <0>;
+		standby_idle = <0>;
+		dram_dll_dis_freq = <300>;
+		phy_dll_dis_freq = <125>;
+
+		ddr3_odt_dis_freq = <333>;
+		ddr3_drv = <DDR3_DS_40ohm>;
+		ddr3_odt = <DDR3_ODT_120ohm>;
+		phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
+		phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
+		phy_ddr3_odt = <PHY_DRV_ODT_240>;
+
+		lpddr3_odt_dis_freq = <333>;
+		lpddr3_drv = <LP3_DS_34ohm>;
+		lpddr3_odt = <LP3_ODT_240ohm>;
+		phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr3_odt = <PHY_DRV_ODT_240>;
+
+		lpddr4_odt_dis_freq = <333>;
+		lpddr4_drv = <LP4_PDDS_60ohm>;
+		lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
+		lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
+		phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
+		phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
+		phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
+		phy_lpddr4_odt = <PHY_DRV_ODT_60>;
+	};
+
+	dmc_opp_table: dmc_opp_table {
+		compatible = "operating-points-v2";
+
+		opp00 {
+			opp-hz = /bits/ 64 <300000000>;
+			opp-microvolt = <900000>;
+		};
+		opp01 {
+			opp-hz = /bits/ 64 <666000000>;
+			opp-microvolt = <900000>;

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 77

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+		};
+	};
+
+	dmc: dmc {
+		compatible = "rockchip,rk3399-dmc";
+		devfreq-events = <&dfi>;
+		interrupts = <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_DDRCLK>;
+		clock-names = "dmc_clk";
+		ddr_timing = <&ddr_timing>;

You can use the following '#include' instead of 'ddr_timing' because the ddr_timing is not a device driver. Instead, the rk3399-dmc must need the ddr timing configuration.

		#include "rk3399-dmc-timing-conf.dtsi"

You can refer the similar usage case[1].
The *.conf.dtsi is used on exynos3250 tmu dt node[2].

[1] arch/arm/boot/dts/exynos4412-tmu-sensor-conf.dtsi
[2] arch/arm/boot/dts/exynos3250.dtsi, 224 line.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 84

Quoted 8 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +7 -0
+		operating-points-v2 = <&dmc_opp_table>;
+		center-supply = <&ppvar_centerlogic>;
+		upthreshold = <15>;
+		downdifferential = <10>;
+		status = "disabled";
+	};
+

For example,
I think that you can add the following timing .dtsi file.
- arch/arm/boot/dts/rk3399-dmc-timing-conf.dtsi

/*
* Device tree sources for RK3399 DDR timing configuration *
* Copyright (c) 2016 Lin Huang <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

rockchip,ddr3_speed_bin = <21>;
rockchip,pd_idle = <0>;
rockchip,sr_idle = <0>;
rockchip,sr_mc_gate_idle = <0>;
rockchip,srpd_lite_idle = <0>;
rockchip,standby_idle = <0>;
rockchip,dram_dll_dis_freq = <300>;
rockchip,phy_dll_dis_freq = <125>;

rockchip,ddr3_odt_dis_freq = <333>;
rockchip,ddr3_drv = <DDR3_DS_40ohm>;
rockchip,ddr3_odt = <DDR3_ODT_120ohm>;
rockchip,phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_odt = <PHY_DRV_ODT_240>;

rockchip,lpddr3_odt_dis_freq = <333>;
rockchip,lpddr3_drv = <LP3_DS_34ohm>;
rockchip,lpddr3_odt = <LP3_ODT_240ohm>;
rockchip,phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_odt = <PHY_DRV_ODT_240>;

Quoted 8 lines

rockchip,lpddr4_odt_dis_freq = <333>;
rockchip,lpddr4_drv = <LP4_PDDS_60ohm>;
rockchip,lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
rockchip,lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
rockchip,phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_odt = <PHY_DRV_ODT_60>;

Actually, i am doing like it on my downstream dtsi, but how to explain it in rk3399_dmc Documentation? Creat a new ddr_timing Documentation? But it is not a driver, just a dtsi, that why i put it on rk3399_dmc.txt now, do you have a better idea?

Quoted 8 lines

Regards,
Chanwoo Choi

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

Signature · 1 line
Lin Huang
maintainer
#13 lore raw

Re: [PATCH v6 6/8] Documentation: bindings: add dt documentation for rk3399 dmc

Hi Lin,

Quoted 192 lines · hl

Hi Chanwoo Choi,

Quoted 181 lines · Chanwoo Choi

Hi Lin,

Quoted 31 lines · Lin Huang

This patch adds the documentation for rockchip rk3399 dmc driver.

---
Changes in v6:
-Add more detail in Documentation

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:

(quoted diff) +0 -1
-None
  .../devicetree/bindings/devfreq/rk3399_dmc.txt     | 84 ++++++++++++++++++++++
  1 file changed, 84 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +0 -0
new file mode 100644
index 0000000..e73067c

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +9 -0
@@ -0,0 +1,84 @@
+* Rockchip rk3399 DMC(Dynamic Memory Controller) device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dmc".
+- devfreq-events: Node to get ddr loading, Refer to
+          Documentation/devicetree/bindings/devfreq/rockchip-dif.txt
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+          depends on the interrupt controller. it should be dcf interrupts,
+          when ddr dvfs finish, it will happen.

If possible, you better to keep the indentation with other properties. s/it->It, dcf->DCF, ddr->DDR

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 13

Quoted 4 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +4 -0
+- clocks: Phandles for clock specified in "clock-names" property
+- clock-names : The name of clock used by the DFI, must be "pclk_ddr_mon";
+- operating-points-v2: Refer to Documentation/devicetree/bindings/power/opp.txt
+               for details.

ditto.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +1 -0
+- center-supply: Dmc supply node.

s/Dmc/DMC becaue DMC an abbreviation.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 24

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+- status: Marks the node enabled/disabled.
+
+Optional properties:
+- ddr_timing: ddr timing need to pass to arm trust firmware
+- upthreshold: the upthreshold to simpleondeamnd policy
+- downdifferential: The downdifferential to simpleondeamnd policy
+
+Example:
+    ddr_timing: ddr_timing {
+        compatible = "rockchip,ddr-timing";

I can't find the 'rockchip,ddr-timing' driver on linux-next git repo (20160816). If ddr_timing includes the only properties for ddr_timing,
I recommend you make the separate a .dtsi file including
the ddr timing configuration. I add the reference and an example on below.

Quoted 43 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +43 -0
+        ddr3_speed_bin = <21>;
+        pd_idle = <0>;
+        sr_idle = <0>;
+        sr_mc_gate_idle = <0>;
+        srpd_lite_idle    = <0>;
+        standby_idle = <0>;
+        dram_dll_dis_freq = <300>;
+        phy_dll_dis_freq = <125>;
+
+        ddr3_odt_dis_freq = <333>;
+        ddr3_drv = <DDR3_DS_40ohm>;
+        ddr3_odt = <DDR3_ODT_120ohm>;
+        phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
+        phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
+        phy_ddr3_odt = <PHY_DRV_ODT_240>;
+
+        lpddr3_odt_dis_freq = <333>;
+        lpddr3_drv = <LP3_DS_34ohm>;
+        lpddr3_odt = <LP3_ODT_240ohm>;
+        phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
+        phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
+        phy_lpddr3_odt = <PHY_DRV_ODT_240>;
+
+        lpddr4_odt_dis_freq = <333>;
+        lpddr4_drv = <LP4_PDDS_60ohm>;
+        lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
+        lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
+        phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
+        phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
+        phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
+        phy_lpddr4_odt = <PHY_DRV_ODT_60>;
+    };
+
+    dmc_opp_table: dmc_opp_table {
+        compatible = "operating-points-v2";
+
+        opp00 {
+            opp-hz = /bits/ 64 <300000000>;
+            opp-microvolt = <900000>;
+        };
+        opp01 {
+            opp-hz = /bits/ 64 <666000000>;
+            opp-microvolt = <900000>;

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 77

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+        };
+    };
+
+    dmc: dmc {
+        compatible = "rockchip,rk3399-dmc";
+        devfreq-events = <&dfi>;
+        interrupts = <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&cru SCLK_DDRCLK>;
+        clock-names = "dmc_clk";
+        ddr_timing = <&ddr_timing>;

You can use the following '#include' instead of 'ddr_timing' because the ddr_timing is not a device driver. Instead, the rk3399-dmc must need the ddr timing configuration.

        #include "rk3399-dmc-timing-conf.dtsi"

You can refer the similar usage case[1].
The *.conf.dtsi is used on exynos3250 tmu dt node[2].

[1] arch/arm/boot/dts/exynos4412-tmu-sensor-conf.dtsi
[2] arch/arm/boot/dts/exynos3250.dtsi, 224 line.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 84

Quoted 8 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +7 -0
+        operating-points-v2 = <&dmc_opp_table>;
+        center-supply = <&ppvar_centerlogic>;
+        upthreshold = <15>;
+        downdifferential = <10>;
+        status = "disabled";
+    };
+

For example,
I think that you can add the following timing .dtsi file.
- arch/arm/boot/dts/rk3399-dmc-timing-conf.dtsi

/*
* Device tree sources for RK3399 DDR timing configuration *
* Copyright (c) 2016 Lin Huang <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

rockchip,ddr3_speed_bin = <21>;
rockchip,pd_idle = <0>;
rockchip,sr_idle = <0>;
rockchip,sr_mc_gate_idle = <0>;
rockchip,srpd_lite_idle = <0>;
rockchip,standby_idle = <0>;
rockchip,dram_dll_dis_freq = <300>;
rockchip,phy_dll_dis_freq = <125>;

rockchip,ddr3_odt_dis_freq = <333>;
rockchip,ddr3_drv = <DDR3_DS_40ohm>;
rockchip,ddr3_odt = <DDR3_ODT_120ohm>;
rockchip,phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_odt = <PHY_DRV_ODT_240>;

rockchip,lpddr3_odt_dis_freq = <333>;
rockchip,lpddr3_drv = <LP3_DS_34ohm>;
rockchip,lpddr3_odt = <LP3_ODT_240ohm>;
rockchip,phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_odt = <PHY_DRV_ODT_240>;

Quoted 8 lines

rockchip,lpddr4_odt_dis_freq = <333>;
rockchip,lpddr4_drv = <LP4_PDDS_60ohm>;
rockchip,lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
rockchip,lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
rockchip,phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_odt = <PHY_DRV_ODT_60>;

Quoted 3 lines

Actually, i am doing like it on my downstream dtsi, but how to explain it in rk3399_dmc Documentation? Creat a new ddr_timing Documentation? But it is not a driver, just a dtsi, that why i put it on rk3399_dmc.txt now, do you have a better idea?

I think that you don't need to add the new ddr_timing document.

The ddr_timing value are only used in the rk3399_dmc.c driver. So, the description of ddr_timing information should be included in rk3399_dmc.txt.

As I already mentioned, please refer the the similiar case[1][2]. The exynos-thermal.txt[2] include the description of propertis[1].

[1] arch/arm/boot/dts/exynos4412-tmu-sensor-conf.dtsi
[2] Documentation/devicetree/bindings/tmu/exynos-thermal.txt

Signature · 2 lines
Best Regards,
Chanwoo Choi
author
#14 lore raw

Re: [PATCH v6 6/8] Documentation: bindings: add dt documentation for rk3399 dmc

Hi Chanwoo Choi,

Quoted 204 lines · Chanwoo Choi

Hi Lin,

Quoted 192 lines · hl

Hi Chanwoo Choi,

Quoted 181 lines · Chanwoo Choi

Hi Lin,

Quoted 31 lines · Lin Huang

This patch adds the documentation for rockchip rk3399 dmc driver.

---
Changes in v6:
-Add more detail in Documentation

Changes in v5:
-None

Changes in v4:
-None

Changes in v3:
-None

Changes in v2:
-None

Changes in v1:

(quoted diff) +0 -1
-None
   .../devicetree/bindings/devfreq/rk3399_dmc.txt     | 84 ++++++++++++++++++++++
   1 file changed, 84 insertions(+)
   create mode 100644 Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +0 -0
new file mode 100644
index 0000000..e73067c

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +9 -0
@@ -0,0 +1,84 @@
+* Rockchip rk3399 DMC(Dynamic Memory Controller) device
+
+Required properties:
+- compatible: Must be "rockchip,rk3399-dmc".
+- devfreq-events: Node to get ddr loading, Refer to
+          Documentation/devicetree/bindings/devfreq/rockchip-dif.txt
+- interrupts: The interrupt number to the cpu. The interrupt specifier format
+          depends on the interrupt controller. it should be dcf interrupts,
+          when ddr dvfs finish, it will happen.

If possible, you better to keep the indentation with other properties. s/it->It, dcf->DCF, ddr->DDR

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 13

Quoted 4 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +4 -0
+- clocks: Phandles for clock specified in "clock-names" property
+- clock-names : The name of clock used by the DFI, must be "pclk_ddr_mon";
+- operating-points-v2: Refer to Documentation/devicetree/bindings/power/opp.txt
+               for details.

ditto.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +1 -0
+- center-supply: Dmc supply node.

s/Dmc/DMC becaue DMC an abbreviation.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 24

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+- status: Marks the node enabled/disabled.
+
+Optional properties:
+- ddr_timing: ddr timing need to pass to arm trust firmware
+- upthreshold: the upthreshold to simpleondeamnd policy
+- downdifferential: The downdifferential to simpleondeamnd policy
+
+Example:
+    ddr_timing: ddr_timing {
+        compatible = "rockchip,ddr-timing";

I can't find the 'rockchip,ddr-timing' driver on linux-next git repo (20160816). If ddr_timing includes the only properties for ddr_timing,
I recommend you make the separate a .dtsi file including
the ddr timing configuration. I add the reference and an example on below.

Quoted 43 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +43 -0
+        ddr3_speed_bin = <21>;
+        pd_idle = <0>;
+        sr_idle = <0>;
+        sr_mc_gate_idle = <0>;
+        srpd_lite_idle    = <0>;
+        standby_idle = <0>;
+        dram_dll_dis_freq = <300>;
+        phy_dll_dis_freq = <125>;
+
+        ddr3_odt_dis_freq = <333>;
+        ddr3_drv = <DDR3_DS_40ohm>;
+        ddr3_odt = <DDR3_ODT_120ohm>;
+        phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
+        phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
+        phy_ddr3_odt = <PHY_DRV_ODT_240>;
+
+        lpddr3_odt_dis_freq = <333>;
+        lpddr3_drv = <LP3_DS_34ohm>;
+        lpddr3_odt = <LP3_ODT_240ohm>;
+        phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
+        phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
+        phy_lpddr3_odt = <PHY_DRV_ODT_240>;
+
+        lpddr4_odt_dis_freq = <333>;
+        lpddr4_drv = <LP4_PDDS_60ohm>;
+        lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
+        lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
+        phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
+        phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
+        phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
+        phy_lpddr4_odt = <PHY_DRV_ODT_60>;
+    };
+
+    dmc_opp_table: dmc_opp_table {
+        compatible = "operating-points-v2";
+
+        opp00 {
+            opp-hz = /bits/ 64 <300000000>;
+            opp-microvolt = <900000>;
+        };
+        opp01 {
+            opp-hz = /bits/ 64 <666000000>;
+            opp-microvolt = <900000>;

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 77

Quoted 10 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +10 -0
+        };
+    };
+
+    dmc: dmc {
+        compatible = "rockchip,rk3399-dmc";
+        devfreq-events = <&dfi>;
+        interrupts = <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&cru SCLK_DDRCLK>;
+        clock-names = "dmc_clk";
+        ddr_timing = <&ddr_timing>;

You can use the following '#include' instead of 'ddr_timing' because the ddr_timing is not a device driver. Instead, the rk3399-dmc must need the ddr timing configuration.

         #include "rk3399-dmc-timing-conf.dtsi"

You can refer the similar usage case[1].
The *.conf.dtsi is used on exynos3250 tmu dt node[2].

[1] arch/arm/boot/dts/exynos4412-tmu-sensor-conf.dtsi
[2] arch/arm/boot/dts/exynos3250.dtsi, 224 line.

Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt line 84

Quoted 8 lines
Documentation/devicetree/bindings/devfreq/rk3399_dmc.txt new file +7 -0
+        operating-points-v2 = <&dmc_opp_table>;
+        center-supply = <&ppvar_centerlogic>;
+        upthreshold = <15>;
+        downdifferential = <10>;
+        status = "disabled";
+    };
+

For example,
I think that you can add the following timing .dtsi file.
- arch/arm/boot/dts/rk3399-dmc-timing-conf.dtsi

/*
* Device tree sources for RK3399 DDR timing configuration *
* Copyright (c) 2016 Lin Huang <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

rockchip,ddr3_speed_bin = <21>;
rockchip,pd_idle = <0>;
rockchip,sr_idle = <0>;
rockchip,sr_mc_gate_idle = <0>;
rockchip,srpd_lite_idle = <0>;
rockchip,standby_idle = <0>;
rockchip,dram_dll_dis_freq = <300>;
rockchip,phy_dll_dis_freq = <125>;

rockchip,ddr3_odt_dis_freq = <333>;
rockchip,ddr3_drv = <DDR3_DS_40ohm>;
rockchip,ddr3_odt = <DDR3_ODT_120ohm>;
rockchip,phy_ddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_ddr3_odt = <PHY_DRV_ODT_240>;

rockchip,lpddr3_odt_dis_freq = <333>;
rockchip,lpddr3_drv = <LP3_DS_34ohm>;
rockchip,lpddr3_odt = <LP3_ODT_240ohm>;
rockchip,phy_lpddr3_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_dq_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr3_odt = <PHY_DRV_ODT_240>;

Quoted 8 lines

rockchip,lpddr4_odt_dis_freq = <333>;
rockchip,lpddr4_drv = <LP4_PDDS_60ohm>;
rockchip,lpddr4_dq_odt = <LP4_DQ_ODT_40ohm>;
rockchip,lpddr4_ca_odt = <LP4_CA_ODT_40ohm>;
rockchip,phy_lpddr4_ca_drv = <PHY_DRV_ODT_40>;
rockchip,phy_lpddr4_ck_cs_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_dq_drv = <PHY_DRV_ODT_80>;
rockchip,phy_lpddr4_odt = <PHY_DRV_ODT_60>;

Quoted 3 lines

Actually, i am doing like it on my downstream dtsi, but how to explain it in rk3399_dmc Documentation? Creat a new ddr_timing Documentation? But it is not a driver, just a dtsi, that why i put it on rk3399_dmc.txt now, do you have a better idea?

I think that you don't need to add the new ddr_timing document.

The ddr_timing value are only used in the rk3399_dmc.c driver. So, the description of ddr_timing information should be included in rk3399_dmc.txt.

Quoted 5 lines

As I already mentioned, please refer the the similiar case[1][2]. The exynos-thermal.txt[2] include the description of propertis[1].

[1] arch/arm/boot/dts/exynos4412-tmu-sensor-conf.dtsi
[2] Documentation/devicetree/bindings/tmu/exynos-thermal.txt

Got it, will reference it next version, thanks.

Signature · 1 line
Lin Huang
author
#15 lore raw

PATCH v6 7/8 PM / devfreq: rockchip: add devfreq driver for rk3399 dmc

In reply to Lin Huang

base on dfi result, we do ddr frequency scaling, register dmc driver to devfreq framework, and use simple-ondemand policy.

---
Changes in v6:
- fix some nit suggest by Chanwoo Choi

Changes in v5:
- improve dmc driver suggest by Chanwoo Choi

Changes in v4:
- use arm_smccc_smc() function talk to bl31
- delete rockchip_dmc.c file and config
- delete dmc_notify
- adjust probe order

Changes in v3:
- operate dram setting through sip call
- imporve set rate flow

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      |  11 +
 drivers/devfreq/Makefile     |   1 +
 drivers/devfreq/rk3399_dmc.c | 497 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 509 insertions(+)
 create mode 100644 drivers/devfreq/rk3399_dmc.c
drivers/devfreq/Kconfig +11 -0
index a5be56e..e848121 100644
@@ -100,6 +100,17 @@ config ARM_TEGRA_DEVFREQ
          It reads ACTMON counters of memory controllers and adjusts the
          operating frequencies and voltages with OPP support.
 
+config ARM_RK3399_DMC_DEVFREQ
+	tristate "ARM RK3399 DMC DEVFREQ Driver"
+	depends on ARCH_ROCKCHIP
+	select DEVFREQ_EVENT_ROCKCHIP_DFI
+	select DEVFREQ_GOV_SIMPLE_ONDEMAND
+	select PM_OPP
+	help
+          This adds the DEVFREQ driver for the RK3399 DMC(Dynamic Memory Controller).
+          It sets the frequency for the memory controller and reads the usage counts
+          from hardware.
+
 source "drivers/devfreq/event/Kconfig"
 
 endif # PM_DEVFREQ
drivers/devfreq/Makefile +1 -0
index 09f11d9..fbff40a 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE)	+= governor_passive.o
 
 # DEVFREQ Drivers
 obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ)	+= exynos-bus.o
+obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ)	+= rk3399_dmc.o
 obj-$(CONFIG_ARM_TEGRA_DEVFREQ)		+= tegra-devfreq.o
 
 # DEVFREQ Event Drivers
drivers/devfreq/rk3399_dmc.c new file +497 -0

497 lines not on this page · raw message

Signature · 1 line
2.6.6
maintainer
#16 lore raw

Re: [PATCH v6 7/8] PM / devfreq: rockchip: add devfreq driver for rk3399 dmc

Hi Lin,

I add just one comment to remove the blank line.

Quoted 38 lines · Lin Huang

base on dfi result, we do ddr frequency scaling, register dmc driver to devfreq framework, and use simple-ondemand policy.

---
Changes in v6:
- fix some nit suggest by Chanwoo Choi

Changes in v5:
- improve dmc driver suggest by Chanwoo Choi

Changes in v4:
- use arm_smccc_smc() function talk to bl31
- delete rockchip_dmc.c file and config
- delete dmc_notify
- adjust probe order

Changes in v3:
- operate dram setting through sip call
- imporve set rate flow

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      |  11 +
 drivers/devfreq/Makefile     |   1 +
 drivers/devfreq/rk3399_dmc.c | 497 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 509 insertions(+)
 create mode 100644 drivers/devfreq/rk3399_dmc.c

[snip]

Quoted 33 lines
drivers/devfreq/rk3399_dmc.c new file +33 -0
+
+static int rk3399_dmcfreq_probe(struct platform_device *pdev)
+{
+	struct arm_smccc_res res;
+	struct device *dev = &pdev->dev;
+	struct device_node *np = pdev->dev.of_node;
+	struct rk3399_dmcfreq *data;
+	int ret, irq, index, size;
+	uint32_t *timing;
+	struct dev_pm_opp *opp;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Cannot get the dmc interrupt resource\n");
+		return -EINVAL;
+	}
+	data = devm_kzalloc(dev, sizeof(struct rk3399_dmcfreq), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	mutex_init(&data->lock);
+
+	data->vdd_center = devm_regulator_get(dev, "center");
+	if (IS_ERR(data->vdd_center)) {
+		dev_err(dev, "Cannot get the regulator \"center\"\n");
+		return PTR_ERR(data->vdd_center);
+	}
+
+	data->dmc_clk = devm_clk_get(dev, "dmc_clk");
+	if (IS_ERR(data->dmc_clk)) {
+		dev_err(dev, "Cannot get the clk dmc_clk\n");
+		return PTR_ERR(data->dmc_clk);
+	};

drivers/devfreq/rk3399_dmc.c line 391

Quoted 10 lines
drivers/devfreq/rk3399_dmc.c new file +10 -0
+
+	data->irq = irq;
+	ret = devm_request_irq(dev, irq, rk3399_dmc_irq, 0,
+			       dev_name(dev), data);
+	if (ret) {
+		dev_err(dev, "Failed to request dmc irq: %d\n", ret);
+		return ret;
+	}
+
+	

Remove the unneeded blank line.

[snip]

Regards,
Chanwoo Choi

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author
#17 lore raw

PATCH v6 8/8 drm/rockchip: Add dmc notifier in vop driver

In reply to Lin Huang

when in ddr frequency scaling process, vop can not do enable or disable operation, 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 devfreq notifier, and we can get the dmc status. Also, when there have two vop enabled, we need to disable dmc, since dcf only base on one vop vblank time, so the other panel will flicker when do ddr frequency scaling.

---
Changes in v6:
- fix a build error

Changes in v5:
- improve some nits

Changes in v4:
- register notifier to devfreq_register_notifier
- use DEVFREQ_PRECHANGE and DEVFREQ_POSTCHANGE to get dmc status
- when two vop enable, disable dmc
- when two vop back to one vop, enable dmc

Changes in v3:
- when do vop eanble/disable, dmc will wait until it finish

Changes in v2:
- None

Changes in v1:
- use wait_event instead usleep

 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 121 +++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +119 -2
index 31744fe..199529e 100644
@@ -12,6 +12,8 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/devfreq.h>
+#include <linux/devfreq-event.h>
 #include <drm/drm.h>
 #include <drm/drmP.h>
 #include <drm/drm_atomic.h>
@@ -118,6 +120,13 @@ struct vop {
 
 	const struct vop_data *data;
 
+	struct devfreq *devfreq;
+	struct devfreq_event_dev *devfreq_event_dev;
+	struct notifier_block dmc_nb;
+	int dmc_in_process;
+	int vop_switch_status;
+	wait_queue_head_t wait_dmc_queue;
+	wait_queue_head_t wait_vop_switch_queue;
 	uint32_t *regsbak;
 	void __iomem *regs;
 
@@ -428,21 +437,56 @@ 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 == DEVFREQ_PRECHANGE) {
+		/*
+		 * check if vop in enable or disable process,
+		 * if yes, wait until it finishes, use 200ms as
+		 * timeout.
+		 */
+		if (!wait_event_timeout(vop->wait_vop_switch_queue,
+					!vop->vop_switch_status, HZ / 5))
+			dev_warn(vop->dev,
+				 "Timeout waiting for vop swtich status\n");
+		vop->dmc_in_process = 1;
+	} else if (event == DEVFREQ_POSTCHANGE) {
+		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);
+	int num_enabled_crtc = 0;
 	int ret;
 
+	/*
+	 * if in dmc scaling frequency process, wait until it finishes
+	 * use 100ms as timeout time.
+	 */
+	if (!wait_event_timeout(vop->wait_dmc_queue,
+				!vop->dmc_in_process, HZ / 5))
+		dev_warn(vop->dev,
+			 "Timeout waiting for dmc when vop enable\n");
+
+	vop->vop_switch_status = 1;
 	ret = pm_runtime_get_sync(vop->dev);
 	if (ret < 0) {
 		dev_err(vop->dev, "failed to get pm runtime: %d\n", ret);
-		return;
+		goto err;
 	}
 
 	ret = clk_enable(vop->hclk);
 	if (ret < 0) {
 		dev_err(vop->dev, "failed to enable hclk - %d\n", ret);
-		return;
+		goto err;
 	}
 
 	ret = clk_enable(vop->dclk);
@@ -485,6 +529,21 @@ static void vop_enable(struct drm_crtc *crtc)
 
 	drm_crtc_vblank_on(crtc);
 
+	vop->vop_switch_status = 0;
+	wake_up(&vop->wait_vop_switch_queue);
+
+	/* check how many vop we use now */
+	drm_for_each_crtc(crtc, vop->drm_dev) {
+		if (crtc->state->enable)
+			num_enabled_crtc++;
+	}
+
+	/* if enable two vop, need to disable dmc */
+	if ((num_enabled_crtc > 1) && vop->devfreq) {
+		if (vop->devfreq_event_dev)
+			devfreq_event_disable_edev(vop->devfreq_event_dev);
+		devfreq_suspend_device(vop->devfreq);
+	}
 	return;
 
 err_disable_aclk:
@@ -493,16 +552,32 @@ err_disable_dclk:
 	clk_disable(vop->dclk);
 err_disable_hclk:
 	clk_disable(vop->hclk);
+err:
+	vop->vop_switch_status = 0;
+	wake_up(&vop->wait_vop_switch_queue);
+	return;
 }
 
 static void vop_crtc_disable(struct drm_crtc *crtc)
 {
 	struct vop *vop = to_vop(crtc);
+	int num_enabled_crtc = 0;
 	int i;
 
 	WARN_ON(vop->event);
 
 	/*
+	 * if in dmc scaling frequency process, wait until it finish
+	 * use 100ms as timeout time.
+	 */
+	if (!wait_event_timeout(vop->wait_dmc_queue,
+				!vop->dmc_in_process, HZ / 5))
+		dev_warn(vop->dev,
+			 "Timeout waiting for dmc when vop disable\n");
+
+	vop->vop_switch_status = 1;
+
+	/*
 	 * 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.
@@ -559,6 +634,25 @@ static void vop_crtc_disable(struct drm_crtc *crtc)
 
 		crtc->state->event = NULL;
 	}
+
+	vop->vop_switch_status = 0;
+	wake_up(&vop->wait_vop_switch_queue);
+
+	/* check how many vop use now */
+	drm_for_each_crtc(crtc, vop->drm_dev) {
+		if (crtc->state->enable)
+			num_enabled_crtc++;
+	}
+
+	/*
+	 * if num_enabled_crtc = 1 now, it means 2 vop enabled
+	 * change to 1 vop enabled  need to enable dmc again.
+	 */
+	if ((num_enabled_crtc == 1) && vop->devfreq) {
+		if (vop->devfreq_event_dev)
+			devfreq_event_enable_edev(vop->devfreq_event_dev);
+		devfreq_resume_device(vop->devfreq);
+	}
 }
 
 static void vop_plane_destroy(struct drm_plane *plane)
@@ -1406,6 +1500,8 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
 	struct drm_device *drm_dev = data;
 	struct vop *vop;
 	struct resource *res;
+	struct devfreq *devfreq;
+	struct devfreq_event_dev *event_dev;
 	size_t alloc_size;
 	int ret, irq;
 
@@ -1467,6 +1563,27 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
 		return ret;
 
 	pm_runtime_enable(&pdev->dev);
+
+	init_waitqueue_head(&vop->wait_vop_switch_queue);
+	vop->vop_switch_status = 0;
+	init_waitqueue_head(&vop->wait_dmc_queue);
+	vop->dmc_in_process = 0;
+
+	devfreq = devfreq_get_devfreq_by_phandle(dev, 0);
+	if (IS_ERR(devfreq))
+		goto out;
+
+	vop->devfreq = devfreq;
+	vop->dmc_nb.notifier_call = dmc_notify;
+	devfreq_register_notifier(vop->devfreq, &vop->dmc_nb,
+				  DEVFREQ_TRANSITION_NOTIFIER);
+
+	event_dev = devfreq_event_get_edev_by_phandle(vop->devfreq->dev.parent,
+						      0);
+	if (IS_ERR(event_dev))
+		goto out;
+	vop->devfreq_event_dev = event_dev;
+out:
 	return 0;
 }
 
Signature · 1 line
2.6.6
#18 lore raw

Re: [PATCH v6 8/8] drm/rockchip: Add dmc notifier in vop driver

Quoted 4 lines · Lin Huang

when in ddr frequency scaling process, vop can not do enable or disable operation, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled.

I'm a little confused by this. Does this mean you need vblank irq to be enabled all the time when vop is enabled? We regularly disable it when there aren't new fbs coming in.

Quoted 240 lines

So need register to devfreq notifier, and we can
get the dmc status.
Also, when there have two vop enabled, we need
to disable dmc, since dcf only base on one vop vblank time, so the other panel will flicker when do ddr frequency scaling.

---
Changes in v6:
- fix a build error

Changes in v5:
- improve some nits

Changes in v4:
- register notifier to devfreq_register_notifier
- use DEVFREQ_PRECHANGE and DEVFREQ_POSTCHANGE to get dmc status
- when two vop enable, disable dmc
- when two vop back to one vop, enable dmc

Changes in v3:
- when do vop eanble/disable, dmc will wait until it finish

Changes in v2:
- None

Changes in v1:
- use wait_event instead usleep

 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 121 +++++++++++++++++++++++++++-
 1 file changed, 119 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +119 -3
index 31744fe..199529e 100644
@@ -12,6 +12,8 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/devfreq.h>
+#include <linux/devfreq-event.h>
 #include <drm/drm.h>
 #include <drm/drmP.h>
 #include <drm/drm_atomic.h>
@@ -118,6 +120,13 @@ struct vop {
 
        const struct vop_data *data;
 
+       struct devfreq *devfreq;
+       struct devfreq_event_dev *devfreq_event_dev;
+       struct notifier_block dmc_nb;
+       int dmc_in_process;
+       int vop_switch_status;
+       wait_queue_head_t wait_dmc_queue;
+       wait_queue_head_t wait_vop_switch_queue;
        uint32_t *regsbak;
        void __iomem *regs;
 
@@ -428,21 +437,56 @@ 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 == DEVFREQ_PRECHANGE) {
+               /*
+                * check if vop in enable or disable process,
+                * if yes, wait until it finishes, use 200ms as
+                * timeout.
+                */
+               if (!wait_event_timeout(vop->wait_vop_switch_queue,
+                                       !vop->vop_switch_status, HZ / 5))
+                       dev_warn(vop->dev,
+                                "Timeout waiting for vop swtich status\n");
+               vop->dmc_in_process = 1;
+       } else if (event == DEVFREQ_POSTCHANGE) {
+               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);
+       int num_enabled_crtc = 0;
        int ret;
 
+       /*
+        * if in dmc scaling frequency process, wait until it finishes
+        * use 100ms as timeout time.
+        */
+       if (!wait_event_timeout(vop->wait_dmc_queue,
+                               !vop->dmc_in_process, HZ / 5))
+               dev_warn(vop->dev,
+                        "Timeout waiting for dmc when vop enable\n");
+
+       vop->vop_switch_status = 1;
        ret = pm_runtime_get_sync(vop->dev);
        if (ret < 0) {
                dev_err(vop->dev, "failed to get pm runtime: %d\n", ret);
-               return;
+               goto err;
        }
 
        ret = clk_enable(vop->hclk);
        if (ret < 0) {
                dev_err(vop->dev, "failed to enable hclk - %d\n", ret);
-               return;
+               goto err;
        }
 
        ret = clk_enable(vop->dclk);
@@ -485,6 +529,21 @@ static void vop_enable(struct drm_crtc *crtc)
 
        drm_crtc_vblank_on(crtc);
 
+       vop->vop_switch_status = 0;
+       wake_up(&vop->wait_vop_switch_queue);
+
+       /* check how many vop we use now */
+       drm_for_each_crtc(crtc, vop->drm_dev) {
+               if (crtc->state->enable)
+                       num_enabled_crtc++;
+       }
+
+       /* if enable two vop, need to disable dmc */
+       if ((num_enabled_crtc > 1) && vop->devfreq) {
+               if (vop->devfreq_event_dev)
+                       devfreq_event_disable_edev(vop->devfreq_event_dev);
+               devfreq_suspend_device(vop->devfreq);
+       }
        return;
 
 err_disable_aclk:
@@ -493,16 +552,32 @@ err_disable_dclk:
        clk_disable(vop->dclk);
 err_disable_hclk:
        clk_disable(vop->hclk);
+err:
+       vop->vop_switch_status = 0;
+       wake_up(&vop->wait_vop_switch_queue);
+       return;
 }
 
 static void vop_crtc_disable(struct drm_crtc *crtc)
 {
        struct vop *vop = to_vop(crtc);
+       int num_enabled_crtc = 0;
        int i;
 
        WARN_ON(vop->event);
 
        /*
+        * if in dmc scaling frequency process, wait until it finish
+        * use 100ms as timeout time.
+        */
+       if (!wait_event_timeout(vop->wait_dmc_queue,
+                               !vop->dmc_in_process, HZ / 5))
+               dev_warn(vop->dev,
+                        "Timeout waiting for dmc when vop disable\n");
+
+       vop->vop_switch_status = 1;
+
+       /*
         * 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.
@@ -559,6 +634,25 @@ static void vop_crtc_disable(struct drm_crtc *crtc)
 
                crtc->state->event = NULL;
        }
+
+       vop->vop_switch_status = 0;
+       wake_up(&vop->wait_vop_switch_queue);
+
+       /* check how many vop use now */
+       drm_for_each_crtc(crtc, vop->drm_dev) {
+               if (crtc->state->enable)
+                       num_enabled_crtc++;
+       }
+
+       /*
+        * if num_enabled_crtc = 1 now, it means 2 vop enabled
+        * change to 1 vop enabled  need to enable dmc again.
+        */
+       if ((num_enabled_crtc == 1) && vop->devfreq) {
+               if (vop->devfreq_event_dev)
+                       devfreq_event_enable_edev(vop->devfreq_event_dev);
+               devfreq_resume_device(vop->devfreq);
+       }
 }
 
 static void vop_plane_destroy(struct drm_plane *plane)
@@ -1406,6 +1500,8 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
        struct drm_device *drm_dev = data;
        struct vop *vop;
        struct resource *res;
+       struct devfreq *devfreq;
+       struct devfreq_event_dev *event_dev;
        size_t alloc_size;
        int ret, irq;
 
@@ -1467,6 +1563,27 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
                return ret;
 
        pm_runtime_enable(&pdev->dev);
+
+       init_waitqueue_head(&vop->wait_vop_switch_queue);
+       vop->vop_switch_status = 0;
+       init_waitqueue_head(&vop->wait_dmc_queue);
+       vop->dmc_in_process = 0;
+
+       devfreq = devfreq_get_devfreq_by_phandle(dev, 0);
+       if (IS_ERR(devfreq))
+               goto out;
+
+       vop->devfreq = devfreq;
+       vop->dmc_nb.notifier_call = dmc_notify;
+       devfreq_register_notifier(vop->devfreq, &vop->dmc_nb,
+                                 DEVFREQ_TRANSITION_NOTIFIER);
+
+       event_dev = devfreq_event_get_edev_by_phandle(vop->devfreq->dev.parent,
+                                                     0);
+       if (IS_ERR(event_dev))
+               goto out;
+       vop->devfreq_event_dev = event_dev;
+out:
        return 0;
 }
 
--

2.6.6

author
#19 lore raw

Re: [PATCH v6 8/8] drm/rockchip: Add dmc notifier in vop driver

Hi,

Quoted 8 lines · Sean Paul
Quoted 4 lines · Lin Huang

when in ddr frequency scaling process, vop can not do enable or disable operation, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled.

I'm a little confused by this. Does this mean you need vblank irq to be enabled all the time when vop is enabled? We regularly disable it when there aren't new fbs coming in.

maybe the commit message lead to misunderstanding, in dcf it will read the vop register to check whether is it in vblank status, if
not, it
will wait until it into vblank status. When vop enable, we need the vop clock enable, so we can read the vop register.

Quoted 244 lines
Quoted 242 lines

So need register to devfreq notifier, and we can
get the dmc status.
Also, when there have two vop enabled, we need
to disable dmc, since dcf only base on one vop vblank time, so the other panel will flicker when do ddr frequency scaling.

---
Changes in v6:
- fix a build error

Changes in v5:
- improve some nits

Changes in v4:
- register notifier to devfreq_register_notifier
- use DEVFREQ_PRECHANGE and DEVFREQ_POSTCHANGE to get dmc status
- when two vop enable, disable dmc
- when two vop back to one vop, enable dmc

Changes in v3:
- when do vop eanble/disable, dmc will wait until it finish

Changes in v2:
- None

Changes in v1:
- use wait_event instead usleep

  drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 121 +++++++++++++++++++++++++++-
  1 file changed, 119 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +119 -3
index 31744fe..199529e 100644
@@ -12,6 +12,8 @@
   * GNU General Public License for more details.
   */
 
+#include <linux/devfreq.h>
+#include <linux/devfreq-event.h>
  #include <drm/drm.h>
  #include <drm/drmP.h>
  #include <drm/drm_atomic.h>
@@ -118,6 +120,13 @@ struct vop {
 
         const struct vop_data *data;
 
+       struct devfreq *devfreq;
+       struct devfreq_event_dev *devfreq_event_dev;
+       struct notifier_block dmc_nb;
+       int dmc_in_process;
+       int vop_switch_status;
+       wait_queue_head_t wait_dmc_queue;
+       wait_queue_head_t wait_vop_switch_queue;
         uint32_t *regsbak;
         void __iomem *regs;
 
@@ -428,21 +437,56 @@ 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 == DEVFREQ_PRECHANGE) {
+               /*
+                * check if vop in enable or disable process,
+                * if yes, wait until it finishes, use 200ms as
+                * timeout.
+                */
+               if (!wait_event_timeout(vop->wait_vop_switch_queue,
+                                       !vop->vop_switch_status, HZ / 5))
+                       dev_warn(vop->dev,
+                                "Timeout waiting for vop swtich status\n");
+               vop->dmc_in_process = 1;
+       } else if (event == DEVFREQ_POSTCHANGE) {
+               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);
+       int num_enabled_crtc = 0;
         int ret;
 
+       /*
+        * if in dmc scaling frequency process, wait until it finishes
+        * use 100ms as timeout time.
+        */
+       if (!wait_event_timeout(vop->wait_dmc_queue,
+                               !vop->dmc_in_process, HZ / 5))
+               dev_warn(vop->dev,
+                        "Timeout waiting for dmc when vop enable\n");
+
+       vop->vop_switch_status = 1;
         ret = pm_runtime_get_sync(vop->dev);
         if (ret < 0) {
                 dev_err(vop->dev, "failed to get pm runtime: %d\n", ret);
-               return;
+               goto err;
         }
 
         ret = clk_enable(vop->hclk);
         if (ret < 0) {
                 dev_err(vop->dev, "failed to enable hclk - %d\n", ret);
-               return;
+               goto err;
         }
 
         ret = clk_enable(vop->dclk);
@@ -485,6 +529,21 @@ static void vop_enable(struct drm_crtc *crtc)
 
         drm_crtc_vblank_on(crtc);
 
+       vop->vop_switch_status = 0;
+       wake_up(&vop->wait_vop_switch_queue);
+
+       /* check how many vop we use now */
+       drm_for_each_crtc(crtc, vop->drm_dev) {
+               if (crtc->state->enable)
+                       num_enabled_crtc++;
+       }
+
+       /* if enable two vop, need to disable dmc */
+       if ((num_enabled_crtc > 1) && vop->devfreq) {
+               if (vop->devfreq_event_dev)
+                       devfreq_event_disable_edev(vop->devfreq_event_dev);
+               devfreq_suspend_device(vop->devfreq);
+       }
         return;
 
  err_disable_aclk:
@@ -493,16 +552,32 @@ err_disable_dclk:
         clk_disable(vop->dclk);
  err_disable_hclk:
         clk_disable(vop->hclk);
+err:
+       vop->vop_switch_status = 0;
+       wake_up(&vop->wait_vop_switch_queue);
+       return;
  }
 
  static void vop_crtc_disable(struct drm_crtc *crtc)
  {
         struct vop *vop = to_vop(crtc);
+       int num_enabled_crtc = 0;
         int i;
 
         WARN_ON(vop->event);
 
         /*
+        * if in dmc scaling frequency process, wait until it finish
+        * use 100ms as timeout time.
+        */
+       if (!wait_event_timeout(vop->wait_dmc_queue,
+                               !vop->dmc_in_process, HZ / 5))
+               dev_warn(vop->dev,
+                        "Timeout waiting for dmc when vop disable\n");
+
+       vop->vop_switch_status = 1;
+
+       /*
          * 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.
@@ -559,6 +634,25 @@ static void vop_crtc_disable(struct drm_crtc *crtc)
 
                 crtc->state->event = NULL;
         }
+
+       vop->vop_switch_status = 0;
+       wake_up(&vop->wait_vop_switch_queue);
+
+       /* check how many vop use now */
+       drm_for_each_crtc(crtc, vop->drm_dev) {
+               if (crtc->state->enable)
+                       num_enabled_crtc++;
+       }
+
+       /*
+        * if num_enabled_crtc = 1 now, it means 2 vop enabled
+        * change to 1 vop enabled  need to enable dmc again.
+        */
+       if ((num_enabled_crtc == 1) && vop->devfreq) {
+               if (vop->devfreq_event_dev)
+                       devfreq_event_enable_edev(vop->devfreq_event_dev);
+               devfreq_resume_device(vop->devfreq);
+       }
  }
 
  static void vop_plane_destroy(struct drm_plane *plane)
@@ -1406,6 +1500,8 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
         struct drm_device *drm_dev = data;
         struct vop *vop;
         struct resource *res;
+       struct devfreq *devfreq;
+       struct devfreq_event_dev *event_dev;
         size_t alloc_size;
         int ret, irq;
 
@@ -1467,6 +1563,27 @@ static int vop_bind(struct device *dev, struct device *master, void *data)
                 return ret;
 
         pm_runtime_enable(&pdev->dev);
+
+       init_waitqueue_head(&vop->wait_vop_switch_queue);
+       vop->vop_switch_status = 0;
+       init_waitqueue_head(&vop->wait_dmc_queue);
+       vop->dmc_in_process = 0;
+
+       devfreq = devfreq_get_devfreq_by_phandle(dev, 0);
+       if (IS_ERR(devfreq))
+               goto out;
+
+       vop->devfreq = devfreq;
+       vop->dmc_nb.notifier_call = dmc_notify;
+       devfreq_register_notifier(vop->devfreq, &vop->dmc_nb,
+                                 DEVFREQ_TRANSITION_NOTIFIER);
+
+       event_dev = devfreq_event_get_edev_by_phandle(vop->devfreq->dev.parent,
+                                                     0);
+       if (IS_ERR(event_dev))
+               goto out;
+       vop->devfreq_event_dev = event_dev;
+out:
         return 0;
  }
 
--

2.6.6

Signature · 1 line
Lin Huang