diff mbox series

[v5,11/16] mach-snapdragon: fixup power-domains

Message ID 20240328-b4-qcom-livetree-v5-11-4e98228b3d03@linaro.org
State Superseded
Delegated to: Caleb Connolly
Headers show
Series Qualcomm platform USB support | expand

Commit Message

Caleb Connolly March 28, 2024, 5:59 p.m. UTC
We don't support the RPM(h)PD power domains in U-Boot, and we don't need
to - the necessary resources are on, and we aren't going to enter any
low power modes.

We could try using a no-op device, but this requires adding a compatible
for every platform, and just pollutes the driver model. So instead let's
just remove every "power-domains" property that references the RPM(h)pd
power controller. This takes <1ms as we're using OF_LIVE.

Of note, this only applies to drivers which are loading post-relocation.
Drivers loaded pre-reloc that reference the rpm(h)pd still need
DM_FLAG_DEFAULT_PD_CTRL_OFF in their flags.

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 arch/arm/mach-snapdragon/of_fixup.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Sumit Garg April 1, 2024, 4:47 a.m. UTC | #1
On Thu, 28 Mar 2024 at 23:29, Caleb Connolly <caleb.connolly@linaro.org> wrote:
>
> We don't support the RPM(h)PD power domains in U-Boot, and we don't need
> to - the necessary resources are on, and we aren't going to enter any
> low power modes.
>
> We could try using a no-op device, but this requires adding a compatible
> for every platform, and just pollutes the driver model. So instead let's
> just remove every "power-domains" property that references the RPM(h)pd
> power controller. This takes <1ms as we're using OF_LIVE.
>
> Of note, this only applies to drivers which are loading post-relocation.
> Drivers loaded pre-reloc that reference the rpm(h)pd still need
> DM_FLAG_DEFAULT_PD_CTRL_OFF in their flags.
>
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>  arch/arm/mach-snapdragon/of_fixup.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>

Acked-by: Sumit Garg <sumit.garg@linaro.org>

-Sumit

