Skip to contentSkip to conversation

drm/msm+clk: handover of bootloader display

RFC In review Rob Clark 4 participants 10 messages Jul 11, 2017 – Jul 18, 2017

Subsystems (8)
lore
Share & tools
lore

Rob Clark

author
#0 lore raw

cover drm/msm+clk: handover of bootloader display

So now that this is working (at least on a single device), I figured it was a good time to send out an RFC to start discussion about how to do this properly, in particular the CCF/powerdomain parts.

The first patch adds flags so we can mark power domains and leaf node clocks which might (or might not) be enabled by bootloader and which we want to inherit when real display driver is probed. (There might be use-cases outside of display.. such as debug serial port? I guess display is the most common/complex/useful use-case.) From the CCF/genpd standpoint, "inherit" really just means "fixup enable/ prepare_count and don't automatically switch off in lateinit". The rest of the complexity is in the display driver.

For display, there are two different cases depending on whether the display driver is built as a module (ie. probes after lateinit) or not. If the display driver is built as a module, then we want efifb to keep working after the clk_disable_unused + genpd_power_off_unused late_initcall's. And in either case, we want the display driver to be able to detect that display is already on (by checking whether various clocks are already enabled) so that it knows to readback the hw state. (And not try to do things like clk_set_rate() on already running clocks.)

Right now this is working on 8x16 (dragonboard 410c). I'm not sure if we'll hit more issues in CCF with more complex devices due to separate GCC and MMCC clock controllers (a bit fuzzy on how things work with initially unparented clocks, if for example MMCC probes before it's GCC parent clocks.. and in general I am by no means an expert about the common clock framework). Certainly I'd like to hear suggestions about how to procede on the CCF/genpd front.

I am aware of another similar RFC[1]. Although on most of the snapdragon devices you can in theory enable/disable the bootloader splashscreen via a 'fastboot oem select-display-panel' command, so I think whatever solution we have needs to introspect the hw to decide what to do.

The latest version of these patches (plus various cleanups/etc that they depend on) can be found here[2]

[1] https://lkml.org/lkml/2017/6/28/188
[2] https://github.com/freedreno/kernel-msm/commits/display-handover

Rob Clark (3):
clk: inherit display clocks enabled by bootloader drm/msm: inherit display from bootloader drm/bridge: adv7511: deal with bootloader lighting up display

 drivers/clk/clk.c                               |  18 ++++
 drivers/clk/qcom/common.c                       |  28 +++++
 drivers/clk/qcom/gcc-msm8916.c                  |  15 +--
 drivers/clk/qcom/gdsc.c                         |   6 ++
 drivers/clk/qcom/gdsc.h                         |   1 +
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c    |  57 ++++++----
 drivers/gpu/drm/bridge/adv7511/adv7533.c        |   3 +
 drivers/gpu/drm/msm/dsi/dsi.h                   |   1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c              |  32 ++++++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c           |   5 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h           |   1 +
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c      |   2 +
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c      |   2 +
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c |   2 +
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_cmd_encoder.c |   8 ++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c        |  21 ++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_ctl.c         |  48 +++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_ctl.h         |   3 +
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_encoder.c     | 132 ++++++++++++++++++++++--
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c         |  79 +++++++++++++-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h         |  11 ++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c       |  79 ++++++++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.c         |  45 ++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.h         |   2 +
 drivers/gpu/drm/msm/msm_drv.c                   |   3 +
 drivers/gpu/drm/msm/msm_drv.h                   |   2 +
 drivers/gpu/drm/msm/msm_fbdev.c                 |  15 ++-
 drivers/gpu/drm/msm/msm_kms.h                   |   2 +
 include/linux/clk-provider.h                    |   1 +
 include/linux/clk.h                             |   9 ++
 30 files changed, 591 insertions(+), 42 deletions(-)
Signature · 1 line
2.13.0
author
#1 lore raw

RFC 1/3 clk: inherit display clocks enabled by bootloader

The goal here is to support inheriting a display setup by bootloader, although there may also be some non-display related use-cases.

Rough idea is to add a flag for clks and power domains that might already be enabled when kernel starts, and make corresponding fixups to clk enable/prepare_count and power-domain state so that these are not automatically disabled late in boot.

If bootloader is enabling display, and kernel is using efifb before real display driver is loaded (potentially from kernel module after userspace starts, in a typical distro kernel), we don't want to kill the clocks and power domains that are used by the display before userspace starts.

Second part is for drm/msm to check if display related clocks are enabled when it is loaded, and if so read back hw state to sync existing display state w/ software state, and skip the initial clk_enable's and otherwise fixing up clk/regulator/etc ref counts (skipping the normal display-enable codepaths), therefore inheriting the enable done by bootloader.

Obviously this should be split up into multiple patches and many TODOs addressed. But I guess this is enough for now to start discussing the approach, and in particular how drm and clock/pd drivers work together to handle handover from bootloader.

The CLK_INHERIT_BOOTLOADER and related gsdc flag should only be set on leaf nodes.

---
 drivers/clk/clk.c              | 18 ++++++++++++++++++
 drivers/clk/qcom/common.c      | 28 ++++++++++++++++++++++++++++
 drivers/clk/qcom/gcc-msm8916.c | 15 ++++++++-------
 drivers/clk/qcom/gdsc.c        |  6 ++++++
 drivers/clk/qcom/gdsc.h        |  1 +
 include/linux/clk-provider.h   |  1 +
 include/linux/clk.h            |  9 +++++++++
 7 files changed, 71 insertions(+), 7 deletions(-)
drivers/clk/clk.c +18 -0
index fc58c52a26b4..7c84e8d6e816 100644
@@ -796,6 +796,24 @@ static void clk_disable_unused_subtree(struct clk_core *core)
 		clk_core_disable_unprepare(core->parent);
 }
 
+/* clock and it's parents are already prepared/enabled from bootloader,
+ * so simply record the fact.
+ */
+static void __clk_inherit_enabled(struct clk_core *core)
+{
+	core->enable_count++;
+	core->prepare_count++;
+if (core->hw->init->name) // XXX hack.. something funny with xo/xo_board..
+	if (core->parent)
+		__clk_inherit_enabled(core->parent);
+}
+
+void clk_inherit_enabled(struct clk *clk)
+{
+	__clk_inherit_enabled(clk->core);
+}
+EXPORT_SYMBOL_GPL(clk_inherit_enabled);
+
 static bool clk_ignore_unused;
 static int __init clk_ignore_unused_setup(char *__unused)
 {
drivers/clk/qcom/common.c +28 -0
index d523991c945f..90b698c910d0 100644
@@ -11,6 +11,7 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
@@ -258,6 +259,33 @@ int qcom_cc_really_probe(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
+	/* Check which of clocks that we inherit state from bootloader
+	 * are enabled, and fixup enable/prepare state (as well as that
+	 * of it's parents).
+	 *
+	 * TODO can we assume that parents coming from another clk
+	 * driver are already registered?
+	 */
+	for (i = 0; i < num_clks; i++) {
+		struct clk_hw *hw;
+
+		if (!rclks[i])
+			continue;
+
+		hw = &rclks[i]->hw;
+
+		if (!(hw->init->flags & CLK_INHERIT_BOOTLOADER))
+			continue;
+
+		if (!clk_is_enabled_regmap(hw))
+			continue;
+
+		dev_dbg(dev, "%s is enabled from bootloader!\n",
+			  hw->init->name);
+
+		clk_inherit_enabled(hw->clk);
+	}
+
 	reset = &cc->reset;
 	reset->rcdev.of_node = dev->of_node;
 	reset->rcdev.ops = &qcom_reset_ops;
drivers/clk/qcom/gcc-msm8916.c +8 -7
index 2cfe7000fc60..c939d33f6377 100644
@@ -2468,7 +2468,7 @@ static struct clk_branch gcc_mdss_ahb_clk = {
 				"pcnoc_bfdcd_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -2485,7 +2485,7 @@ static struct clk_branch gcc_mdss_axi_clk = {
 				"system_noc_bfdcd_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -2502,7 +2502,7 @@ static struct clk_branch gcc_mdss_byte0_clk = {
 				"byte0_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -2519,7 +2519,7 @@ static struct clk_branch gcc_mdss_esc0_clk = {
 				"esc0_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -2536,7 +2536,7 @@ static struct clk_branch gcc_mdss_mdp_clk = {
 				"mdp_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -2553,7 +2553,7 @@ static struct clk_branch gcc_mdss_pclk0_clk = {
 				"pclk0_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -2570,7 +2570,7 @@ static struct clk_branch gcc_mdss_vsync_clk = {
 				"vsync_clk_src",
 			},
 			.num_parents = 1,
-			.flags = CLK_SET_RATE_PARENT,
+			.flags = CLK_SET_RATE_PARENT | CLK_INHERIT_BOOTLOADER,
 			.ops = &clk_branch2_ops,
 		},
 	},
