diff mbox series

[1/2] thermal: ti-soc-thermal: Enable addition power management

Message ID 20200818154633.5421-1-aford173@gmail.com (mailing list archive)
State New, archived
Delegated to: Daniel Lezcano
Headers show
Series [1/2] thermal: ti-soc-thermal: Enable addition power management | expand

Commit Message

Adam Ford Aug. 18, 2020, 3:46 p.m. UTC
The bandgap sensor can be idled when the processor is too, but it
isn't currently being done, so the power consumption of OMAP3
boards can elevated if the bangap sensor is enabled.

This patch attempts to use some additional power management
to idle the clock to the bandgap when not needed.

Signed-off-by: Adam Ford <aford173@gmail.com>

Comments

Tony Lindgren Aug. 19, 2020, 4:59 a.m. UTC | #1
* Adam Ford <aford173@gmail.com> [200818 15:46]:
> @@ -1153,6 +1166,38 @@ static int ti_bandgap_suspend(struct device *dev)
>  	return err;
>  }
>  
> +static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
> +				  unsigned long cmd, void *v)
> +{
> +	struct ti_bandgap *bgp;
> +
> +	bgp = container_of(nb, struct ti_bandgap, nb);
> +
> +	spin_lock(&bgp->lock);
> +	switch (cmd) {
> +	case CPU_CLUSTER_PM_ENTER:
> +		if (bgp->is_suspended)
> +			break;
> +		ti_bandgap_save_ctxt(bgp);
> +		ti_bandgap_power(bgp, false);
> +		if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
> +			clk_disable(bgp->fclock);
> +		break;
> +	case CPU_CLUSTER_PM_ENTER_FAILED:
> +	case CPU_CLUSTER_PM_EXIT:
> +		if (bgp->is_suspended)
> +			break;
> +		if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
> +			clk_enable(bgp->fclock);
> +		ti_bandgap_power(bgp, true);
> +		ti_bandgap_restore_ctxt(bgp);
> +		break;
> +	}
> +	spin_unlock(&bgp->lock);
> +
> +	return NOTIFY_OK;
> +}

Hmm to me it looks like is_suspended is not used right now?
I guess you want to set it in ti_bandgap_suspend() and clear
it in ti_bandgap_resume()?

Otherwise looks good to me, I can't test the power consumption
right now though so you may want to check it to make sure
device still hits off mode during idle.

Regards,

Tony
Adam Ford Aug. 19, 2020, 12:21 p.m. UTC | #2
On Tue, Aug 18, 2020 at 11:58 PM Tony Lindgren <tony@atomide.com> wrote:
>
> * Adam Ford <aford173@gmail.com> [200818 15:46]:
> > @@ -1153,6 +1166,38 @@ static int ti_bandgap_suspend(struct device *dev)
> >       return err;
> >  }
> >
> > +static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
> > +                               unsigned long cmd, void *v)
> > +{
> > +     struct ti_bandgap *bgp;
> > +
> > +     bgp = container_of(nb, struct ti_bandgap, nb);
> > +
> > +     spin_lock(&bgp->lock);
> > +     switch (cmd) {
> > +     case CPU_CLUSTER_PM_ENTER:
> > +             if (bgp->is_suspended)
> > +                     break;
> > +             ti_bandgap_save_ctxt(bgp);
> > +             ti_bandgap_power(bgp, false);
> > +             if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
> > +                     clk_disable(bgp->fclock);
> > +             break;
> > +     case CPU_CLUSTER_PM_ENTER_FAILED:
> > +     case CPU_CLUSTER_PM_EXIT:
> > +             if (bgp->is_suspended)
> > +                     break;
> > +             if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
> > +                     clk_enable(bgp->fclock);
> > +             ti_bandgap_power(bgp, true);
> > +             ti_bandgap_restore_ctxt(bgp);
> > +             break;
> > +     }
> > +     spin_unlock(&bgp->lock);
> > +
> > +     return NOTIFY_OK;
> > +}
>
> Hmm to me it looks like is_suspended is not used right now?
> I guess you want to set it in ti_bandgap_suspend() and clear
> it in ti_bandgap_resume()?
>
> Otherwise looks good to me, I can't test the power consumption
> right now though so you may want to check it to make sure
> device still hits off mode during idle.

I have a V2.  Do you want me to re-post 2/2 with V2 as no change, or
should I just submit this patch alone?

adam
>
> Regards,
>
> Tony
Tony Lindgren Aug. 19, 2020, 12:54 p.m. UTC | #3
* Adam Ford <aford173@gmail.com> [200819 12:21]:
> On Tue, Aug 18, 2020 at 11:58 PM Tony Lindgren <tony@atomide.com> wrote:
> >
> > * Adam Ford <aford173@gmail.com> [200818 15:46]:
> > > @@ -1153,6 +1166,38 @@ static int ti_bandgap_suspend(struct device *dev)
> > >       return err;
> > >  }
> > >
> > > +static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
> > > +                               unsigned long cmd, void *v)
> > > +{
> > > +     struct ti_bandgap *bgp;
> > > +
> > > +     bgp = container_of(nb, struct ti_bandgap, nb);
> > > +
> > > +     spin_lock(&bgp->lock);
> > > +     switch (cmd) {
> > > +     case CPU_CLUSTER_PM_ENTER:
> > > +             if (bgp->is_suspended)
> > > +                     break;
> > > +             ti_bandgap_save_ctxt(bgp);
> > > +             ti_bandgap_power(bgp, false);
> > > +             if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
> > > +                     clk_disable(bgp->fclock);
> > > +             break;
> > > +     case CPU_CLUSTER_PM_ENTER_FAILED:
> > > +     case CPU_CLUSTER_PM_EXIT:
> > > +             if (bgp->is_suspended)
> > > +                     break;
> > > +             if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
> > > +                     clk_enable(bgp->fclock);
> > > +             ti_bandgap_power(bgp, true);
> > > +             ti_bandgap_restore_ctxt(bgp);
> > > +             break;
> > > +     }
> > > +     spin_unlock(&bgp->lock);
> > > +
> > > +     return NOTIFY_OK;
> > > +}
> >
> > Hmm to me it looks like is_suspended is not used right now?
> > I guess you want to set it in ti_bandgap_suspend() and clear
> > it in ti_bandgap_resume()?
> >
> > Otherwise looks good to me, I can't test the power consumption
> > right now though so you may want to check it to make sure
> > device still hits off mode during idle.
> 
> I have a V2.  Do you want me to re-post 2/2 with V2 as no change, or
> should I just submit this patch alone?

Up to you, might make it easier for other folks to follow if the
whole series is reposted.

Regards,

Tony
diff mbox series

Patch

diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
index ab19ceff6e2a..923ef3abb867 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c
@@ -25,10 +25,18 @@ 
 #include <linux/of_platform.h>
 #include <linux/of_irq.h>
 #include <linux/io.h>
+#include <linux/cpu_pm.h>
+#include <linux/device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 
 #include "ti-bandgap.h"
 
 static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id);
+static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
+				  unsigned long cmd, void *v);
 
 /***   Helper functions to access registers and their bitfields   ***/
 
@@ -1008,6 +1016,9 @@  int ti_bandgap_probe(struct platform_device *pdev)
 		}
 	}
 
+	bgp->nb.notifier_call = bandgap_omap_cpu_notifier;
+	cpu_pm_register_notifier(&bgp->nb);
+
 	return 0;
 
 remove_last_cooling:
@@ -1041,7 +1052,9 @@  int ti_bandgap_remove(struct platform_device *pdev)
 	struct ti_bandgap *bgp = platform_get_drvdata(pdev);
 	int i;
 
-	/* First thing is to remove sensor interfaces */
+	cpu_pm_unregister_notifier(&bgp->nb);
+
+	/* Remove sensor interfaces */
 	for (i = 0; i < bgp->conf->sensor_count; i++) {
 		if (bgp->conf->sensors[i].unregister_cooling)
 			bgp->conf->sensors[i].unregister_cooling(bgp, i);
@@ -1153,6 +1166,38 @@  static int ti_bandgap_suspend(struct device *dev)
 	return err;
 }
 
+static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
+				  unsigned long cmd, void *v)
+{
+	struct ti_bandgap *bgp;
+
+	bgp = container_of(nb, struct ti_bandgap, nb);
+
+	spin_lock(&bgp->lock);
+	switch (cmd) {
+	case CPU_CLUSTER_PM_ENTER:
+		if (bgp->is_suspended)
+			break;
+		ti_bandgap_save_ctxt(bgp);
+		ti_bandgap_power(bgp, false);
+		if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+			clk_disable(bgp->fclock);
+		break;
+	case CPU_CLUSTER_PM_ENTER_FAILED:
+	case CPU_CLUSTER_PM_EXIT:
+		if (bgp->is_suspended)
+			break;
+		if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
+			clk_enable(bgp->fclock);
+		ti_bandgap_power(bgp, true);
+		ti_bandgap_restore_ctxt(bgp);
+		break;
+	}
+	spin_unlock(&bgp->lock);
+
+	return NOTIFY_OK;
+}
+
 static int ti_bandgap_resume(struct device *dev)
 {
 	struct ti_bandgap *bgp = dev_get_drvdata(dev);
diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.h b/drivers/thermal/ti-soc-thermal/ti-bandgap.h
index fce4657e9486..ed0ea4b17b25 100644
--- a/drivers/thermal/ti-soc-thermal/ti-bandgap.h
+++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.h
@@ -12,6 +12,10 @@ 
 #include <linux/spinlock.h>
 #include <linux/types.h>
 #include <linux/err.h>
+#include <linux/cpu_pm.h>
+#include <linux/device.h>
+#include <linux/pm_runtime.h>
+#include <linux/pm.h>
 
 struct gpio_desc;
 
@@ -203,6 +207,8 @@  struct ti_bandgap {
 	int				irq;
 	struct gpio_desc		*tshut_gpiod;
 	u32				clk_rate;
+	struct notifier_block		nb;
+	unsigned int is_suspended:1;
 };
 
 /**