> diff --git a/arch/arm/mach-snapdragon/of_fixup.c b/arch/arm/mach-snapdragon/of_fixup.c
> index 4fdfed2dff16..3f7ac227bd09 100644
> --- a/arch/arm/mach-snapdragon/of_fixup.c
> +++ b/arch/arm/mach-snapdragon/of_fixup.c
> @@ -21,8 +21,9 @@
>  #include <dm/of_access.h>
>  #include <dm/of.h>
>  #include <fdt_support.h>
>  #include <linux/errno.h>
> +#include <stdlib.h>
>  #include <time.h>
>
>  /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3
>   * USB controllers. Rather than requiring source level DT changes, we fix up
> @@ -109,8 +110,38 @@ static void fixup_usb_nodes(void)
>                         log_warning("Failed to fixup node %s: %d\n", glue_np->name, ret);
>         }
>  }
>
> +/* Remove all references to the rpmhpd device */
> +static void fixup_power_domains(void)
> +{
> +       struct device_node *pd = NULL, *np = NULL;
> +       struct property *prop;
> +       const __be32 *val;
> +
> +       /* All Qualcomm platforms name the rpm(h)pd "power-controller" */
> +       for_each_of_allnodes(pd) {
> +               if (pd->name && !strcmp("power-controller", pd->name))
> +                       break;
> +       }
> +
> +       /* Sanity check that this is indeed a power domain controller */
> +       if (!of_find_property(pd, "#power-domain-cells", NULL)) {
> +               log_err("Found power-controller but it doesn't have #power-domain-cells\n");
> +               return;
> +       }
> +
> +       /* Remove all references to the power domain controller */
> +       for_each_of_allnodes(np) {
> +               if (!(prop = of_find_property(np, "power-domains", NULL)))
> +                       continue;
> +
> +               val = prop->value;
> +               if (val[0] == cpu_to_fdt32(pd->phandle))
> +                       of_remove_property(np, prop);
> +       }
> +}
> +
>  #define time_call(func, ...) \
>         do { \
>                 u64 start = timer_get_us(); \
>                 func(__VA_ARGS__); \
> @@ -119,5 +150,6 @@ static void fixup_usb_nodes(void)
>
>  void qcom_of_fixup_nodes(void)
>  {
>         time_call(fixup_usb_nodes);
> +       time_call(fixup_power_domains);
>  }
>
> --
> 2.44.0
>
Neil Armstrong April 2, 2024, 8:32 a.m. UTC | #2
On 28/03/2024 18:59, Caleb Connolly wrote:
> We don't support the RPM(h)PD power domains in U-Boot, and we don't need
> to - the necessary resources are on, and we aren't going to enter any
> low power modes.
> 
> We could try using a no-op device, but this requires adding a compatible
> for every platform, and just pollutes the driver model. So instead let's
> just remove every "power-domains" property that references the RPM(h)pd
> power controller. This takes <1ms as we're using OF_LIVE.
> 
> Of note, this only applies to drivers which are loading post-relocation.
> Drivers loaded pre-reloc that reference the rpm(h)pd still need
> DM_FLAG_DEFAULT_PD_CTRL_OFF in their flags.
> 
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
>   arch/arm/mach-snapdragon/of_fixup.c | 32 ++++++++++++++++++++++++++++++++
>   1 file changed, 32 insertions(+)
> 
> diff --git a/arch/arm/mach-snapdragon/of_fixup.c b/arch/arm/mach-snapdragon/of_fixup.c
> index 4fdfed2dff16..3f7ac227bd09 100644
> --- a/arch/arm/mach-snapdragon/of_fixup.c
> +++ b/arch/arm/mach-snapdragon/of_fixup.c
> @@ -21,8 +21,9 @@
>   #include <dm/of_access.h>
>   #include <dm/of.h>
>   #include <fdt_support.h>
>   #include <linux/errno.h>
> +#include <stdlib.h>
>   #include <time.h>
>   
>   /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3
>    * USB controllers. Rather than requiring source level DT changes, we fix up
> @@ -109,8 +110,38 @@ static void fixup_usb_nodes(void)
>   			log_warning("Failed to fixup node %s: %d\n", glue_np->name, ret);
>   	}
>   }
>   
> +/* Remove all references to the rpmhpd device */
> +static void fixup_power_domains(void)
> +{
> +	struct device_node *pd = NULL, *np = NULL;
> +	struct property *prop;
> +	const __be32 *val;
> +
> +	/* All Qualcomm platforms name the rpm(h)pd "power-controller" */
> +	for_each_of_allnodes(pd) {
> +		if (pd->name && !strcmp("power-controller", pd->name))
> +			break;
> +	}
> +
> +	/* Sanity check that this is indeed a power domain controller */
> +	if (!of_find_property(pd, "#power-domain-cells", NULL)) {
> +		log_err("Found power-controller but it doesn't have #power-domain-cells\n");
> +		return;
> +	}
> +
> +	/* Remove all references to the power domain controller */
> +	for_each_of_allnodes(np) {
> +		if (!(prop = of_find_property(np, "power-domains", NULL)))
> +			continue;
> +
> +		val = prop->value;
> +		if (val[0] == cpu_to_fdt32(pd->phandle))
> +			of_remove_property(np, prop);
> +	}
> +}
> +
>   #define time_call(func, ...) \
>   	do { \
>   		u64 start = timer_get_us(); \
>   		func(__VA_ARGS__); \
> @@ -119,5 +150,6 @@ static void fixup_usb_nodes(void)
>   
>   void qcom_of_fixup_nodes(void)
>   {
>   	time_call(fixup_usb_nodes);
> +	time_call(fixup_power_domains);
>   }
> 

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

Also tested on SM8550 & SM8650, so:

Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
diff mbox series

Patch

diff --git a/arch/arm/mach-snapdragon/of_fixup.c b/arch/arm/mach-snapdragon/of_fixup.c
index 4fdfed2dff16..3f7ac227bd09 100644
--- a/arch/arm/mach-snapdragon/of_fixup.c
+++ b/arch/arm/mach-snapdragon/of_fixup.c
@@ -21,8 +21,9 @@ 
 #include <dm/of_access.h>
 #include <dm/of.h>
 #include <fdt_support.h>
 #include <linux/errno.h>
+#include <stdlib.h>
 #include <time.h>
 
 /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3
  * USB controllers. Rather than requiring source level DT changes, we fix up
@@ -109,8 +110,38 @@  static void fixup_usb_nodes(void)
 			log_warning("Failed to fixup node %s: %d\n", glue_np->name, ret);
 	}
 }
 
+/* Remove all references to the rpmhpd device */
+static void fixup_power_domains(void)
+{
+	struct device_node *pd = NULL, *np = NULL;
+	struct property *prop;
+	const __be32 *val;
+
+	/* All Qualcomm platforms name the rpm(h)pd "power-controller" */
+	for_each_of_allnodes(pd) {
+		if (pd->name && !strcmp("power-controller", pd->name))
+			break;
+	}
+
+	/* Sanity check that this is indeed a power domain controller */
+	if (!of_find_property(pd, "#power-domain-cells", NULL)) {
+		log_err("Found power-controller but it doesn't have #power-domain-cells\n");
+		return;
+	}
+
+	/* Remove all references to the power domain controller */
+	for_each_of_allnodes(np) {
+		if (!(prop = of_find_property(np, "power-domains", NULL)))
+			continue;
+
+		val = prop->value;
+		if (val[0] == cpu_to_fdt32(pd->phandle))
+			of_remove_property(np, prop);
+	}
+}
+
 #define time_call(func, ...) \
 	do { \
 		u64 start = timer_get_us(); \
 		func(__VA_ARGS__); \
@@ -119,5 +150,6 @@  static void fixup_usb_nodes(void)
 
 void qcom_of_fixup_nodes(void)
 {
 	time_call(fixup_usb_nodes);
+	time_call(fixup_power_domains);
 }