@@ -3060,6 +3060,7 @@ static struct gdsc mdss_gdsc = {
 		.name = "mdss",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = INHERIT_BL,
 };
 
 static struct gdsc jpeg_gdsc = {
drivers/clk/qcom/gdsc.c +6 -0
index a4f3580587b7..440d819b2d9d 100644
@@ -291,6 +291,12 @@ static int gdsc_init(struct gdsc *sc)
 	if ((sc->flags & VOTABLE) && on)
 		gdsc_enable(&sc->pd);
 
+	if ((sc->flags & INHERIT_BL) && on) {
+		pr_debug("gdsc: %s is enabled from bootloader!\n", sc->pd.name);
+		gdsc_enable(&sc->pd);
+		sc->pd.flags |= GENPD_FLAG_ALWAYS_ON;
+	}
+
 	if (on || (sc->pwrsts & PWRSTS_RET))
 		gdsc_force_mem_on(sc);
 	else
drivers/clk/qcom/gdsc.h +1 -0
index 39648348e5ec..3b5e64b060c2 100644
@@ -53,6 +53,7 @@ struct gdsc {
 #define VOTABLE		BIT(0)
 #define CLAMP_IO	BIT(1)
 #define HW_CTRL		BIT(2)
+#define INHERIT_BL	BIT(3)
 	struct reset_controller_dev	*rcdev;
 	unsigned int			*resets;
 	unsigned int			reset_count;
include/linux/clk-provider.h +1 -0
index c59c62571e4f..4d5505f92329 100644
@@ -35,6 +35,7 @@
 #define CLK_IS_CRITICAL		BIT(11) /* do not gate, ever */
 /* parents need enable during gate/ungate, set rate and re-parent */
 #define CLK_OPS_PARENT_ENABLE	BIT(12)
+#define CLK_INHERIT_BOOTLOADER	BIT(13) /* clk may be enabled from bootloader */
 
 struct clk;
 struct clk_hw;
include/linux/clk.h +9 -0
index 91bd464f4c9b..461991fc57e2 100644
@@ -391,6 +391,15 @@ void clk_disable(struct clk *clk);
 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
 
 /**
+ * clk_inherit_enabled - update the enable/prepare count of a clock and it's
+ * parents for clock enabled by bootloader.
+ *
+ * Intended to be used by clock drivers to inform the clk core of a clock
+ * that is already running.
+ */
+void clk_inherit_enabled(struct clk *clk);
+
+/**
  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
  *		  This is only valid once the clock source has been enabled.
  * @clk: clock source
Signature · 1 line
2.13.0
#2 lore raw

Re: [RFC 1/3] clk: inherit display clocks enabled by bootloader

Hi Rob,

Quoted 21 lines · Rob Clark

The goal here is to support inheriting a display setup by bootloader, although there may also be some non-display related use-cases.

Rough idea is to add a flag for clks and power domains that might already be enabled when kernel starts, and make corresponding fixups to clk enable/prepare_count and power-domain state so that these are not automatically disabled late in boot.

If bootloader is enabling display, and kernel is using efifb before real display driver is loaded (potentially from kernel module after userspace starts, in a typical distro kernel), we don't want to kill the clocks and power domains that are used by the display before userspace starts.

Second part is for drm/msm to check if display related clocks are enabled when it is loaded, and if so read back hw state to sync existing display state w/ software state, and skip the initial clk_enable's and otherwise fixing up clk/regulator/etc ref counts (skipping the normal display-enable codepaths), therefore inheriting the enable done by bootloader.

Quoted 8 lines

Obviously this should be split up into multiple patches and many TODOs addressed. But I guess this is enough for now to start discussing the approach, and in particular how drm and clock/pd drivers work together to handle handover from bootloader.

The CLK_INHERIT_BOOTLOADER and related gsdc flag should only be set on leaf nodes.
---

[]..

Quoted 31 lines
drivers/clk/qcom/common.c +16 -0
index d523991c945f..90b698c910d0 100644
@@ -11,6 +11,7 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
@@ -258,6 +259,33 @@ int qcom_cc_really_probe(struct platform_device *pdev,
 	if (ret)
 		return ret;
 
+	/* Check which of clocks that we inherit state from bootloader
+	 * are enabled, and fixup enable/prepare state (as well as that
+	 * of it's parents).
+	 *
+	 * TODO can we assume that parents coming from another clk
+	 * driver are already registered?
+	 */
+	for (i = 0; i < num_clks; i++) {
+		struct clk_hw *hw;
+
+		if (!rclks[i])
+			continue;
+
+		hw = &rclks[i]->hw;
+

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 286

Quoted 10 lines
drivers/clk/qcom/common.c +10 -0
+		if (!(hw->init->flags & CLK_INHERIT_BOOTLOADER))
+			continue;
+
+		if (!clk_is_enabled_regmap(hw))
+			continue;
+
+		dev_dbg(dev, "%s is enabled from bootloader!\n",
+			  hw->init->name);
+
+		clk_inherit_enabled(hw->clk);

how about just calling a clk_prepare_enable(hw->clk) instead of adding a new API? The flag could also be something qcom specific and then we avoid having to add anything in generic CCF code and its all handled in the qcom clock drivers.

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 291

Quoted 5 lines
drivers/clk/qcom/common.c +2 -0
+	}
+
 	reset = &cc->reset;
 	reset->rcdev.of_node = dev->of_node;
 	reset->rcdev.ops = &qcom_reset_ops;

[] ..

drivers/clk/qcom/gdsc.c static int gdsc_init(struct gdsc *sc) · line 297

Quoted 12 lines
drivers/clk/qcom/gdsc.c +4 -0
index a4f3580587b7..440d819b2d9d 100644
@@ -291,6 +291,12 @@ static int gdsc_init(struct gdsc *sc)
 	if ((sc->flags & VOTABLE) && on)
 		gdsc_enable(&sc->pd);
 
+	if ((sc->flags & INHERIT_BL) && on) {
+		pr_debug("gdsc: %s is enabled from bootloader!\n", sc->pd.name);
+		gdsc_enable(&sc->pd);
+		sc->pd.flags |= GENPD_FLAG_ALWAYS_ON;

Would this not prevent the powerdomain from ever getting disabled?

regards,
Rajendra

Quoted 50 lines
drivers/clk/qcom/gdsc.c +2 -0
+	}
+
 	if (on || (sc->pwrsts & PWRSTS_RET))
 		gdsc_force_mem_on(sc);
 	else
drivers/clk/qcom/gdsc.h +1 -0
index 39648348e5ec..3b5e64b060c2 100644
@@ -53,6 +53,7 @@ struct gdsc {
 #define VOTABLE		BIT(0)
 #define CLAMP_IO	BIT(1)
 #define HW_CTRL		BIT(2)
+#define INHERIT_BL	BIT(3)
 	struct reset_controller_dev	*rcdev;
 	unsigned int			*resets;
 	unsigned int			reset_count;
include/linux/clk-provider.h +1 -0
index c59c62571e4f..4d5505f92329 100644
@@ -35,6 +35,7 @@
 #define CLK_IS_CRITICAL		BIT(11) /* do not gate, ever */
 /* parents need enable during gate/ungate, set rate and re-parent */
 #define CLK_OPS_PARENT_ENABLE	BIT(12)
+#define CLK_INHERIT_BOOTLOADER	BIT(13) /* clk may be enabled from bootloader */
 
 struct clk;
 struct clk_hw;
include/linux/clk.h +9 -0
index 91bd464f4c9b..461991fc57e2 100644
@@ -391,6 +391,15 @@ void clk_disable(struct clk *clk);
 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
 
 /**
+ * clk_inherit_enabled - update the enable/prepare count of a clock and it's
+ * parents for clock enabled by bootloader.
+ *
+ * Intended to be used by clock drivers to inform the clk core of a clock
+ * that is already running.
+ */
+void clk_inherit_enabled(struct clk *clk);
+
+/**
  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
  *		  This is only valid once the clock source has been enabled.
  * @clk: clock source
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
author
#3 lore raw

Re: [RFC 1/3] clk: inherit display clocks enabled by bootloader

Quoted 72 lines · Rajendra Nayak

Hi Rob,

Quoted 21 lines · Rob Clark

The goal here is to support inheriting a display setup by bootloader, although there may also be some non-display related use-cases.

Rough idea is to add a flag for clks and power domains that might already be enabled when kernel starts, and make corresponding fixups to clk enable/prepare_count and power-domain state so that these are not automatically disabled late in boot.

If bootloader is enabling display, and kernel is using efifb before real display driver is loaded (potentially from kernel module after userspace starts, in a typical distro kernel), we don't want to kill the clocks and power domains that are used by the display before userspace starts.

Second part is for drm/msm to check if display related clocks are enabled when it is loaded, and if so read back hw state to sync existing display state w/ software state, and skip the initial clk_enable's and otherwise fixing up clk/regulator/etc ref counts (skipping the normal display-enable codepaths), therefore inheriting the enable done by bootloader.

Quoted 8 lines

Obviously this should be split up into multiple patches and many TODOs addressed. But I guess this is enough for now to start discussing the approach, and in particular how drm and clock/pd drivers work together to handle handover from bootloader.

The CLK_INHERIT_BOOTLOADER and related gsdc flag should only be set on leaf nodes.
---

[]..

Quoted 37 lines
drivers/clk/qcom/common.c +22 -0
index d523991c945f..90b698c910d0 100644
@@ -11,6 +11,7 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
@@ -258,6 +259,33 @@ int qcom_cc_really_probe(struct platform_device *pdev,
      if (ret)
              return ret;
 
+     /* Check which of clocks that we inherit state from bootloader
+      * are enabled, and fixup enable/prepare state (as well as that
+      * of it's parents).
+      *
+      * TODO can we assume that parents coming from another clk
+      * driver are already registered?
+      */
+     for (i = 0; i < num_clks; i++) {
+             struct clk_hw *hw;
+
+             if (!rclks[i])
+                     continue;
+
+             hw = &rclks[i]->hw;
+
+             if (!(hw->init->flags & CLK_INHERIT_BOOTLOADER))
+                     continue;
+
+             if (!clk_is_enabled_regmap(hw))
+                     continue;
+
Quoted 8 lines

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 286

Quoted 4 lines
drivers/clk/qcom/common.c +4 -0
+             dev_dbg(dev, "%s is enabled from bootloader!\n",
+                       hw->init->name);
+
+             clk_inherit_enabled(hw->clk);

how about just calling a clk_prepare_enable(hw->clk) instead of adding a new API? The flag could also be something qcom specific and then we avoid having to add anything in generic CCF code and its all handled in the qcom clock drivers.

Hmm, I could try that.. I *guess* it doesn't hurt to enable an already enabled clk..

beyond that, I wonder if this is something that other platforms would want, so maybe I should be doing the check for enabled in CCF core? If not, making this a qcom specific flag makes sense.

Quoted 16 lines

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 291

Quoted 5 lines
drivers/clk/qcom/common.c +2 -0
+     }
+
      reset = &cc->reset;
      reset->rcdev.of_node = dev->of_node;
      reset->rcdev.ops = &qcom_reset_ops;

[] ..

Quoted 8 lines
drivers/clk/qcom/gdsc.c +0 -0
index a4f3580587b7..440d819b2d9d 100644
@@ -291,6 +291,12 @@ static int gdsc_init(struct gdsc *sc)
      if ((sc->flags & VOTABLE) && on)
              gdsc_enable(&sc->pd);
 
Quoted 6 lines

drivers/clk/qcom/gdsc.c static int gdsc_init(struct gdsc *sc) · line 297

Quoted 4 lines
drivers/clk/qcom/gdsc.c +4 -0
+     if ((sc->flags & INHERIT_BL) && on) {
+             pr_debug("gdsc: %s is enabled from bootloader!\n", sc->pd.name);
+             gdsc_enable(&sc->pd);
+             sc->pd.flags |= GENPD_FLAG_ALWAYS_ON;

Would this not prevent the powerdomain from ever getting disabled?

Yeah, this is a hack, because I couldn't figure out something better. The problem is that gdsc/powerdomain doesn't have it's own enable_count but this is tracked at the device level (afaict.. maybe I'm miss-understanding something). I guess we could add our own enable_count within gdsc? Suggestions welcome, since I don't know these parts of the code so well.

BR,
-R

Quoted 57 lines

regards,
Rajendra

Quoted 40 lines
drivers/clk/qcom/gdsc.c +2 -0
+     }
+
      if (on || (sc->pwrsts & PWRSTS_RET))
              gdsc_force_mem_on(sc);
      else
drivers/clk/qcom/gdsc.h +1 -0
index 39648348e5ec..3b5e64b060c2 100644
@@ -53,6 +53,7 @@ struct gdsc {
 #define VOTABLE              BIT(0)
 #define CLAMP_IO     BIT(1)
 #define HW_CTRL              BIT(2)
+#define INHERIT_BL   BIT(3)
      struct reset_controller_dev     *rcdev;
      unsigned int                    *resets;
      unsigned int                    reset_count;
include/linux/clk-provider.h +1 -0
index c59c62571e4f..4d5505f92329 100644
@@ -35,6 +35,7 @@
 #define CLK_IS_CRITICAL              BIT(11) /* do not gate, ever */
 /* parents need enable during gate/ungate, set rate and re-parent */
 #define CLK_OPS_PARENT_ENABLE        BIT(12)
+#define CLK_INHERIT_BOOTLOADER       BIT(13) /* clk may be enabled from bootloader */
 
 struct clk;
 struct clk_hw;
include/linux/clk.h +2 -0
index 91bd464f4c9b..461991fc57e2 100644
@@ -391,6 +391,15 @@ void clk_disable(struct clk *clk);
 void clk_bulk_disable(int num_clks, const struct clk_bulk_data *clks);
 
 /**
+ * clk_inherit_enabled - update the enable/prepare count of a clock and it's
+ * parents for clock enabled by bootloader.

include/linux/clk.h void clk_disable(struct clk *clk); · line 405

Quoted 10 lines
include/linux/clk.h +7 -0
+ *
+ * Intended to be used by clock drivers to inform the clk core of a clock
+ * that is already running.
+ */
+void clk_inherit_enabled(struct clk *clk);
+
+/**
  * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
  *             This is only valid once the clock source has been enabled.
  * @clk: clock source

--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#4 lore raw

Re: [RFC 1/3] clk: inherit display clocks enabled by bootloader

Quoted 82 lines · Rob Clark
Quoted 72 lines · Rajendra Nayak

Hi Rob,

Quoted 21 lines · Rob Clark

The goal here is to support inheriting a display setup by bootloader, although there may also be some non-display related use-cases.

Rough idea is to add a flag for clks and power domains that might already be enabled when kernel starts, and make corresponding fixups to clk enable/prepare_count and power-domain state so that these are not automatically disabled late in boot.

If bootloader is enabling display, and kernel is using efifb before real display driver is loaded (potentially from kernel module after userspace starts, in a typical distro kernel), we don't want to kill the clocks and power domains that are used by the display before userspace starts.

Second part is for drm/msm to check if display related clocks are enabled when it is loaded, and if so read back hw state to sync existing display state w/ software state, and skip the initial clk_enable's and otherwise fixing up clk/regulator/etc ref counts (skipping the normal display-enable codepaths), therefore inheriting the enable done by bootloader.

Quoted 8 lines

Obviously this should be split up into multiple patches and many TODOs addressed. But I guess this is enough for now to start discussing the approach, and in particular how drm and clock/pd drivers work together to handle handover from bootloader.

The CLK_INHERIT_BOOTLOADER and related gsdc flag should only be set on leaf nodes.
---

[]..

Quoted 37 lines
drivers/clk/qcom/common.c +22 -0
index d523991c945f..90b698c910d0 100644
@@ -11,6 +11,7 @@
   * GNU General Public License for more details.
   */
 
+#include <linux/clk.h>
  #include <linux/export.h>
  #include <linux/module.h>
  #include <linux/regmap.h>
@@ -258,6 +259,33 @@ int qcom_cc_really_probe(struct platform_device *pdev,
       if (ret)
               return ret;
 
+     /* Check which of clocks that we inherit state from bootloader
+      * are enabled, and fixup enable/prepare state (as well as that
+      * of it's parents).
+      *
+      * TODO can we assume that parents coming from another clk
+      * driver are already registered?
+      */
+     for (i = 0; i < num_clks; i++) {
+             struct clk_hw *hw;
+
+             if (!rclks[i])
+                     continue;
+
+             hw = &rclks[i]->hw;
+
+             if (!(hw->init->flags & CLK_INHERIT_BOOTLOADER))
+                     continue;
+
+             if (!clk_is_enabled_regmap(hw))
+                     continue;
+
Quoted 8 lines

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 286

Quoted 4 lines
drivers/clk/qcom/common.c +4 -0
+             dev_dbg(dev, "%s is enabled from bootloader!\n",
+                       hw->init->name);
+
+             clk_inherit_enabled(hw->clk);

how about just calling a clk_prepare_enable(hw->clk) instead of adding a new API? The flag could also be something qcom specific and then we avoid having to add anything in generic CCF code and its all handled in the qcom clock drivers.

Quoted 2 lines

Hmm, I could try that.. I *guess* it doesn't hurt to enable an already enabled clk..

yes, ideally it shouldn't hurt.

Quoted 4 lines

beyond that, I wonder if this is something that other platforms would want, so maybe I should be doing the check for enabled in CCF core? If not, making this a qcom specific flag makes sense.

I think most previous attempts to solve this were done trying to keep it very generic and they didn't go too far.
So I was thinking maybe we could deal with it within qcom drivers for now, and if others come up with something similar, then look to consolidate at a generic CCF level.

Quoted 24 lines
Quoted 17 lines

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 291

Quoted 6 lines
drivers/clk/qcom/common.c +2 -0
+     }
+
       reset = &cc->reset;
       reset->rcdev.of_node = dev->of_node;
       reset->rcdev.ops = &qcom_reset_ops;

[] ..

Quoted 8 lines
drivers/clk/qcom/gdsc.c +0 -0
index a4f3580587b7..440d819b2d9d 100644
@@ -291,6 +291,12 @@ static int gdsc_init(struct gdsc *sc)
       if ((sc->flags & VOTABLE) && on)
               gdsc_enable(&sc->pd);
 
Quoted 6 lines

drivers/clk/qcom/gdsc.c static int gdsc_init(struct gdsc *sc) · line 297

Quoted 4 lines
drivers/clk/qcom/gdsc.c +4 -0
+     if ((sc->flags & INHERIT_BL) && on) {
+             pr_debug("gdsc: %s is enabled from bootloader!\n", sc->pd.name);
+             gdsc_enable(&sc->pd);
+             sc->pd.flags |= GENPD_FLAG_ALWAYS_ON;

Would this not prevent the powerdomain from ever getting disabled?

Quoted 6 lines

Yeah, this is a hack, because I couldn't figure out something better. The problem is that gdsc/powerdomain doesn't have it's own enable_count but this is tracked at the device level (afaict.. maybe I'm miss-understanding something). I guess we could add our own enable_count within gdsc? Suggestions welcome, since I don't know these parts of the code so well.

One way to deal with it would be to tell the genpd core, that the gdsc isn't really enabled, so it does not go ahead and disable it thinking its unused.

Once the display driver comes up, it runtime enables/disables it. I am guessing, if the bootloader turns on the gdsc, there will also be a kernel driver to handle it.

So I am basically saying,
if ((sc->flags & INHERIT_BL) && on)
on = !on; /* Prevent genpd from thinking its unsued */

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [RFC 1/3] clk: inherit display clocks enabled by bootloader

Quoted 54 lines · Rajendra
Quoted 51 lines · Rob Clark
Quoted 49 lines · Rajendra Nayak

Hi Rob,

Quoted 31 lines · Rob Clark
drivers/clk/qcom/common.c +16 -0
index d523991c945f..90b698c910d0 100644
@@ -11,6 +11,7 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/clk.h>
 #include <linux/export.h>
 #include <linux/module.h>
 #include <linux/regmap.h>
@@ -258,6 +259,33 @@ int qcom_cc_really_probe(struct platform_device *pdev,
      if (ret)
              return ret;
 
+     /* Check which of clocks that we inherit state from bootloader
+      * are enabled, and fixup enable/prepare state (as well as that
+      * of it's parents).
+      *
+      * TODO can we assume that parents coming from another clk
+      * driver are already registered?
+      */
+     for (i = 0; i < num_clks; i++) {
+             struct clk_hw *hw;
+
+             if (!rclks[i])
+                     continue;
+
+             hw = &rclks[i]->hw;
+

drivers/clk/qcom/common.c int qcom_cc_really_probe(struct platform_device *pdev, · line 286

Quoted 10 lines
drivers/clk/qcom/common.c +10 -0
+             if (!(hw->init->flags & CLK_INHERIT_BOOTLOADER))
+                     continue;
+
+             if (!clk_is_enabled_regmap(hw))
+                     continue;
+
+             dev_dbg(dev, "%s is enabled from bootloader!\n",
+                       hw->init->name);
+
+             clk_inherit_enabled(hw->clk);

how about just calling a clk_prepare_enable(hw->clk) instead of adding a new API? The flag could also be something qcom specific and then we avoid having to add anything in generic CCF code and its all handled in the qcom clock drivers.

Quoted 4 lines
Quoted 2 lines

Hmm, I could try that.. I *guess* it doesn't hurt to enable an already enabled clk..

yes, ideally it shouldn't hurt.

It hurts when you enable a PLL when it's already enabled. I recall having to add code specifically for this reason to avoid enabling a PLL that is already enabled out of the bootloader. But that's because the enable sequence for a PLL is multiple writes that first keep the output off and then turn it back on after things stabilize. For RCGs this isn't the case.

Quoted 11 lines
Quoted 5 lines

beyond that, I wonder if this is something that other platforms would want, so maybe I should be doing the check for enabled in CCF core? If not, making this a qcom specific flag makes sense.

I think most previous attempts to solve this were done trying to keep it very generic and they didn't go too far.
So I was thinking maybe we could deal with it within qcom drivers for now, and if others come up with something similar, then look to consolidate at a generic CCF level.

We know that other SoC vendors need handoff features as well, so there will definitely be a point where we need to consolidate at the framework level. Working something up that works for qcom would be good to try out though to find edge cases, etc.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#6 lore raw

RFC 2/3 drm/msm: inherit display from bootloader

In reply to Rob Clark

It is quite common for bootloader to enable display on tablets/phones. But until now for upstream kernel we've been ignoring that since it highly confuses drm/msm, and recommending to disable the bootloader display. (Otherwise we end up trying to set rates on already enabled clks and all sorts of similar fun.) But to get grub graphical boot menu to work (and also efifb for early boot), we need to solve this properly.

This could possibly be split out better. But the basic idea is to

(a) determine what is enabled at probe time by looking at what clocks are enabled (ie. if display is enabled at all, mdp5's core clock will be on. If DSI output is enabled (at least in video mode) the dsi block's pixel clock will be enabled, etc.

(b) For the enabled outputs, work backwards up the display pipe from output to plane (input). We need to work in this direction as we cannot (for example) read back crtc state until we know which layer-mixer is used or read plane state until we know which hw pipe is used. (But for mdp5 which drm_plane or drm_crtc is picked does not matter since they are virtualized, ie. we assign dynamically hwpipes and lm's to planes and crtcs.)

So far this is only implemented for DSI video mode. For DSI command- mode I think we end up needing to get the mode from the drm_panel. (On db410c, which I'm testing this on, it is DSI video mode to an adv7533 bridge.) HDMI/eDP are unimplemented so far.

We have to make some simplifications/assumptions in a few places, about how the bootloader is setting things up (ie. that there is just a single plane, and about the pixel format). I'm not sure that working backwards from hw state is completely possible in all cases without making some assumptions. (For example, the hw is flexible enough to deal with imaginary color formats like BARG5865.. and I think for 4k scanout ganging up multiple hwpipes and layermixers you end up with multiple possible sw states mapping to single hw state.) Maybe there is some room for a more generic optional framework for this (which can also be used for extra debug to validate atomic commits via hw-readback after commit), but probably best to start with some more simple display block for that.

---
 drivers/gpu/drm/msm/dsi/dsi.h                   |   1 +
 drivers/gpu/drm/msm/dsi/dsi_host.c              |  32 ++++++
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.c           |   5 +-
 drivers/gpu/drm/msm/dsi/phy/dsi_phy.h           |   1 +
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c      |   2 +
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c      |   2 +
 drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c |   2 +
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_cmd_encoder.c |   8 ++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c        |  21 ++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_ctl.c         |  48 +++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_ctl.h         |   3 +
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_encoder.c     | 132 ++++++++++++++++++++++--
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c         |  79 +++++++++++++-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h         |  11 ++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c       |  79 ++++++++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.c         |  45 ++++++++
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.h         |   2 +
 drivers/gpu/drm/msm/msm_drv.c                   |   3 +
 drivers/gpu/drm/msm/msm_drv.h                   |   2 +
 drivers/gpu/drm/msm/msm_fbdev.c                 |  15 ++-
 drivers/gpu/drm/msm/msm_kms.h                   |   2 +
 21 files changed, 478 insertions(+), 17 deletions(-)
drivers/gpu/drm/msm/dsi/dsi.h +1 -0
index 9e6017387efb..4340edaec8e2 100644
@@ -99,6 +99,7 @@ bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
 void msm_dsi_manager_attach_dsi_device(int id, u32 device_flags);
 int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
+void msm_dsi_hw_readback(struct msm_dsi *msm_dsi);
 
 /* msm dsi */
 static inline bool msm_dsi_device_connected(struct msm_dsi *msm_dsi)
drivers/gpu/drm/msm/dsi/dsi_host.c +32 -0
index 9e9c5696bc03..71a1d3dd7eb5 100644
@@ -28,11 +28,14 @@
 #include <linux/regmap.h>
 #include <video/mipi_display.h>
 
+#include "msm_drv.h"
+#include "msm_kms.h"
 #include "dsi.h"
 #include "dsi.xml.h"
 #include "sfpb.xml.h"
 #include "dsi_cfg.h"
 #include "msm_kms.h"
+#include "phy/dsi_phy.h"
 
 static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor)
 {
@@ -1866,6 +1869,35 @@ void msm_dsi_host_unregister(struct mipi_dsi_host *host)
 	}
 }
 
+// XXX msm_dsi_host_hw_readback()... preserve the layer-cake?
+void msm_dsi_hw_readback(struct msm_dsi *msm_dsi)
+{
+	struct msm_dsi_host *msm_host = to_msm_dsi_host(msm_dsi->host);
+	struct msm_drm_private *priv = msm_dsi->dev->dev_private;
+	struct msm_kms *kms = priv->kms;
+
+	if (!__clk_is_enabled(msm_host->pixel_clk))
+		return;
+
+	kms->funcs->hw_readback_encoder(kms, msm_dsi->encoder);
+	msm_dsi->connector->state->crtc = msm_dsi->encoder->crtc;
+	msm_dsi->connector->state->best_encoder = msm_dsi->encoder;
+	msm_dsi->encoder->crtc->state->connector_mask =
+		(1 << drm_connector_index(msm_dsi->connector));
+	msm_host->power_on = true;
+
+	/* also fixup refcnt on regulators: */
+	dsi_host_regulator_enable(msm_host);
+
+	/* clocks will already be on, but with just a single refcnt,
+	 * whereas normally (at least in some cases) both dsi and
+	 * mdp5 take a reference to the same clks.  So take an extra
+	 * reference here to balance things out in the disable path.
+	 */
+	dsi_bus_clk_enable(msm_host);
+	dsi_phy_enable_resource(msm_dsi->phy);
+}
+
 int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
 				const struct mipi_dsi_msg *msg)
 {
drivers/gpu/drm/msm/dsi/phy/dsi_phy.c +4 -1
index 0c2eb9c9a1fc..ea0d674983dd 100644
@@ -354,11 +354,13 @@ static int dsi_phy_regulator_enable(struct msm_dsi_phy *phy)
 	return ret;
 }
 
-static int dsi_phy_enable_resource(struct msm_dsi_phy *phy)
+int dsi_phy_enable_resource(struct msm_dsi_phy *phy)
 {
 	struct device *dev = &phy->pdev->dev;
 	int ret;
 
+	DBG("");
+
 	pm_runtime_get_sync(dev);
 
 	ret = clk_prepare_enable(phy->ahb_clk);
@@ -372,6 +374,7 @@ static int dsi_phy_enable_resource(struct msm_dsi_phy *phy)
 
 static void dsi_phy_disable_resource(struct msm_dsi_phy *phy)
 {
+	DBG("");
 	clk_disable_unprepare(phy->ahb_clk);
 	pm_runtime_put_sync(&phy->pdev->dev);
 }
drivers/gpu/drm/msm/dsi/phy/dsi_phy.h +1 -0
index 1733f6608a09..ee417c43c539 100644
@@ -103,6 +103,7 @@ int msm_dsi_dphy_timing_calc_v2(struct msm_dsi_dphy_timing *timing,
 void msm_dsi_phy_set_src_pll(struct msm_dsi_phy *phy, int pll_id, u32 reg,
 				u32 bit_mask);
 int msm_dsi_phy_init_common(struct msm_dsi_phy *phy);
+int dsi_phy_enable_resource(struct msm_dsi_phy *phy);
 
 #endif /* __DSI_PHY_H__ */
 
drivers/gpu/drm/msm/dsi/pll/dsi_pll_14nm.c +2 -0
index fe15aa64086f..fef3f208199a 100644
@@ -1088,6 +1088,8 @@ struct msm_dsi_pll *msm_dsi_pll_14nm_init(struct platform_device *pdev, int id)
 	pll->save_state = dsi_pll_14nm_save_state;
 	pll->restore_state = dsi_pll_14nm_restore_state;
 	pll->set_usecase = dsi_pll_14nm_set_usecase;
+	pll->pll_on = pll_14nm_poll_for_ready(pll_14nm, POLL_MAX_READS,
+			POLL_TIMEOUT_US);
 
 	pll_14nm->vco_delay = 1;
 
drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm.c +2 -0
index 26e3a01a99c2..f1634c533e1f 100644
@@ -313,6 +313,7 @@ static const struct clk_ops clk_ops_dsi_pll_28nm_vco = {
 	.prepare = msm_dsi_pll_helper_clk_prepare,
 	.unprepare = msm_dsi_pll_helper_clk_unprepare,
 	.is_enabled = dsi_pll_28nm_clk_is_enabled,
+	.is_prepared = dsi_pll_28nm_clk_is_enabled,
 };
 
 /*
@@ -619,6 +620,7 @@ struct msm_dsi_pll *msm_dsi_pll_28nm_init(struct platform_device *pdev,
 	pll->disable_seq = dsi_pll_28nm_disable_seq;
 	pll->save_state = dsi_pll_28nm_save_state;
 	pll->restore_state = dsi_pll_28nm_restore_state;
+	pll->pll_on = pll_28nm_poll_for_ready(pll_28nm, 10, 50);
 
 	if (type == MSM_DSI_PHY_28NM_HPM) {
 		pll_28nm->vco_delay = 1;
drivers/gpu/drm/msm/dsi/pll/dsi_pll_28nm_8960.c +2 -0
index 49008451085b..16eb49f22bf2 100644
@@ -520,6 +520,8 @@ struct msm_dsi_pll *msm_dsi_pll_28nm_8960_init(struct platform_device *pdev,
 	pll->disable_seq = dsi_pll_28nm_disable_seq;
 	pll->save_state = dsi_pll_28nm_save_state;
 	pll->restore_state = dsi_pll_28nm_restore_state;
+	pll->pll_on = pll_28nm_poll_for_ready(pll_28nm, POLL_MAX_READS,
+			POLL_TIMEOUT_US);
 
 	pll->en_seq_cnt = 1;
 	pll->enable_seqs[0] = dsi_pll_28nm_enable_seq;
drivers/gpu/drm/msm/mdp/mdp5/mdp5_cmd_encoder.c +8 -0
index aa7402e03f67..83322f52f971 100644
@@ -146,6 +146,14 @@ void mdp5_cmd_encoder_mode_set(struct drm_encoder *encoder,
 	mdp5_crtc_set_pipeline(encoder->crtc);
 }
 
+struct drm_display_mode *mdp5_cmd_encoder_readback_mode(struct drm_encoder *encoder)
+{
+	// TODO can we even reconstruct something that resembles a mode
+	// in the case of cmd mode?  (And will bootloader ever enable
+	// a panel in cmd mode, or can we just ignore this scenario?)
+	return NULL;
+}
+
 void mdp5_cmd_encoder_disable(struct drm_encoder *encoder)
 {
 	struct mdp5_encoder *mdp5_cmd_enc = to_mdp5_encoder(encoder);
drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c +21 -0
index 9d01656d853e..e0f8437ac868 100644
@@ -409,6 +409,27 @@ static void mdp5_crtc_mode_set_nofb(struct drm_crtc *crtc)
 	spin_unlock_irqrestore(&mdp5_crtc->lm_lock, flags);
 }
 
+void mdp5_crtc_readback(struct drm_crtc *crtc, struct drm_display_mode *mode,
+		enum mdp5_pipe pipe)
+{
+	struct drm_crtc_state *state = crtc->state;
+	struct drm_plane *plane = crtc->primary;
+	int ret;
+
+	// TODO probably just drop mdp5_state->enabled?
+	to_mdp5_crtc(crtc)->enabled = true;
+
+	state->active = true;
+	ret = drm_atomic_set_mode_for_crtc(state, mode);
+	WARN_ON(ret);
+	drm_mode_copy(&state->adjusted_mode, mode);
+
+	state->plane_mask = 1 << drm_plane_index(plane);
+	plane->state->crtc = crtc;
+
+	mdp5_plane_readback(plane, pipe);
+}
+
 static void mdp5_crtc_disable(struct drm_crtc *crtc)
 {
 	struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc);
drivers/gpu/drm/msm/mdp/mdp5/mdp5_ctl.c +48 -0

54 lines not on this page · raw message

drivers/gpu/drm/msm/mdp/mdp5/mdp5_ctl.h +3 -0
index b63120388dc6..5b8fa5df7713 100644
@@ -65,6 +65,9 @@ int mdp5_ctl_blend(struct mdp5_ctl *ctl, struct mdp5_pipeline *pipeline,
 		   enum mdp5_pipe r_stage[][MAX_PIPE_STAGE],
 		   u32 stage_cnt, u32 ctl_blend_op_flags);
 
+struct mdp5_hw_mixer * mdp5_ctl_readback(struct mdp5_ctl *ctl,
+		enum mdp5_pipe *pipe);
+
 /**
  * mdp_ctl_flush_mask...() - Register FLUSH masks
  *
drivers/gpu/drm/msm/mdp/mdp5/mdp5_encoder.c +125 -7

156 lines not on this page · raw message

drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.c +74 -5

116 lines not on this page · raw message

drivers/gpu/drm/msm/mdp/mdp5/mdp5_kms.h +11 -0
index 3b6dd4250242..15d32357d58b 100644
@@ -74,6 +74,7 @@ struct mdp5_kms {
 	spinlock_t resource_lock;
 
 	bool rpm_enabled;
+	bool poweron_enabled;     /* display already on when driver probed */
 
 	struct mdp_irq error_handler;
 
@@ -273,12 +274,15 @@ void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
 int mdp5_irq_domain_init(struct mdp5_kms *mdp5_kms);
 void mdp5_irq_domain_fini(struct mdp5_kms *mdp5_kms);
 
+void mdp5_plane_readback(struct drm_plane *plane, enum mdp5_pipe pipe);
 uint32_t mdp5_plane_get_flush(struct drm_plane *plane);
 enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane);
 enum mdp5_pipe mdp5_plane_right_pipe(struct drm_plane *plane);
 struct drm_plane *mdp5_plane_init(struct drm_device *dev,
 				  enum drm_plane_type type);
 
+void mdp5_crtc_readback(struct drm_crtc *crtc, struct drm_display_mode *mode,
+		enum mdp5_pipe pipe);
 struct mdp5_ctl *mdp5_crtc_get_ctl(struct drm_crtc *crtc);
 uint32_t mdp5_crtc_vblank(struct drm_crtc *crtc);
 
@@ -290,6 +294,7 @@ struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
 				struct drm_plane *plane,
 				struct drm_plane *cursor_plane, int id);
 
+void mdp5_encoder_readback(struct drm_encoder *encoder);
 struct drm_encoder *mdp5_encoder_init(struct drm_device *dev,
 		struct mdp5_interface *intf, struct mdp5_ctl *ctl);
 int mdp5_vid_encoder_set_split_display(struct drm_encoder *encoder,
@@ -302,6 +307,7 @@ u32 mdp5_encoder_get_framecount(struct drm_encoder *encoder);
 void mdp5_cmd_encoder_mode_set(struct drm_encoder *encoder,
 			       struct drm_display_mode *mode,
 			       struct drm_display_mode *adjusted_mode);
+struct drm_display_mode *mdp5_cmd_encoder_readback_mode(struct drm_encoder *encoder);
 void mdp5_cmd_encoder_disable(struct drm_encoder *encoder);
 void mdp5_cmd_encoder_enable(struct drm_encoder *encoder);
 int mdp5_cmd_encoder_set_split_display(struct drm_encoder *encoder,
@@ -312,6 +318,11 @@ static inline void mdp5_cmd_encoder_mode_set(struct drm_encoder *encoder,
 					     struct drm_display_mode *adjusted_mode)
 {
 }
+static inline struct drm_display_mode *
+mdp5_cmd_encoder_readback_mode(struct drm_encoder *encoder)
+{
+	return NULL;
+}
 static inline void mdp5_cmd_encoder_disable(struct drm_encoder *encoder)
 {
 }
drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c +79 -0

85 lines not on this page · raw message

drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.c +45 -0

57 lines not on this page · raw message

drivers/gpu/drm/msm/mdp/mdp5/mdp5_smp.h +2 -0
index b41d0448fbe8..1fedeb6bc554 100644
@@ -94,5 +94,7 @@ void mdp5_smp_release(struct mdp5_smp *smp, struct mdp5_smp_state *state,
 
 void mdp5_smp_prepare_commit(struct mdp5_smp *smp, struct mdp5_smp_state *state);
 void mdp5_smp_complete_commit(struct mdp5_smp *smp, struct mdp5_smp_state *state);
+void mdp5_smp_readback(struct mdp5_smp *smp, struct mdp5_smp_state *state,
+		enum mdp5_pipe pipe);
 
 #endif /* __MDP5_SMP_H__ */
drivers/gpu/drm/msm/msm_drv.c +3 -0
index 7a842b769925..542d8122a832 100644
@@ -545,6 +545,9 @@ static int msm_drm_init(struct device *dev, struct drm_driver *drv)
 
 	drm_mode_config_reset(ddev);
 
+	if (kms->funcs->hw_readback)
+		kms->funcs->hw_readback(kms);
+
 #ifdef CONFIG_DRM_FBDEV_EMULATION
 	if (fbdev)
 		priv->fbdev = msm_fbdev_init(ddev);
drivers/gpu/drm/msm/msm_drv.h +2 -0
index c6adf7aaea26..5ade6a0f467f 100644
@@ -20,6 +20,7 @@
 
 #include <linux/kernel.h>
 #include <linux/clk.h>
+#include <linux/clk-provider.h>
 #include <linux/cpufreq.h>
 #include <linux/module.h>
 #include <linux/component.h>
@@ -109,6 +110,7 @@ struct msm_drm_private {
 	struct msm_file_private *lastctx;
 
 	struct drm_fb_helper *fbdev;
+	struct drm_framebuffer *stolen_fb;
 
 	struct msm_rd_state *rd;
 	struct msm_perf_state *perf;
drivers/gpu/drm/msm/msm_fbdev.c +11 -4
index bb068d7f979f..7d721fd4fc7a 100644
@@ -78,7 +78,7 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,
 	struct fb_info *fbi = NULL;
 	uint64_t paddr;
 	uint32_t format;
-	int ret, pitch;
+	int ret;
 
 	format = drm_mode_legacy_fb_format(sizes->surface_bpp, sizes->surface_depth);
 
@@ -86,9 +86,16 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,
 			sizes->surface_height, sizes->surface_bpp,
 			sizes->fb_width, sizes->fb_height);
 
-	pitch = align_pitch(sizes->surface_width, sizes->surface_bpp);
-	fb = msm_alloc_stolen_fb(dev, sizes->surface_width,
-			sizes->surface_height, pitch, format);
+	if (priv->stolen_fb && (priv->stolen_fb->width == sizes->surface_width) &&
+	    (priv->stolen_fb->height == sizes->surface_height) &&
+	    (priv->stolen_fb->format->format == format)) {
+		DBG("Reusing stolen fb\n");
+		fb = priv->stolen_fb;
+	} else {
+		int pitch = align_pitch(sizes->surface_width, sizes->surface_bpp);
+		fb = msm_alloc_stolen_fb(dev, sizes->surface_width,
+				sizes->surface_height, pitch, format);
+	}
 
 	if (IS_ERR(fb)) {
 		dev_err(dev->dev, "failed to allocate fb\n");
drivers/gpu/drm/msm/msm_kms.h +2 -0
index a8f2ba5e5f07..0b20eece3827 100644
@@ -33,6 +33,8 @@
 struct msm_kms_funcs {
 	/* hw initialization: */
 	int (*hw_init)(struct msm_kms *kms);
+	void (*hw_readback)(struct msm_kms *kms);
+	void (*hw_readback_encoder)(struct msm_kms *kms, struct drm_encoder *encoder);
 	/* irq handling: */
 	void (*irq_preinstall)(struct msm_kms *kms);
 	int (*irq_postinstall)(struct msm_kms *kms);
Signature · 1 line
2.13.0
author
#7 lore raw

RFC 3/3 drm/bridge: adv7511: deal with bootloader lighting up display

In reply to Rob Clark

We need to do some things a bit differently if the bridge chip is already powered up when the driver loads (ie. bootloader has already enabled display). In particular we don't want to do anything that would kill the display.

---
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 57 +++++++++++++++++++---------
 drivers/gpu/drm/bridge/adv7511/adv7533.c     |  3 ++
 2 files changed, 42 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +39 -18
index f75ab6278113..15e725fa8616 100644
@@ -107,6 +107,7 @@ static bool adv7511_register_volatile(struct device *dev, unsigned int reg)
 	case ADV7511_REG_BSTATUS(1):
 	case ADV7511_REG_CHIP_ID_HIGH:
 	case ADV7511_REG_CHIP_ID_LOW:
+	case ADV7511_REG_POWER:
 		return true;
 	}
 
@@ -584,6 +585,8 @@ static int adv7511_get_modes(struct adv7511 *adv7511,
 			     edid_i2c_addr);
 	}
 
+	adv7511->current_edid_segment = -1;
+
 	edid = drm_do_get_edid(connector, adv7511_get_edid_block, adv7511);
 
 	if (!adv7511->powered)
@@ -627,7 +630,8 @@ adv7511_detect(struct adv7511 *adv7511, struct drm_connector *connector)
 	 * has to be reinitialized. */
 	if (status == connector_status_connected && hpd && adv7511->powered) {
 		regcache_mark_dirty(adv7511->regmap);
-		adv7511_power_on(adv7511);
+		if (!adv7511->powered)
+			adv7511_power_on(adv7511);
 		adv7511_get_modes(adv7511, connector);
 		if (adv7511->status == connector_status_connected)
 			status = connector_status_disconnected;
@@ -1044,33 +1048,47 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 		return ret;
 	}
 
+	adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
+	if (IS_ERR(adv7511->regmap)) {
+		ret = PTR_ERR(adv7511->regmap);
+		goto uninit_regulators;
+	}
+
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
+	if (ret)
+		goto uninit_regulators;
+	dev_dbg(dev, "Rev. %d\n", val);
+
+	ret = regmap_read(adv7511->regmap, ADV7511_REG_POWER, &val);
+	if (ret)
+		goto uninit_regulators;
+	dev_dbg(dev, "Power: %x\n", val);
+
+	if ((val & ADV7511_POWER_POWER_DOWN) == 0) {
+		dev_dbg(dev, "powered on at probe!\n");
+		regcache_sync(adv7511->regmap);
+		adv7511->powered = true;
+	}
+
 	/*
 	 * The power down GPIO is optional. If present, toggle it from active to
 	 * inactive to wake up the encoder.
 	 */
-	adv7511->gpio_pd = devm_gpiod_get_optional(dev, "pd", GPIOD_OUT_HIGH);
+	adv7511->gpio_pd = devm_gpiod_get_optional(dev, "pd",
+			adv7511->powered ? GPIOD_ASIS : GPIOD_OUT_HIGH);
 	if (IS_ERR(adv7511->gpio_pd)) {
 		ret = PTR_ERR(adv7511->gpio_pd);
 		goto uninit_regulators;
 	}
 
-	if (adv7511->gpio_pd) {
+	if (adv7511->gpio_pd && !adv7511->powered) {
 		mdelay(5);
 		gpiod_set_value_cansleep(adv7511->gpio_pd, 0);
 	}
 
-	adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
-	if (IS_ERR(adv7511->regmap)) {
-		ret = PTR_ERR(adv7511->regmap);
-		goto uninit_regulators;
-	}
-
-	ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
-	if (ret)
-		goto uninit_regulators;
-	dev_dbg(dev, "Rev. %d\n", val);
-
-	if (adv7511->type == ADV7511)
+	if (adv7511->powered)
+		adv7511_hpd(adv7511);  /* clear pending irq's */
+	else if (adv7511->type == ADV7511)
 		ret = regmap_register_patch(adv7511->regmap,
 					    adv7511_fixed_registers,
 					    ARRAY_SIZE(adv7511_fixed_registers));
@@ -1085,7 +1103,8 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	regmap_write(adv7511->regmap, ADV7511_REG_CEC_I2C_ADDR,
 		     main_i2c_addr - 2);
 
-	adv7511_packet_disable(adv7511, 0xffff);
+	if (!adv7511->powered)
+		adv7511_packet_disable(adv7511, 0xffff);
 
 	adv7511->i2c_edid = i2c_new_dummy(i2c->adapter, edid_i2c_addr >> 1);
 	if (!adv7511->i2c_edid) {
@@ -1116,7 +1135,8 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	regmap_write(adv7511->regmap, ADV7511_REG_CEC_CTRL,
 		     ADV7511_CEC_CTRL_POWER_DOWN);
 
-	adv7511_power_off(adv7511);
+	if (!adv7511->powered)
+		adv7511_power_off(adv7511);
 
 	i2c_set_clientdata(i2c, adv7511);
 
@@ -1132,7 +1152,8 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 		goto err_unregister_cec;
 	}
 
-	adv7511_audio_init(dev, adv7511);
+	if (!adv7511->powered)
+		adv7511_audio_init(dev, adv7511);
 
 	return 0;
 
drivers/gpu/drm/bridge/adv7511/adv7533.c +3 -0
index ac804f81e2f6..43dc53821acb 100644
@@ -166,6 +166,9 @@ int adv7533_init_cec(struct adv7511 *adv)
 		goto err;
 	}
 
+	if (adv->powered)
+		return 0;
+
 	ret = regmap_register_patch(adv->regmap_cec,
 				    adv7533_cec_fixed_registers,
 				    ARRAY_SIZE(adv7533_cec_fixed_registers));
Signature · 6 lines
2.13.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw
In reply to Rob Clark

Hi Rob,

Quoted 13 lines · Rob Clark

So now that this is working (at least on a single device), I figured it was a good time to send out an RFC to start discussion about how to do this properly, in particular the CCF/powerdomain parts.

The first patch adds flags so we can mark power domains and leaf node clocks which might (or might not) be enabled by bootloader and which we want to inherit when real display driver is probed. (There might be use-cases outside of display.. such as debug serial port? I guess display is the most common/complex/useful use-case.) From the CCF/genpd standpoint, "inherit" really just means "fixup enable/ prepare_count and don't automatically switch off in lateinit". The rest of the complexity is in the display driver.

Quoted 9 lines

For display, there are two different cases depending on whether the display driver is built as a module (ie. probes after lateinit) or not. If the display driver is built as a module, then we want efifb to keep working after the clk_disable_unused + genpd_power_off_unused late_initcall's. And in either case, we want the display driver to be able to detect that display is already on (by checking whether various clocks are already enabled) so that it knows to readback the hw state. (And not try to do things like clk_set_rate() on already running clocks.)

For the PM domains: won't these just stay enabled if efifb would call pm_runtime_enable() and pm_runtime_get_sync()?

For clocks, can't efifb enable all clocks tied to the device in DT?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author
#9 lore raw
Quoted 26 lines · Geert Uytterhoeven

Hi Rob,

Quoted 13 lines · Rob Clark

So now that this is working (at least on a single device), I figured it was a good time to send out an RFC to start discussion about how to do this properly, in particular the CCF/powerdomain parts.

The first patch adds flags so we can mark power domains and leaf node clocks which might (or might not) be enabled by bootloader and which we want to inherit when real display driver is probed. (There might be use-cases outside of display.. such as debug serial port? I guess display is the most common/complex/useful use-case.) From the CCF/genpd standpoint, "inherit" really just means "fixup enable/ prepare_count and don't automatically switch off in lateinit". The rest of the complexity is in the display driver.

Quoted 9 lines

For display, there are two different cases depending on whether the display driver is built as a module (ie. probes after lateinit) or not. If the display driver is built as a module, then we want efifb to keep working after the clk_disable_unused + genpd_power_off_unused late_initcall's. And in either case, we want the display driver to be able to detect that display is already on (by checking whether various clocks are already enabled) so that it knows to readback the hw state. (And not try to do things like clk_set_rate() on already running clocks.)

Quoted 4 lines

For the PM domains: won't these just stay enabled if efifb would call pm_runtime_enable() and pm_runtime_get_sync()?

For clocks, can't efifb enable all clocks tied to the device in DT?

There is no node in dt (nor dt bindings) for efifb, and there really should not be any, so no.

That could maybe work in the non-efi-boot case with simplefb except that (a) we'd still need to know if clocks were already enabled at boot or not, and in general having a dependency on clocks would keep simplefb from probing anywhere near as early in boot, and (b) since bootloader is populating simple-fb node in this case, it would end up being kernel specific (ie. clk/powerdomain bindings work differently between upstream and vendor kernel, so what the bootloader did would end up being the right thing for downstream kernel and not upstream kernel). So in the end trying to solve this through DT doesn't really accomplish anything.

BR,
-R
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel