Skip to contentSkip to conversation

Add support for MSM8996 GDSCs

PATCH Superseded Rajendra Nayak 2 participants 13 messages Nov 26, 2015 – Dec 1, 2015

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for MSM8996 GDSCs

This series adds support for GDSCs' which are part of gcc and mmcc in QCOM msm8996 SoC. Series applies on top of the patches[1] which adds support for MSM8996 clocks.

There are many more cases of gdscs within gdscs (hierarchical power domains) in msm8996 (msm8974 has one such instance which is supported upstream) and hence the series adds support within gdsc driver to handle this.

Also msm8996 has gdscs with gds hw controllers within, for ensuring slave device idleness before gdscs are powered off, hence the series also adds support for gdscs with gds hw controllers.

ToDo: Series does not yet add support for gpu gdscs which are part of mmcc.

Tested on apq8096 dragonboards to make sure all modelled gdscs can be turned on/off successfully.

[1] https://lkml.org/lkml/2015/11/17/949

Rajendra Nayak (6):
clk: qcom: gdsc: Add support for hierarchical power domains
clk: qcom: gdsc: Add support for gdscs with gds hw controller
clk: qcom: gdsc: Add GDSCs in msm8996 GCC
clk: qcom: gdsc: Add mmcc gdscs for msm8996 family
clk: qcom: gdsc: Do not check for disabled status on votable gdscs
clk: qcom: mmcc8974: Use gdscs .parent and remove genpd calls

 arch/arm64/boot/dts/qcom/msm8996.dtsi         |   2 +
 drivers/clk/qcom/common.c                     |  14 ++-
 drivers/clk/qcom/gcc-msm8996.c                |  92 +++++++++++++++
 drivers/clk/qcom/gdsc.c                       |  69 ++++++++---
 drivers/clk/qcom/gdsc.h                       |  34 ++++--
 drivers/clk/qcom/mmcc-msm8974.c               |  14 +--
 drivers/clk/qcom/mmcc-msm8996.c               | 157 ++++++++++++++++++++++++++
 include/dt-bindings/clock/qcom,gcc-msm8996.h  |  11 ++
 include/dt-bindings/clock/qcom,mmcc-msm8996.h |  17 +++
 9 files changed, 363 insertions(+), 47 deletions(-)
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH 1/6 clk: qcom: gdsc: Add support for hierarchical power domains

Some qcom SoCs' can have hierarchical power domains. Let the gdsc structs specify the parents (if any) and the driver add genpd subdomains for them.

---
 drivers/clk/qcom/common.c | 14 +++++++++-----
 drivers/clk/qcom/gdsc.c   | 27 +++++++++++++++++++++++++--
 drivers/clk/qcom/gdsc.h   | 17 ++++++++++++-----
 3 files changed, 46 insertions(+), 12 deletions(-)
drivers/clk/qcom/common.c +9 -5
index 8fa4772..cf100f9 100644
@@ -98,6 +98,7 @@ int qcom_cc_really_probe(struct platform_device *pdev,
 	struct clk **clks;
 	struct qcom_reset_controller *reset;
 	struct qcom_cc *cc;
+	struct gdsc_desc *scd;
 	size_t num_clks = desc->num_clks;
 	struct clk_regmap **rclks = desc->clks;
 
@@ -143,15 +144,18 @@ int qcom_cc_really_probe(struct platform_device *pdev,
 	devm_add_action(dev, qcom_cc_reset_unregister, &reset->rcdev);
 
 	if (desc->gdscs && desc->num_gdscs) {
-		ret = gdsc_register(dev, desc->gdscs, desc->num_gdscs,
-				    &reset->rcdev, regmap);
+		scd = devm_kzalloc(dev, sizeof(*scd), GFP_KERNEL);
+		if (!scd)
+			return -ENOMEM;
+		scd->dev = dev;
+		scd->scs = desc->gdscs;
+		scd->num = desc->num_gdscs;
+		ret = gdsc_register(scd, &reset->rcdev, regmap);
 		if (ret)
 			return ret;
+		devm_add_action(dev, qcom_cc_gdsc_unregister, scd);
 	}
 
-	devm_add_action(dev, qcom_cc_gdsc_unregister, dev);
-
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(qcom_cc_really_probe);
drivers/clk/qcom/gdsc.c +25 -2
index da9fad8..a164c38 100644
@@ -201,11 +201,14 @@ static int gdsc_init(struct gdsc *sc)
 	return 0;
 }
 
-int gdsc_register(struct device *dev, struct gdsc **scs, size_t num,
+int gdsc_register(struct gdsc_desc *desc,
 		  struct reset_controller_dev *rcdev, struct regmap *regmap)
 {
 	int i, ret;
 	struct genpd_onecell_data *data;
+	struct device *dev = desc->dev;
+	struct gdsc **scs = desc->scs;
+	size_t num = desc->num;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -228,10 +231,30 @@ int gdsc_register(struct device *dev, struct gdsc **scs, size_t num,
 		data->domains[i] = &scs[i]->pd;
 	}
 
+	/* Add subdomains */
+	for (i = 0; i < num; i++) {
+		if (!scs[i])
+			continue;
+		if (scs[i]->parent)
+			pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
+	}
+
 	return of_genpd_add_provider_onecell(dev->of_node, data);
 }
 
-void gdsc_unregister(struct device *dev)
+void gdsc_unregister(struct gdsc_desc *desc)
 {
+	int i;
+	struct device *dev = desc->dev;
+	struct gdsc **scs = desc->scs;
+	size_t num = desc->num;
+
+	/* Remove subdomains */
+	for (i = 0; i < num; i++) {
+		if (!scs[i])
+			continue;
+		if (scs[i]->parent)
+			pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd);
+	}
 	of_genpd_del_provider(dev->of_node);
 }
drivers/clk/qcom/gdsc.h +12 -5
index 5ded268..4e9dfc1 100644
@@ -41,6 +41,7 @@ struct reset_controller_dev;
  */
 struct gdsc {
 	struct generic_pm_domain	pd;
+	struct generic_pm_domain	*parent;
 	struct regmap			*regmap;
 	unsigned int			gdscr;
 	unsigned int			*cxcs;
@@ -51,18 +52,24 @@ struct gdsc {
 	unsigned int			reset_count;
 };
 
+struct gdsc_desc {
+	struct device *dev;
+	struct gdsc **scs;
+	size_t num;
+};
+
 #ifdef CONFIG_QCOM_GDSC
-int gdsc_register(struct device *, struct gdsc **, size_t n,
-		  struct reset_controller_dev *, struct regmap *);
-void gdsc_unregister(struct device *);
+int gdsc_register(struct gdsc_desc *desc, struct reset_controller_dev *,
+		  struct regmap *);
+void gdsc_unregister(struct gdsc_desc *desc);
 #else
-static inline int gdsc_register(struct device *d, struct gdsc **g, size_t n,
+static inline int gdsc_register(struct gdsc_desc *desc,
 				struct reset_controller_dev *rcdev,
 				struct regmap *r)
 {
 	return -ENOSYS;
 }
 
-static inline void gdsc_unregister(struct device *d) {};
+static inline void gdsc_unregister(struct gdsc_desc *desc) {};
 #endif /* CONFIG_QCOM_GDSC */
 #endif /* __QCOM_GDSC_H__ */
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#2 lore raw

PATCH 2/6 clk: qcom: gdsc: Add support for gdscs with gds hw controller

In reply to Rajendra Nayak

Some gdsc power domains can have a gds_hw_controller block inside to help ensure all slave devices within the power domain are idle before the gdsc is actually switched off.
This is mainly useful in power domains which host a MMU, in which case its necessary to make sure there are no outstanding MMU operations or pending bus transactions before the power domain is turned off.

In gdscs with gds_hw_controller block, its necessary to check the gds_hw_ctrl status bits instead of the ones in gdscr, to determine the state of the powerdomain.

---
 drivers/clk/qcom/gdsc.c | 38 ++++++++++++++++++++++----------------
 drivers/clk/qcom/gdsc.h |  2 ++
 2 files changed, 24 insertions(+), 16 deletions(-)
drivers/clk/qcom/gdsc.c +22 -16
index a164c38..fb2e43c 100644
@@ -42,12 +42,12 @@
 
 #define domain_to_gdsc(domain) container_of(domain, struct gdsc, pd)
 
-static int gdsc_is_enabled(struct gdsc *sc)
+static int gdsc_is_enabled(struct gdsc *sc, unsigned int reg)
 {
 	u32 val;
 	int ret;
 
-	ret = regmap_read(sc->regmap, sc->gdscr, &val);
+	ret = regmap_read(sc->regmap, reg, &val);
 	if (ret)
 		return ret;
 
@@ -58,30 +58,34 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
 {
 	int ret;
 	u32 val = en ? 0 : SW_COLLAPSE_MASK;
-	u32 check = en ? PWR_ON_MASK : 0;
 	unsigned long timeout;
+	unsigned int status_reg = sc->gdscr;
 
 	ret = regmap_update_bits(sc->regmap, sc->gdscr, SW_COLLAPSE_MASK, val);
 	if (ret)
 		return ret;
 
 	timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
-	do {
-		ret = regmap_read(sc->regmap, sc->gdscr, &val);
-		if (ret)
-			return ret;
 
-		if ((val & PWR_ON_MASK) == check)
+	if (sc->gds_hw_ctrl) {
+		status_reg = sc->gds_hw_ctrl;
+	/*
+	 * The gds hw controller asserts/de-asserts the status bit soon
+	 * after it receives a power on/off request from a master.
+	 * The controller then takes around 8 xo cycles to start its internal
+	 * state machine and update the status bit. During this time, the
+	 * status bit does not reflect the true status of the core.
+	 * Add a delay of 1 us between writing to the SW_COLLAPSE bit and
+	 * polling the status bit
+	 */
+		udelay(1);
+	}
+
+	do {
+		if (gdsc_is_enabled(sc, status_reg) == en)
 			return 0;
 	} while (time_before(jiffies, timeout));
 
-	ret = regmap_read(sc->regmap, sc->gdscr, &val);
-	if (ret)
-		return ret;
-
-	if ((val & PWR_ON_MASK) == check)
-		return 0;
-
 	return -ETIMEDOUT;
 }
 
@@ -165,6 +169,7 @@ static int gdsc_init(struct gdsc *sc)
 {
 	u32 mask, val;
 	int on, ret;
+	unsigned int reg;
 
 	/*
 	 * Disable HW trigger: collapse/restore occur based on registers writes.
@@ -185,7 +190,8 @@ static int gdsc_init(struct gdsc *sc)
 			return ret;
 	}
 
-	on = gdsc_is_enabled(sc);
+	reg = sc->gds_hw_ctrl ? sc->gds_hw_ctrl : sc->gdscr;
+	on = gdsc_is_enabled(sc, reg);
 	if (on < 0)
 		return on;
 
drivers/clk/qcom/gdsc.h +2 -0
index 4e9dfc1..66a43be 100644
@@ -32,6 +32,7 @@ struct reset_controller_dev;
  * @pd: generic power domain
  * @regmap: regmap for MMIO accesses
  * @gdscr: gsdc control register
+ * @gds_hw_ctrl: gds_hw_ctrl register
  * @cxcs: offsets of branch registers to toggle mem/periph bits in
  * @cxc_count: number of @cxcs
  * @pwrsts: Possible powerdomain power states
@@ -44,6 +45,7 @@ struct gdsc {
 	struct generic_pm_domain	*parent;
 	struct regmap			*regmap;
 	unsigned int			gdscr;
+	unsigned int			gds_hw_ctrl;
 	unsigned int			*cxcs;
 	unsigned int			cxc_count;
 	const u8			pwrsts;
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#3 lore raw

Re: [PATCH 2/6] clk: qcom: gdsc: Add support for gdscs with gds hw controller

Quoted 20 lines · Rajendra Nayak
drivers/clk/qcom/gdsc.c +2 -6
@@ -58,30 +58,34 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
 {
 	int ret;
 	u32 val = en ? 0 : SW_COLLAPSE_MASK;
-	u32 check = en ? PWR_ON_MASK : 0;
 	unsigned long timeout;
+	unsigned int status_reg = sc->gdscr;
 
 	ret = regmap_update_bits(sc->regmap, sc->gdscr, SW_COLLAPSE_MASK, val);
 	if (ret)
 		return ret;
 
 	timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
-	do {
-		ret = regmap_read(sc->regmap, sc->gdscr, &val);
-		if (ret)
-			return ret;
 
-		if ((val & PWR_ON_MASK) == check)
+	if (sc->gds_hw_ctrl) {

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 80

Quoted 10 lines
drivers/clk/qcom/gdsc.c +10 -0
+		status_reg = sc->gds_hw_ctrl;
+	/*
+	 * The gds hw controller asserts/de-asserts the status bit soon
+	 * after it receives a power on/off request from a master.
+	 * The controller then takes around 8 xo cycles to start its internal
+	 * state machine and update the status bit. During this time, the
+	 * status bit does not reflect the true status of the core.
+	 * Add a delay of 1 us between writing to the SW_COLLAPSE bit and
+	 * polling the status bit
+	 */

Please indent this correctly to the udelay indent level.

Quoted 5 lines
drivers/clk/qcom/gdsc.c +5 -0
+		udelay(1);
+	}
+
+	do {
+		if (gdsc_is_enabled(sc, status_reg) == en)

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 84

Quoted 10 lines
drivers/clk/qcom/gdsc.c +0 -7
 			return 0;
 	} while (time_before(jiffies, timeout));
 
-	ret = regmap_read(sc->regmap, sc->gdscr, &val);
-	if (ret)
-		return ret;
-
-	if ((val & PWR_ON_MASK) == check)
-		return 0;
-

This opens a bug where we timeout and then the status bit changes after the timeout. One more check is good and should stay. We could also change this to ktime instead of jiffies. That would be a good improvement.

Quoted 12 lines
drivers/clk/qcom/gdsc.c +1 -0
 	return -ETIMEDOUT;
 }
 
@@ -165,6 +169,7 @@ static int gdsc_init(struct gdsc *sc)
 {
 	u32 mask, val;
 	int on, ret;
+	unsigned int reg;
 
 	/*
 	 * Disable HW trigger: collapse/restore occur based on registers writes.

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

Quoted 6 lines
drivers/clk/qcom/gdsc.c +2 -1
@@ -185,7 +190,8 @@ static int gdsc_init(struct gdsc *sc)
 			return ret;
 	}
 
-	on = gdsc_is_enabled(sc);
+	reg = sc->gds_hw_ctrl ? sc->gds_hw_ctrl : sc->gdscr;
+	on = gdsc_is_enabled(sc, reg);

If the gdsc is voteable, then we need to make sure that the vote is from us when we boot up. Otherwise the kernel may think that the gdsc is enabled, but it gets turned off by some other master later on. I don't know if this causes some sort of problem for the power domain framework, but we can't rely on the status bit unless we're sure that we've actually set the register to enable it. In the normal enable/disable path we'll always know we set the register, so this really only matters once when we boot up.

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

Re: [PATCH 2/6] clk: qcom: gdsc: Add support for gdscs with gds hw controller

Quoted 19 lines · Stephen Boyd
Quoted 18 lines · Rajendra Nayak
drivers/clk/qcom/gdsc.c +1 -5
@@ -58,30 +58,34 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
 {
 	int ret;
 	u32 val = en ? 0 : SW_COLLAPSE_MASK;
-	u32 check = en ? PWR_ON_MASK : 0;
 	unsigned long timeout;
+	unsigned int status_reg = sc->gdscr;
 
 	ret = regmap_update_bits(sc->regmap, sc->gdscr, SW_COLLAPSE_MASK, val);
 	if (ret)
 		return ret;
 
 	timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
-	do {
-		ret = regmap_read(sc->regmap, sc->gdscr, &val);
-		if (ret)
-			return ret;
 
Quoted 14 lines

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 80

Quoted 12 lines
drivers/clk/qcom/gdsc.c +11 -1
-		if ((val & PWR_ON_MASK) == check)
+	if (sc->gds_hw_ctrl) {
+		status_reg = sc->gds_hw_ctrl;
+	/*
+	 * The gds hw controller asserts/de-asserts the status bit soon
+	 * after it receives a power on/off request from a master.
+	 * The controller then takes around 8 xo cycles to start its internal
+	 * state machine and update the status bit. During this time, the
+	 * status bit does not reflect the true status of the core.
+	 * Add a delay of 1 us between writing to the SW_COLLAPSE bit and
+	 * polling the status bit
+	 */

Please indent this correctly to the udelay indent level.

will do.

Quoted 9 lines
Quoted 9 lines
drivers/clk/qcom/gdsc.c +5 -0
+		udelay(1);
+	}
+
+	do {
+		if (gdsc_is_enabled(sc, status_reg) == en)
 			return 0;
 	} while (time_before(jiffies, timeout));
 
Quoted 12 lines

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 84

Quoted 7 lines
drivers/clk/qcom/gdsc.c +0 -7
-	ret = regmap_read(sc->regmap, sc->gdscr, &val);
-	if (ret)
-		return ret;
-
-	if ((val & PWR_ON_MASK) == check)
-		return 0;
-

This opens a bug where we timeout and then the status bit changes after the timeout. One more check is good and should stay. We could also change this to ktime instead of jiffies. That would be a good improvement.

If the status bit does change after timeout maybe the timeout isn't really enough and needs to be increased?

Quoted 16 lines
Quoted 16 lines
drivers/clk/qcom/gdsc.c +1 -0
 	return -ETIMEDOUT;
 }
 
@@ -165,6 +169,7 @@ static int gdsc_init(struct gdsc *sc)
 {
 	u32 mask, val;
 	int on, ret;
+	unsigned int reg;
 
 	/*
 	 * Disable HW trigger: collapse/restore occur based on registers writes.
@@ -185,7 +190,8 @@ static int gdsc_init(struct gdsc *sc)
 			return ret;
 	}
 
Quoted 12 lines

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

Quoted 3 lines
drivers/clk/qcom/gdsc.c +2 -1
-	on = gdsc_is_enabled(sc);
+	reg = sc->gds_hw_ctrl ? sc->gds_hw_ctrl : sc->gdscr;
+	on = gdsc_is_enabled(sc, reg);

If the gdsc is voteable, then we need to make sure that the vote is from us when we boot up. Otherwise the kernel may think that the gdsc is enabled, but it gets turned off by some other master later on. I don't know if this causes some sort of problem for the power domain framework, but we can't rely on the status bit unless we're sure that we've actually set the register to enable it. In the normal enable/disable path we'll always know we set the register, so this really only matters once when we boot up.

right, thanks for catching this. However if we vote for a votable GDSC just because its ON at boot (due to someone else having voted) we won't ever remove the vote keeping it always enabled.

I think a safe way would be to consider all votable gdscs for which *we* haven't voted explicitly to be disabled at boot?

Quoted 1 line
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw

Re: [PATCH 2/6] clk: qcom: gdsc: Add support for gdscs with gds hw controller

Quoted 25 lines · Rajendra Nayak
Quoted 10 lines · Stephen Boyd
Quoted 8 lines · Rajendra Nayak
drivers/clk/qcom/gdsc.c +5 -0
+		udelay(1);
+	}
+
+	do {
+		if (gdsc_is_enabled(sc, status_reg) == en)
 			return 0;
 	} while (time_before(jiffies, timeout));
Quoted 12 lines

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 84

Quoted 7 lines
drivers/clk/qcom/gdsc.c +0 -7
-	ret = regmap_read(sc->regmap, sc->gdscr, &val);
-	if (ret)
-		return ret;
-
-	if ((val & PWR_ON_MASK) == check)
-		return 0;
-

This opens a bug where we timeout and then the status bit changes after the timeout. One more check is good and should stay. We could also change this to ktime instead of jiffies. That would be a good improvement.

Quoted 2 lines

If the status bit does change after timeout maybe the timeout isn't really enough and needs to be increased?

The problem is more that this isn't a tight loop with interrupts disabled, so we may schedule the task away for quite some time before we come back here and test the timeout against the jiffies value. So it's best to always check the register one more time after we bail out in case this occurs.

Quoted 30 lines
Quoted 17 lines
Quoted 17 lines
drivers/clk/qcom/gdsc.c +1 -0
 	return -ETIMEDOUT;
 }
@@ -165,6 +169,7 @@ static int gdsc_init(struct gdsc *sc)
 {
 	u32 mask, val;
 	int on, ret;
+	unsigned int reg;
 
 	/*
 	 * Disable HW trigger: collapse/restore occur based on registers writes.
@@ -185,7 +190,8 @@ static int gdsc_init(struct gdsc *sc)
 			return ret;
 	}
 
Quoted 12 lines

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

Quoted 3 lines
drivers/clk/qcom/gdsc.c +2 -1
-	on = gdsc_is_enabled(sc);
+	reg = sc->gds_hw_ctrl ? sc->gds_hw_ctrl : sc->gdscr;
+	on = gdsc_is_enabled(sc, reg);

If the gdsc is voteable, then we need to make sure that the vote is from us when we boot up. Otherwise the kernel may think that the gdsc is enabled, but it gets turned off by some other master later on. I don't know if this causes some sort of problem for the power domain framework, but we can't rely on the status bit unless we're sure that we've actually set the register to enable it. In the normal enable/disable path we'll always know we set the register, so this really only matters once when we boot up.

Quoted 7 lines

right, thanks for catching this. However if we vote for a votable GDSC just because its ON at boot (due to someone else having voted) we won't ever remove the vote keeping it always enabled.

I think a safe way would be to consider all votable gdscs for which *we* haven't voted explicitly to be disabled at boot?

Agreed, when we boot we should consider GDSCs that are indicating they're enabled via the bit 31 status bit but without the sw enable mask set as "disabled" even though they're actually enabled by some other master in the SoC.

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

Re: [PATCH 2/6] clk: qcom: gdsc: Add support for gdscs with gds hw controller

[]..

Quoted 33 lines
Quoted 33 lines
Quoted 11 lines

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

Quoted 11 lines
drivers/clk/qcom/gdsc.c +1 -0
 	return -ETIMEDOUT;
 }
@@ -165,6 +169,7 @@ static int gdsc_init(struct gdsc *sc)
 {
 	u32 mask, val;
 	int on, ret;
+	unsigned int reg;
 
 	/*
 	 * Disable HW trigger: collapse/restore occur based on registers

writes.

Quoted 4 lines
Quoted 4 lines
drivers/clk/qcom/gdsc.c +0 -0
@@ -185,7 +190,8 @@ static int gdsc_init(struct gdsc *sc)
 			return ret;
 	}
 
Quoted 12 lines

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

Quoted 3 lines
drivers/clk/qcom/gdsc.c +2 -1
-	on = gdsc_is_enabled(sc);
+	reg = sc->gds_hw_ctrl ? sc->gds_hw_ctrl : sc->gdscr;
+	on = gdsc_is_enabled(sc, reg);

If the gdsc is voteable, then we need to make sure that the vote is from us when we boot up. Otherwise the kernel may think that the gdsc is enabled, but it gets turned off by some other master later on. I don't know if this causes some sort of problem for the power domain framework, but we can't rely on the status bit unless we're sure that we've actually set the register to enable it. In the normal enable/disable path we'll always know we set the register, so this really only matters once when we boot up.

right, thanks for catching this. However if we vote for a votable GDSC just because its ON at boot (due to someone else having voted) we won't ever remove the vote keeping it always enabled.

Quoted 8 lines
Quoted 3 lines

I think a safe way would be to consider all votable gdscs for which *we* haven't voted explicitly to be disabled at boot?

Agreed, when we boot we should consider GDSCs that are indicating they're enabled via the bit 31 status bit but without the sw enable mask set as "disabled" even though they're actually enabled by some other master in the SoC.

Thinking about this a bit more, your earlier suggestion of voting for the GDSC explicitly seemed to work too, and also seemed cleaner. genpd ends up removing the vote if there aren't any users as part of genpd_poweroff_unused()

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#7 lore raw

PATCH 3/6 clk: qcom: gdsc: Add GDSCs in msm8996 GCC

In reply to Rajendra Nayak

Add all data for the GDSCs which are part of msm8996 GCC block

---
 arch/arm64/boot/dts/qcom/msm8996.dtsi        |  1 +
 drivers/clk/qcom/gcc-msm8996.c               | 88 ++++++++++++++++++++++++++++
 include/dt-bindings/clock/qcom,gcc-msm8996.h | 11 ++++
 3 files changed, 100 insertions(+)
arch/arm64/boot/dts/qcom/msm8996.dtsi +1 -0
index 2c2736d..31e7bd9 100644
@@ -147,6 +147,7 @@
 			compatible = "qcom,gcc-msm8996";
 			#clock-cells = <1>;
 			#reset-cells = <1>;
+			#power-domain-cells = <1>;
 			reg = <0x300000 0x90000>;
 		};
 
drivers/clk/qcom/gcc-msm8996.c +88 -0

112 lines not on this page · raw message

include/dt-bindings/clock/qcom,gcc-msm8996.h +11 -0
index 888e75c..6f814db 100644
@@ -336,4 +336,15 @@
 #define GCC_MSS_Q6_BCR						99
 #define GCC_QREFS_VBG_CAL_BCR					100
 
+/* Indexes for GDSCs */
+#define AGGRE0_NOC_GDSC			0
+#define HLOS1_VOTE_AGGRE0_NOC_GDSC	1
+#define HLOS1_VOTE_LPASS_ADSP_GDSC	2
+#define HLOS1_VOTE_LPASS_CORE_GDSC	3
+#define USB30_GDSC			4
+#define PCIE0_GDSC			5
+#define PCIE1_GDSC			6
+#define PCIE2_GDSC			7
+#define UFS_GDSC			8
+
 #endif
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#8 lore raw

PATCH 4/6 clk: qcom: gdsc: Add mmcc gdscs for msm8996 family

In reply to Rajendra Nayak

Add all gdsc data which are part of mmcc on msm8996 family

---
 arch/arm64/boot/dts/qcom/msm8996.dtsi         |   1 +
 drivers/clk/qcom/mmcc-msm8996.c               | 154 ++++++++++++++++++++++++++
 include/dt-bindings/clock/qcom,mmcc-msm8996.h |  17 +++
 3 files changed, 172 insertions(+)
arch/arm64/boot/dts/qcom/msm8996.dtsi +1 -0
index 31e7bd9..0506fb8 100644
@@ -252,6 +252,7 @@
 			compatible = "qcom,mmcc-msm8996";
 			#clock-cells = <1>;
 			#reset-cells = <1>;
+			#power-domain-cells = <1>;
 			reg = <0x8c0000 0x40000>;
 			assigned-clocks = <&mmcc MMPLL9_PLL>,
 					  <&mmcc MMPLL1_PLL>,
drivers/clk/qcom/mmcc-msm8996.c +154 -0

178 lines not on this page · raw message

include/dt-bindings/clock/qcom,mmcc-msm8996.h +17 -0
index 9b81ca6..7d3a7fa 100644
@@ -282,4 +282,21 @@
 #define FD_BCR						58
 #define MMSS_SPDM_RM_BCR				59
 
+/* Indexes for GDSCs */
+#define MMAGIC_VIDEO_GDSC	0
+#define MMAGIC_MDSS_GDSC	1
+#define MMAGIC_CAMSS_GDSC	2
+#define GPU_GDSC		3
+#define VENUS_GDSC		4
+#define VENUS_CORE0_GDSC	5
+#define VENUS_CORE1_GDSC	6
+#define CAMSS_GDSC		7
+#define VFE0_GDSC		8
+#define VFE1_GDSC		9
+#define JPEG_GDSC		10
+#define CPP_GDSC		11
+#define FD_GDSC			12
+#define MDSS_GDSC		13
+#define GPU_GX_GDSC		14
+
 #endif
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#9 lore raw

PATCH 5/6 clk: qcom: gdsc: Do not check for disabled status on votable gdscs

In reply to Rajendra Nayak

Some gdscs might be controlled via voting registers and might not really disable when the kernel intends to disable them (due to other votes keeping them enabled)
Mark these gdscs with a flag for we do not check/wait on a disable status for these gdscs within the kernel disable callback.

---
 drivers/clk/qcom/gcc-msm8996.c  |  4 ++++
 drivers/clk/qcom/gdsc.c         |  4 ++++
 drivers/clk/qcom/gdsc.h         | 15 ++++++++-------
 drivers/clk/qcom/mmcc-msm8996.c |  3 +++
 4 files changed, 19 insertions(+), 7 deletions(-)
drivers/clk/qcom/gcc-msm8996.c +4 -0
index c5bce5f..bb8c61f 100644
@@ -3067,6 +3067,7 @@ static struct gdsc aggre0_noc_gdsc = {
 		.name = "aggre0_noc",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 static struct gdsc hlos1_vote_aggre0_noc_gdsc = {
@@ -3075,6 +3076,7 @@ static struct gdsc hlos1_vote_aggre0_noc_gdsc = {
 		.name = "hlos1_vote_aggre0_noc",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 static struct gdsc hlos1_vote_lpass_adsp_gdsc = {
@@ -3083,6 +3085,7 @@ static struct gdsc hlos1_vote_lpass_adsp_gdsc = {
 		.name = "hlos1_vote_lpass_adsp",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 static struct gdsc hlos1_vote_lpass_core_gdsc = {
@@ -3091,6 +3094,7 @@ static struct gdsc hlos1_vote_lpass_core_gdsc = {
 		.name = "hlos1_vote_lpass_core",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 static struct gdsc usb30_gdsc = {
drivers/clk/qcom/gdsc.c +4 -0
index fb2e43c..984537f 100644
@@ -65,6 +65,10 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
 	if (ret)
 		return ret;
 
+	/* If disabling votable gdscs, don't poll on status */
+	if ((sc->flags & VOTABLE) && !en)
+		return 0;
+
 	timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
 
 	if (sc->gds_hw_ctrl) {
drivers/clk/qcom/gdsc.h +8 -7
index 66a43be..91cbb09 100644
@@ -20,13 +20,6 @@
 struct regmap;
 struct reset_controller_dev;
 
-/* Powerdomain allowable state bitfields */
-#define PWRSTS_OFF		BIT(0)
-#define PWRSTS_RET		BIT(1)
-#define PWRSTS_ON		BIT(2)
-#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
-#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
-
 /**
  * struct gdsc - Globally Distributed Switch Controller
  * @pd: generic power domain
@@ -49,6 +42,14 @@ struct gdsc {
 	unsigned int			*cxcs;
 	unsigned int			cxc_count;
 	const u8			pwrsts;
+/* Powerdomain allowable state bitfields */
+#define PWRSTS_OFF		BIT(0)
+#define PWRSTS_RET		BIT(1)
+#define PWRSTS_ON		BIT(2)
+#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
+#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
+	const u8			flags;
+#define VOTABLE		BIT(0)
 	struct reset_controller_dev	*rcdev;
 	unsigned int			*resets;
 	unsigned int			reset_count;
drivers/clk/qcom/mmcc-msm8996.c +3 -0
index 236acf5..a0a7338 100644
@@ -2925,6 +2925,7 @@ struct gdsc mmagic_video_gdsc = {
 		.name = "mmagic_video",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 struct gdsc mmagic_mdss_gdsc = {
@@ -2934,6 +2935,7 @@ struct gdsc mmagic_mdss_gdsc = {
 		.name = "mmagic_mdss",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 struct gdsc mmagic_camss_gdsc = {
@@ -2943,6 +2945,7 @@ struct gdsc mmagic_camss_gdsc = {
 		.name = "mmagic_camss",
 	},
 	.pwrsts = PWRSTS_OFF_ON,
+	.flags = VOTABLE,
 };
 
 struct gdsc venus_gdsc = {
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
#10 lore raw

Re: [PATCH 5/6] clk: qcom: gdsc: Do not check for disabled status on votable gdscs

Quoted 6 lines · Rajendra Nayak

Some gdscs might be controlled via voting registers and might not really disable when the kernel intends to disable them (due to other votes keeping them enabled)
Mark these gdscs with a flag for we do not check/wait on a disable status for these gdscs within the kernel disable callback.

Quoted 7 lines
---
 drivers/clk/qcom/gcc-msm8996.c  |  4 ++++
 drivers/clk/qcom/gdsc.c         |  4 ++++
 drivers/clk/qcom/gdsc.h         | 15 ++++++++-------
 drivers/clk/qcom/mmcc-msm8996.c |  3 +++
 4 files changed, 19 insertions(+), 7 deletions(-)

We should have this patch before adding the gdscs that use it. Prevents any bisect hole.

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 71

Quoted 13 lines

static struct gdsc usb30_gdsc = {

drivers/clk/qcom/gdsc.c +4 -0
index fb2e43c..984537f 100644
@@ -65,6 +65,10 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
 	if (ret)
 		return ret;
 
+	/* If disabling votable gdscs, don't poll on status */
+	if ((sc->flags & VOTABLE) && !en)
+		return 0;
+

There's an explicit delay of 100uS on the disable path for votable gdscs in the downstream code. I don't see that here.

Quoted 22 lines
drivers/clk/qcom/gdsc.c +0 -0
 	timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
 
 	if (sc->gds_hw_ctrl) {
drivers/clk/qcom/gdsc.h +0 -7
index 66a43be..91cbb09 100644
@@ -20,13 +20,6 @@
 struct regmap;
 struct reset_controller_dev;
 
-/* Powerdomain allowable state bitfields */
-#define PWRSTS_OFF		BIT(0)
-#define PWRSTS_RET		BIT(1)
-#define PWRSTS_ON		BIT(2)
-#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
-#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
-
 /**
  * struct gdsc - Globally Distributed Switch Controller
  * @pd: generic power domain

drivers/clk/qcom/gdsc.h struct gdsc { · line 50

Quoted 9 lines
drivers/clk/qcom/gdsc.h +6 -0
@@ -49,6 +42,14 @@ struct gdsc {
 	unsigned int			*cxcs;
 	unsigned int			cxc_count;
 	const u8			pwrsts;
+/* Powerdomain allowable state bitfields */
+#define PWRSTS_OFF		BIT(0)
+#define PWRSTS_RET		BIT(1)
+#define PWRSTS_ON		BIT(2)
+#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
+#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)

Yes! We should have done this already. I guess I'm ok combining it with this patch.

Quoted 5 lines
drivers/clk/qcom/gdsc.h +2 -0
+	const u8			flags;
+#define VOTABLE		BIT(0)
 	struct reset_controller_dev	*rcdev;
 	unsigned int			*resets;
 	unsigned int			reset_count;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#11 lore raw

Re: [PATCH 5/6] clk: qcom: gdsc: Do not check for disabled status on votable gdscs

Quoted 15 lines · Stephen Boyd
Quoted 6 lines · Rajendra Nayak

Some gdscs might be controlled via voting registers and might not really disable when the kernel intends to disable them (due to other votes keeping them enabled)
Mark these gdscs with a flag for we do not check/wait on a disable status for these gdscs within the kernel disable callback.

Quoted 7 lines
---
 drivers/clk/qcom/gcc-msm8996.c  |  4 ++++
 drivers/clk/qcom/gdsc.c         |  4 ++++
 drivers/clk/qcom/gdsc.h         | 15 ++++++++-------
 drivers/clk/qcom/mmcc-msm8996.c |  3 +++
 4 files changed, 19 insertions(+), 7 deletions(-)
Quoted 2 lines

We should have this patch before adding the gdscs that use it. Prevents any bisect hole.

yes, will rearrange to move this up in the series.

Quoted 10 lines
Quoted 10 lines

static struct gdsc usb30_gdsc = {

drivers/clk/qcom/gdsc.c +0 -0
index fb2e43c..984537f 100644
@@ -65,6 +65,10 @@ static int gdsc_toggle_logic(struct gdsc *sc, bool en)
 	if (ret)
 		return ret;
 
Quoted 7 lines

drivers/clk/qcom/gdsc.c static int gdsc_toggle_logic(struct gdsc *sc, bool en) · line 71

Quoted 4 lines
drivers/clk/qcom/gdsc.c +4 -0
+	/* If disabling votable gdscs, don't poll on status */
+	if ((sc->flags & VOTABLE) && !en)
+		return 0;
+

There's an explicit delay of 100uS on the disable path for votable gdscs in the downstream code. I don't see that here.

right, I just left it out as I did not see any issues testing without it, when I did enable/disable the votable gdscs in a tight loop. But maybe my testing was limited to only apss voting for these so I can put it back in.

Quoted 42 lines
Quoted 23 lines
drivers/clk/qcom/gdsc.c +0 -0
 	timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
 
 	if (sc->gds_hw_ctrl) {
drivers/clk/qcom/gdsc.h +0 -7
index 66a43be..91cbb09 100644
@@ -20,13 +20,6 @@
 struct regmap;
 struct reset_controller_dev;
 
-/* Powerdomain allowable state bitfields */
-#define PWRSTS_OFF		BIT(0)
-#define PWRSTS_RET		BIT(1)
-#define PWRSTS_ON		BIT(2)
-#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
-#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
-
 /**
  * struct gdsc - Globally Distributed Switch Controller
  * @pd: generic power domain

drivers/clk/qcom/gdsc.h struct gdsc { · line 50

Quoted 9 lines
drivers/clk/qcom/gdsc.h +6 -0
@@ -49,6 +42,14 @@ struct gdsc {
 	unsigned int			*cxcs;
 	unsigned int			cxc_count;
 	const u8			pwrsts;
+/* Powerdomain allowable state bitfields */
+#define PWRSTS_OFF		BIT(0)
+#define PWRSTS_RET		BIT(1)
+#define PWRSTS_ON		BIT(2)
+#define PWRSTS_OFF_ON		(PWRSTS_OFF | PWRSTS_ON)
+#define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)

Yes! We should have done this already. I guess I'm ok combining it with this patch.

Quoted 5 lines
drivers/clk/qcom/gdsc.h +2 -0
+	const u8			flags;
+#define VOTABLE		BIT(0)
 	struct reset_controller_dev	*rcdev;
 	unsigned int			*resets;
 	unsigned int			reset_count;
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#12 lore raw

PATCH 6/6 clk: qcom: mmcc8974: Use gdscs .parent and remove genpd calls

In reply to Rajendra Nayak

With gdsc driver capable of handling hierarchical power domains, specify oxili_gdsc as parent of oxilicx_gdsc.

Remove all direct calls to genpd from the mmcc clock driver. The adding and removing of subdomains is now handled from within the gdsc driver.

---
 drivers/clk/qcom/mmcc-msm8974.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/clk/qcom/mmcc-msm8974.c +2 -12
index 9d790bc..12cea42 100644
@@ -2400,6 +2400,7 @@ static struct gdsc oxilicx_gdsc = {
 	.pd = {
 		.name = "oxilicx",
 	},
+	.parent = &oxili_gdsc.pd,
 	.pwrsts = PWRSTS_OFF_ON,
 };
 
@@ -2624,22 +2625,11 @@ static int mmcc_msm8974_probe(struct platform_device *pdev)
 	clk_pll_configure_sr_hpm_lp(&mmpll1, regmap, &mmpll1_config, true);
 	clk_pll_configure_sr_hpm_lp(&mmpll3, regmap, &mmpll3_config, false);
 
-	ret = qcom_cc_really_probe(pdev, &mmcc_msm8974_desc, regmap);
-	if (ret)
-		return ret;
-
-	return pm_genpd_add_subdomain(&oxili_gdsc.pd, &oxilicx_gdsc.pd);
-}
-
-static int mmcc_msm8974_remove(struct platform_device *pdev)
-{
-	pm_genpd_remove_subdomain(&oxili_gdsc.pd, &oxilicx_gdsc.pd);
-	return 0;
+	return qcom_cc_really_probe(pdev, &mmcc_msm8974_desc, regmap);
 }
 
 static struct platform_driver mmcc_msm8974_driver = {
 	.probe		= mmcc_msm8974_probe,
-	.remove		= mmcc_msm8974_remove,
 	.driver		= {
 		.name	= "mmcc-msm8974",
 		.of_match_table = mmcc_msm8974_match_table,
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation