Skip to contentSkip to conversation

ARM: OMAP4+: powerdomain fixes

PATCH In review Nishanth Menon 4 participants 15 messages Aug 22, 2014 – Aug 27, 2014

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ARM: OMAP4+: powerdomain fixes

Hi,

The following series are various fixes and improvements for powerdomain support in OMAP4+.

This is part 1/6 series which eventually enables framework for suspend-to-ram and cpuidle for OMAP5 and DRA7

Each of series is based on v3.17-rc1 and this specific series is available:
weblink: https://github.com/nmenon/linux-2.6-playground/commits/push/v3.17/powerdomain-fixes

git repo: https://github.com/nmenon/linux-2.6-playground.git push/v3.17/powerdomain-fixes

An complete integrated branch is available here: https://github.com/nmenon/linux-2.6-playground/commits/testing/v3.17/cpu-idle-suspend-dra7-omap5-framework

Nishanth Menon (7):
ARM: OMAP: DRA7: powerdomain data: fix powerdomain powerstate
ARM: OMAP5: powerdomain data: fix powerdomain powerstate
ARM: OMAP2+: powerdomain: pwrdm_for_each_clkdm iterate only valid
clkdms
ARM: OMAP2+: powerdomain: introduce logic for finding valid power
domain
ARM: OMAP4+: PM: Make logic state programmable
ARM: OMAP4+: PM: use only valid low power state for suspend
ARM: OMAP4+: PM: Use only valid low power state for CPU hotplug

 arch/arm/mach-omap2/omap-mpuss-lowpower.c   |    4 ++
 arch/arm/mach-omap2/pm44xx.c                |    9 +++-
 arch/arm/mach-omap2/powerdomain.c           |   76 ++++++++++++++++++++++++++-
 arch/arm/mach-omap2/powerdomain.h           |    4 ++
 arch/arm/mach-omap2/powerdomains54xx_data.c |   12 ++---
 arch/arm/mach-omap2/powerdomains7xx_data.c  |   14 ++---
 6 files changed, 103 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/7 ARM: OMAP: DRA7: powerdomain data: fix powerdomain powerstate

DRA7 supports only CSWR for CPU, MPU power domains. Core power domain supports upto INA.

---
 arch/arm/mach-omap2/powerdomain.h          |    1 +
 arch/arm/mach-omap2/powerdomains7xx_data.c |   14 +++++++-------
 2 files changed, 8 insertions(+), 7 deletions(-)
arch/arm/mach-omap2/powerdomain.h +1 -0
index f472711..a754c82 100644
@@ -39,6 +39,7 @@
 #define PWRSTS_OFF_RET		(PWRSTS_OFF | PWRSTS_RET)
 #define PWRSTS_RET_ON		(PWRSTS_RET | PWRSTS_ON)
 #define PWRSTS_OFF_RET_ON	(PWRSTS_OFF_RET | PWRSTS_ON)
+#define PWRSTS_INA_ON		(PWRSTS_INACTIVE | PWRSTS_ON)
 
 
 /*
arch/arm/mach-omap2/powerdomains7xx_data.c +7 -7
index 48151d1..287a203 100644
@@ -160,8 +160,8 @@ static struct powerdomain core_7xx_pwrdm = {
 	.name		  = "core_pwrdm",
 	.prcm_offs	  = DRA7XX_PRM_CORE_INST,
 	.prcm_partition	  = DRA7XX_PRM_PARTITION,
-	.pwrsts		  = PWRSTS_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts		  = PWRSTS_INA_ON,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 5,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* core_nret_bank */
@@ -193,8 +193,8 @@ static struct powerdomain cpu0_7xx_pwrdm = {
 	.name		  = "cpu0_pwrdm",
 	.prcm_offs	  = DRA7XX_MPU_PRCM_PRM_C0_INST,
 	.prcm_partition	  = DRA7XX_MPU_PRCM_PARTITION,
-	.pwrsts		  = PWRSTS_OFF_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts		  = PWRSTS_RET_ON,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 1,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* cpu0_l1 */
@@ -209,8 +209,8 @@ static struct powerdomain cpu1_7xx_pwrdm = {
 	.name		  = "cpu1_pwrdm",
 	.prcm_offs	  = DRA7XX_MPU_PRCM_PRM_C1_INST,
 	.prcm_partition	  = DRA7XX_MPU_PRCM_PARTITION,
-	.pwrsts		  = PWRSTS_OFF_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts		  = PWRSTS_RET_ON,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 1,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* cpu1_l1 */
@@ -243,7 +243,7 @@ static struct powerdomain mpu_7xx_pwrdm = {
 	.prcm_offs	  = DRA7XX_PRM_MPU_INST,
 	.prcm_partition	  = DRA7XX_PRM_PARTITION,
 	.pwrsts		  = PWRSTS_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 2,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* mpu_l2 */
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/7 ARM: OMAP5: powerdomain data: fix powerdomain powerstate

In reply to Nishanth Menon

Update the power domain power states for final production chip capability. OFF mode, OSWR etc have been descoped for various domains.

---
 arch/arm/mach-omap2/powerdomains54xx_data.c |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm/mach-omap2/powerdomains54xx_data.c +6 -6
index ce1d752..60d7ed8 100644
@@ -35,7 +35,7 @@ static struct powerdomain core_54xx_pwrdm = {
 	.prcm_offs	  = OMAP54XX_PRM_CORE_INST,
 	.prcm_partition	  = OMAP54XX_PRM_PARTITION,
 	.pwrsts		  = PWRSTS_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 5,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* core_nret_bank */
@@ -107,8 +107,8 @@ static struct powerdomain cpu0_54xx_pwrdm = {
 	.voltdm		  = { .name = "mpu" },
 	.prcm_offs	  = OMAP54XX_PRCM_MPU_PRM_C0_INST,
 	.prcm_partition	  = OMAP54XX_PRCM_MPU_PARTITION,
-	.pwrsts		  = PWRSTS_OFF_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts		  = PWRSTS_RET_ON,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 1,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* cpu0_l1 */
@@ -124,8 +124,8 @@ static struct powerdomain cpu1_54xx_pwrdm = {
 	.voltdm		  = { .name = "mpu" },
 	.prcm_offs	  = OMAP54XX_PRCM_MPU_PRM_C1_INST,
 	.prcm_partition	  = OMAP54XX_PRCM_MPU_PARTITION,
-	.pwrsts		  = PWRSTS_OFF_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts		  = PWRSTS_RET_ON,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 1,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* cpu1_l1 */
@@ -158,7 +158,7 @@ static struct powerdomain mpu_54xx_pwrdm = {
 	.prcm_offs	  = OMAP54XX_PRM_MPU_INST,
 	.prcm_partition	  = OMAP54XX_PRM_PARTITION,
 	.pwrsts		  = PWRSTS_RET_ON,
-	.pwrsts_logic_ret = PWRSTS_OFF_RET,
+	.pwrsts_logic_ret = PWRSTS_RET,
 	.banks		  = 2,
 	.pwrsts_mem_ret	= {
 		[0] = PWRSTS_OFF_RET,	/* mpu_l2 */
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/7 ARM: OMAP2+: powerdomain: pwrdm_for_each_clkdm iterate only valid clkdms

In reply to Nishanth Menon

No need to invoke callback when the clkdm pointer is NULL.

---
 arch/arm/mach-omap2/powerdomain.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/powerdomain.c +2 -1
index faebd5f..f391948 100644
@@ -546,7 +546,8 @@ int pwrdm_for_each_clkdm(struct powerdomain *pwrdm,
 		return -EINVAL;
 
 	for (i = 0; i < PWRDM_MAX_CLKDMS && !ret; i++)
-		ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
+		if (pwrdm->pwrdm_clkdms[i])
+			ret = (*fn)(pwrdm, pwrdm->pwrdm_clkdms[i]);
 
 	return ret;
 }
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/7 ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain

In reply to Nishanth Menon

powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file.

So, provide a function to easily query valid low power state that the power domain is allowed to go to.

Based on work originally done by Jean Pihet <[email protected]>
https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well.

Similar solutions have been done in product kernels in the past such as:
https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c

---
 arch/arm/mach-omap2/powerdomain.c |   73 +++++++++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/powerdomain.h |    3 ++
 2 files changed, 76 insertions(+)
arch/arm/mach-omap2/powerdomain.c +73 -0
index f391948..831a2bc 100644
@@ -1081,6 +1081,79 @@ int pwrdm_post_transition(struct powerdomain *pwrdm)
 }
 
 /**
+ * pwrdm_get_valid_lp_state() - Find best match deep power state
+ * @pwrdm:	power domain for which we want to find best match
+ * @is_logic_state: Are we looking for logic state match here? Should
+ *		    be one of PWRDM_xxx macro values
+ * @req_state:	requested power state
+ *
+ * Returns: closest match for requested power state. default fallback
+ * is RET for logic state and ON for power state.
+ *
+ * This does a search from the power domain data looking for the
+ * closest valid power domain state that the hardware can achieve.
+ * PRCM definitions for PWRSTCTRL allows us to program whatever
+ * configuration we'd like, and PRCM will actually attempt such
+ * a transition, however if the powerdomain does not actually support it,
+ * we endup with a hung system. The valid power domain states are already
+ * available in our powerdomain data files. So this function tries to do
+ * the following:
+ * a) find if we have an exact match to the request - no issues.
+ * b) else find if a deeper power state is possible.
+ * c) failing which, it tries to find closest higher power state for the
+ * request.
+ */
+u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm,
+			    bool is_logic_state, u8 req_state)
+{
+	u8 pwrdm_states = is_logic_state ? pwrdm->pwrsts_logic_ret :
+			pwrdm->pwrsts;
+	/* For logic, ret is highest and others, ON is highest */
+	u8 default_pwrst = is_logic_state ? PWRDM_POWER_RET : PWRDM_POWER_ON;
+	u8 new_pwrst;
+	bool found;
+
+	/* If it is already supported, nothing to search */
+	if (pwrdm_states & BIT(req_state))
+		return req_state;
+
+	if (!req_state)
+		goto up_search;
+
+	/*
+	 * So, we dont have a exact match
+	 * Can we get a deeper power state match?
+	 */
+	new_pwrst = req_state - 1;
+	found = true;
+	while (!(pwrdm_states & BIT(new_pwrst))) {
+		/* No match even at OFF? Not available */
+		if (new_pwrst == PWRDM_POWER_OFF) {
+			found = false;
+			break;
+		}
+		new_pwrst--;
+	}
+
+	if (found)
+		goto done;
+
+up_search:
+	/* OK, no deeper ones, can we get a higher match? */
+	new_pwrst = req_state + 1;
+	while (!(pwrdm_states & BIT(new_pwrst))) {
+		/* BUG if we have messed up database */
+		BUG_ON(new_pwrst > PWRDM_POWER_ON);
+
+		if (new_pwrst == default_pwrst)
+			break;
+		new_pwrst++;
+	}
+done:
+	return new_pwrst;
+}
+
+/**
  * omap_set_pwrdm_state - change a powerdomain's current power state
  * @pwrdm: struct powerdomain * to change the power state of
  * @pwrst: power state to change to
arch/arm/mach-omap2/powerdomain.h +3 -0
index a754c82..11bd4dd 100644
@@ -220,6 +220,9 @@ struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm);
 
 int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm);
 
+u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm,
+			    bool is_logic_state, u8 req_state);
+
 int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst);
 int pwrdm_read_next_pwrst(struct powerdomain *pwrdm);
 int pwrdm_read_pwrst(struct powerdomain *pwrdm);
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 5/7 ARM: OMAP4+: PM: Make logic state programmable

In reply to Nishanth Menon

Move the logic state as different for each power domain. This allows us to customize the deepest power state we should target over all for each powerdomain in the follow on patches.

---
 arch/arm/mach-omap2/pm44xx.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/pm44xx.c +4 -1
index 0dda6cf..b377b03 100644
@@ -29,6 +29,7 @@ u16 pm44xx_errata;
 struct power_state {
 	struct powerdomain *pwrdm;
 	u32 next_state;
+	u32 next_logic_state;
 #ifdef CONFIG_SUSPEND
 	u32 saved_state;
 	u32 saved_logic_state;
@@ -54,7 +55,7 @@ static int omap4_pm_suspend(void)
 	/* Set targeted power domain states by suspend */
 	list_for_each_entry(pwrst, &pwrst_list, node) {
 		omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
-		pwrdm_set_logic_retst(pwrst->pwrdm, PWRDM_POWER_OFF);
+		pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->next_logic_state);
 	}
 
 	/*
@@ -121,6 +122,8 @@ static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
 
 	pwrst->pwrdm = pwrdm;
 	pwrst->next_state = PWRDM_POWER_RET;
+	pwrst->next_logic_state = PWRDM_POWER_OFF;
+
 	list_add(&pwrst->node, &pwrst_list);
 
 	return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 6/7 ARM: OMAP4+: PM: use only valid low power state for suspend

In reply to Nishanth Menon

We are using power domain state as RET and logic state as OFF. This state is OSWR. This may not always be supported on ALL power domains. In fact, on certain power domains, this might result in a hang on certain platforms. Instead, depend on powerdomain data to provide accurate information about the supported powerdomain states and use the appropriate function to query and use it as part of suspend path.

---
 arch/arm/mach-omap2/pm44xx.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/arm/mach-omap2/pm44xx.c +4 -2
index b377b03..0bfce38 100644
@@ -121,8 +121,10 @@ static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
 		return -ENOMEM;
 
 	pwrst->pwrdm = pwrdm;
-	pwrst->next_state = PWRDM_POWER_RET;
-	pwrst->next_logic_state = PWRDM_POWER_OFF;
+	pwrst->next_state = pwrdm_get_valid_lp_state(pwrdm, false,
+						     PWRDM_POWER_RET);
+	pwrst->next_logic_state = pwrdm_get_valid_lp_state(pwrdm, true,
+							   PWRDM_POWER_OFF);
 
 	list_add(&pwrst->node, &pwrst_list);
 
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH 7/7 ARM: OMAP4+: PM: Use only valid low power state for CPU hotplug

In reply to Nishanth Menon

Not all SoCs support OFF mode - for example DRA74/72. So, use valid power state during CPU hotplug.

---
 arch/arm/mach-omap2/omap-mpuss-lowpower.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-omap2/omap-mpuss-lowpower.c +4 -0
index 4001325..e9cdacf 100644
@@ -298,6 +298,10 @@ int omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state)
 	if (omap_rev() == OMAP4430_REV_ES1_0)
 		return -ENXIO;
 
+	/* Use the achievable power state for the domain */
+	power_state = pwrdm_get_valid_lp_state(pm_info->pwrdm,
+					       false, power_state);
+
 	if (power_state == PWRDM_POWER_OFF)
 		cpu_state = 1;
 
Signature · 1 line
1.7.9.5
#5 lore raw

Re: [PATCH 4/7] ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain

In reply to Nishanth Menon
Quoted 16 lines · Nishanth Menon

powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file.

So, provide a function to easily query valid low power state that the power domain is allowed to go to.

Based on work originally done by Jean Pihet <[email protected]>
https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well.

Quoted 6 lines

Similar solutions have been done in product kernels in the past such as:
https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c

---

nit: this is part of a fixes series, but it's more of a new feature.

That being said, the feature is needed and looks OK, except for...

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(struct powerdomain *pwrdm) · line 1146

Quoted 6 lines
arch/arm/mach-omap2/powerdomain.c +6 -0
+up_search:
+	/* OK, no deeper ones, can we get a higher match? */
+	new_pwrst = req_state + 1;
+	while (!(pwrdm_states & BIT(new_pwrst))) {
+		/* BUG if we have messed up database */
+		BUG_ON(new_pwrst > PWRDM_POWER_ON);

I don't think this is BUG() worthy, and should have a saner way to recover.

Kevin

Reviewed-by on the v1 series
#11 lore raw
In reply to Nishanth Menon
Quoted 2 lines · Nishanth Menon

The following series are various fixes and improvements for powerdomain support in OMAP4+.

Ah, here I see "fixes and improvements" since I was about to nipick that the series contains more than just fixes.

Anyways, the series looks good to me. After fixing up the BUG_ON issue, feel free to add

Quoted 28 lines

This is part 1/6 series which eventually enables framework for suspend-to-ram and cpuidle for OMAP5 and DRA7

Each of series is based on v3.17-rc1 and this specific series is available:
weblink: https://github.com/nmenon/linux-2.6-playground/commits/push/v3.17/powerdomain-fixes

git repo: https://github.com/nmenon/linux-2.6-playground.git push/v3.17/powerdomain-fixes

An complete integrated branch is available here: https://github.com/nmenon/linux-2.6-playground/commits/testing/v3.17/cpu-idle-suspend-dra7-omap5-framework

Nishanth Menon (7):
ARM: OMAP: DRA7: powerdomain data: fix powerdomain powerstate
ARM: OMAP5: powerdomain data: fix powerdomain powerstate
ARM: OMAP2+: powerdomain: pwrdm_for_each_clkdm iterate only valid
clkdms
ARM: OMAP2+: powerdomain: introduce logic for finding valid power
domain
ARM: OMAP4+: PM: Make logic state programmable
ARM: OMAP4+: PM: use only valid low power state for suspend
ARM: OMAP4+: PM: Use only valid low power state for CPU hotplug

 arch/arm/mach-omap2/omap-mpuss-lowpower.c   |    4 ++
 arch/arm/mach-omap2/pm44xx.c                |    9 +++-
 arch/arm/mach-omap2/powerdomain.c           |   76 ++++++++++++++++++++++++++-
 arch/arm/mach-omap2/powerdomain.h           |    4 ++
 arch/arm/mach-omap2/powerdomains54xx_data.c |   12 ++---
 arch/arm/mach-omap2/powerdomains7xx_data.c  |   14 ++---
 6 files changed, 103 insertions(+), 16 deletions(-)
#6 lore raw

Re: [PATCH 4/7] ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain

In reply to Kevin Hilman
Quoted 29 lines · Kevin Hilman
Quoted 16 lines · Nishanth Menon

powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file.

So, provide a function to easily query valid low power state that the power domain is allowed to go to.

Based on work originally done by Jean Pihet <[email protected]>
https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well.

Quoted 6 lines

Similar solutions have been done in product kernels in the past such as:
https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c

---

nit: this is part of a fixes series, but it's more of a new feature.

That being said, the feature is needed and looks OK, except for...

Quoted 8 lines

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(struct powerdomain *pwrdm) · line 1146

Quoted 6 lines
arch/arm/mach-omap2/powerdomain.c +6 -0
+up_search:
+     /* OK, no deeper ones, can we get a higher match? */
+     new_pwrst = req_state + 1;
+     while (!(pwrdm_states & BIT(new_pwrst))) {
+             /* BUG if we have messed up database */
+             BUG_ON(new_pwrst > PWRDM_POWER_ON);

I don't think this is BUG() worthy, and should have a saner way to recover.

it is not even a legal value to have a power state higher than ON. I mean, yeah, we can do
if (new_pwrst > PWRDM_POWER_ON) {
pr_debug("powerdomain: %s: fix my powerdomain max to ON\n",

pwrdm->name);
         return PWRDM_POWER_ON;
}

if that is your suggestion here, personally, I would use a WARN at least here..

Signature · 3 lines
---
Regards,
Nishanth Menon
#12 lore raw
In reply to Nishanth Menon
Quoted 11 lines · Nishanth Menon

Hi,

The following series are various fixes and improvements for powerdomain support in OMAP4+.

This is part 1/6 series which eventually enables framework for suspend-to-ram and cpuidle for OMAP5 and DRA7

Each of series is based on v3.17-rc1 and this specific series is available:
weblink: https://github.com/nmenon/linux-2.6-playground/commits/push/v3.17/powerdomain-fixes

Series looks good to me. The achievable power state doesn't apeal much but with so many variations of SOCs, descopes etc, it probably makes sense.

Once you update Kevin's BUG() comments, feel free to add my ack.

Regards,
Santosh

#7 lore raw

Re: [PATCH 4/7] ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain

In reply to Nishanth Menon
Quoted 44 lines · Nishanth Menon
Quoted 29 lines · Kevin Hilman
Quoted 16 lines · Nishanth Menon

powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file.

So, provide a function to easily query valid low power state that the power domain is allowed to go to.

Based on work originally done by Jean Pihet <[email protected]>
https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well.

Quoted 6 lines

Similar solutions have been done in product kernels in the past such as:
https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c

---

nit: this is part of a fixes series, but it's more of a new feature.

That being said, the feature is needed and looks OK, except for...

Quoted 8 lines

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(struct powerdomain *pwrdm) · line 1146

Quoted 6 lines
arch/arm/mach-omap2/powerdomain.c +6 -0
+up_search:
+     /* OK, no deeper ones, can we get a higher match? */
+     new_pwrst = req_state + 1;
+     while (!(pwrdm_states & BIT(new_pwrst))) {
+             /* BUG if we have messed up database */
+             BUG_ON(new_pwrst > PWRDM_POWER_ON);

I don't think this is BUG() worthy, and should have a saner way to recover.

it is not even a legal value to have a power state higher than ON. I mean, yeah, we can do
if (new_pwrst > PWRDM_POWER_ON) {
pr_debug("powerdomain: %s: fix my powerdomain max to ON\n",

Quoted 5 lines
pwrdm->name);
         return PWRDM_POWER_ON;
}

if that is your suggestion here, personally, I would use a WARN at least here..

WARN, pr_warn() as you like.

The point is that BUG* calls panic() and locks up the system tight. As what your'e adding is not fatal to the entire system, you should not be using bug. From asm-generic/bug.h:

*
* Don't use BUG() or BUG_ON() unless there's really no way out; one
* example might be detecting data structure corruption in the middle
* of an operation that can't be backed out of. If the (sub)system
* can somehow continue operating, perhaps with reduced functionality,
* it's probably not BUG-worthy.
*
* If you're tempted to BUG(), think again: is completely giving up
* really the *only* solution? There are usually better options, where
* users don't need to reboot ASAP and can mostly shut down cleanly. */

#13 lore raw

PATCH v2 4/7 ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain

In reply to Nishanth Menon

powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file.

So, provide a function to easily query valid low power state that the power domain is allowed to go to.

Based on work originally done by Jean Pihet <[email protected]>
https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well.

Similar solutions have been done in product kernels in the past such as:
https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c

---

Not posting the entire series again and updating just this patch..

V2: drop BUG in favor of WARN, picked up Santosh and Kevin's acks.

V1: https://patchwork.kernel.org/patch/4764131/

 arch/arm/mach-omap2/powerdomain.c |   76 +++++++++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/powerdomain.h |    3 ++
 2 files changed, 79 insertions(+)
arch/arm/mach-omap2/powerdomain.c +76 -0
index f391948..7fb033e 100644
@@ -1081,6 +1081,82 @@ int pwrdm_post_transition(struct powerdomain *pwrdm)
 }
 
 /**
+ * pwrdm_get_valid_lp_state() - Find best match deep power state
+ * @pwrdm:	power domain for which we want to find best match
+ * @is_logic_state: Are we looking for logic state match here? Should
+ *		    be one of PWRDM_xxx macro values
+ * @req_state:	requested power state
+ *
+ * Returns: closest match for requested power state. default fallback
+ * is RET for logic state and ON for power state.
+ *
+ * This does a search from the power domain data looking for the
+ * closest valid power domain state that the hardware can achieve.
+ * PRCM definitions for PWRSTCTRL allows us to program whatever
+ * configuration we'd like, and PRCM will actually attempt such
+ * a transition, however if the powerdomain does not actually support it,
+ * we endup with a hung system. The valid power domain states are already
+ * available in our powerdomain data files. So this function tries to do
+ * the following:
+ * a) find if we have an exact match to the request - no issues.
+ * b) else find if a deeper power state is possible.
+ * c) failing which, it tries to find closest higher power state for the
+ * request.
+ */
+u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm,
+			    bool is_logic_state, u8 req_state)
+{
+	u8 pwrdm_states = is_logic_state ? pwrdm->pwrsts_logic_ret :
+			pwrdm->pwrsts;
+	/* For logic, ret is highest and others, ON is highest */
+	u8 default_pwrst = is_logic_state ? PWRDM_POWER_RET : PWRDM_POWER_ON;
+	u8 new_pwrst;
+	bool found;
+
+	/* If it is already supported, nothing to search */
+	if (pwrdm_states & BIT(req_state))
+		return req_state;
+
+	if (!req_state)
+		goto up_search;
+
+	/*
+	 * So, we dont have a exact match
+	 * Can we get a deeper power state match?
+	 */
+	new_pwrst = req_state - 1;
+	found = true;
+	while (!(pwrdm_states & BIT(new_pwrst))) {
+		/* No match even at OFF? Not available */
+		if (new_pwrst == PWRDM_POWER_OFF) {
+			found = false;
+			break;
+		}
+		new_pwrst--;
+	}
+
+	if (found)
+		goto done;
+
+up_search:
+	/* OK, no deeper ones, can we get a higher match? */
+	new_pwrst = req_state + 1;
+	while (!(pwrdm_states & BIT(new_pwrst))) {
+		if (new_pwrst > PWRDM_POWER_ON) {
+			WARN(1, "powerdomain: %s: Fix max powerstate to ON\n",
+			     pwrdm->name);
+			return PWRDM_POWER_ON;
+		}
+
+		if (new_pwrst == default_pwrst)
+			break;
+		new_pwrst++;
+	}
+done:
+	return new_pwrst;
+}
+
+/**
  * omap_set_pwrdm_state - change a powerdomain's current power state
  * @pwrdm: struct powerdomain * to change the power state of
  * @pwrst: power state to change to
arch/arm/mach-omap2/powerdomain.h +3 -0
index a754c82..11bd4dd 100644
@@ -220,6 +220,9 @@ struct voltagedomain *pwrdm_get_voltdm(struct powerdomain *pwrdm);
 
 int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm);
 
+u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm,
+			    bool is_logic_state, u8 req_state);
+
 int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst);
 int pwrdm_read_next_pwrst(struct powerdomain *pwrdm);
 int pwrdm_read_pwrst(struct powerdomain *pwrdm);
Signature · 1 line
1.7.9.5
#14 lore raw

Re: [PATCH V2 4/7] ARM: OMAP2+: powerdomain: introduce logic for finding valid power domain

Quoted 20 lines · Nishanth Menon

powerdomain configuration in OMAP is done using PWRSTCTRL register for each power domain. However, PRCM lets us write any value we'd like to the logic and power domain target states, however the SoC integration tends to actually function only at a few discrete states. These valid states are already in our powerdomains_xxx_data.c file.

So, provide a function to easily query valid low power state that the power domain is allowed to go to.

Based on work originally done by Jean Pihet <[email protected]>
https://patchwork.kernel.org/patch/1325091/ . There is no attempt to create a new powerdomain solution here, except fixing issues seen attempting invalid programming attempts. Future consolidation to the generic powerdomain framework should consider this requirement as well.

Similar solutions have been done in product kernels in the past such as:
https://android.googlesource.com/kernel/omap.git/+blame/android-omap-panda-3.0/arch/arm/mach-omap2/pm44xx.c

Quoted 8 lines

---

Not posting the entire series again and updating just this patch..

V2: drop BUG in favor of WARN, picked up Santosh and Kevin's acks.

Looks good, thanks,

Kevin