Skip to content

Commit 5093402

Browse files
aford173dlezcano
authored andcommitted
thermal: ti-soc-thermal: Enable addition power management
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> Reported-by: kernel test robot <lkp@intel.com> Tested-by: Andreas Kemnade <andreas@kemnade.info> # GTA04 Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20200911123157.759379-1-aford173@gmail.com
1 parent 92ad897 commit 5093402

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

drivers/thermal/ti-soc-thermal/ti-bandgap.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@
2525
#include <linux/of_platform.h>
2626
#include <linux/of_irq.h>
2727
#include <linux/io.h>
28+
#include <linux/cpu_pm.h>
29+
#include <linux/device.h>
30+
#include <linux/pm_runtime.h>
31+
#include <linux/pm.h>
32+
#include <linux/of.h>
33+
#include <linux/of_device.h>
2834

2935
#include "ti-bandgap.h"
3036

3137
static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id);
38+
#ifdef CONFIG_PM_SLEEP
39+
static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
40+
unsigned long cmd, void *v);
41+
#endif
3242

3343
/*** Helper functions to access registers and their bitfields ***/
3444

@@ -1008,6 +1018,11 @@ int ti_bandgap_probe(struct platform_device *pdev)
10081018
}
10091019
}
10101020

1021+
#ifdef CONFIG_PM_SLEEP
1022+
bgp->nb.notifier_call = bandgap_omap_cpu_notifier;
1023+
cpu_pm_register_notifier(&bgp->nb);
1024+
#endif
1025+
10111026
return 0;
10121027

10131028
remove_last_cooling:
@@ -1041,7 +1056,9 @@ int ti_bandgap_remove(struct platform_device *pdev)
10411056
struct ti_bandgap *bgp = platform_get_drvdata(pdev);
10421057
int i;
10431058

1044-
/* First thing is to remove sensor interfaces */
1059+
cpu_pm_unregister_notifier(&bgp->nb);
1060+
1061+
/* Remove sensor interfaces */
10451062
for (i = 0; i < bgp->conf->sensor_count; i++) {
10461063
if (bgp->conf->sensors[i].unregister_cooling)
10471064
bgp->conf->sensors[i].unregister_cooling(bgp, i);
@@ -1150,9 +1167,43 @@ static int ti_bandgap_suspend(struct device *dev)
11501167
if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
11511168
clk_disable_unprepare(bgp->fclock);
11521169

1170+
bgp->is_suspended = true;
1171+
11531172
return err;
11541173
}
11551174

1175+
static int bandgap_omap_cpu_notifier(struct notifier_block *nb,
1176+
unsigned long cmd, void *v)
1177+
{
1178+
struct ti_bandgap *bgp;
1179+
1180+
bgp = container_of(nb, struct ti_bandgap, nb);
1181+
1182+
spin_lock(&bgp->lock);
1183+
switch (cmd) {
1184+
case CPU_CLUSTER_PM_ENTER:
1185+
if (bgp->is_suspended)
1186+
break;
1187+
ti_bandgap_save_ctxt(bgp);
1188+
ti_bandgap_power(bgp, false);
1189+
if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
1190+
clk_disable(bgp->fclock);
1191+
break;
1192+
case CPU_CLUSTER_PM_ENTER_FAILED:
1193+
case CPU_CLUSTER_PM_EXIT:
1194+
if (bgp->is_suspended)
1195+
break;
1196+
if (TI_BANDGAP_HAS(bgp, CLK_CTRL))
1197+
clk_enable(bgp->fclock);
1198+
ti_bandgap_power(bgp, true);
1199+
ti_bandgap_restore_ctxt(bgp);
1200+
break;
1201+
}
1202+
spin_unlock(&bgp->lock);
1203+
1204+
return NOTIFY_OK;
1205+
}
1206+
11561207
static int ti_bandgap_resume(struct device *dev)
11571208
{
11581209
struct ti_bandgap *bgp = dev_get_drvdata(dev);
@@ -1161,6 +1212,7 @@ static int ti_bandgap_resume(struct device *dev)
11611212
clk_prepare_enable(bgp->fclock);
11621213

11631214
ti_bandgap_power(bgp, true);
1215+
bgp->is_suspended = false;
11641216

11651217
return ti_bandgap_restore_ctxt(bgp);
11661218
}

drivers/thermal/ti-soc-thermal/ti-bandgap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <linux/spinlock.h>
1313
#include <linux/types.h>
1414
#include <linux/err.h>
15+
#include <linux/cpu_pm.h>
16+
#include <linux/device.h>
17+
#include <linux/pm_runtime.h>
18+
#include <linux/pm.h>
1519

1620
struct gpio_desc;
1721

@@ -203,6 +207,8 @@ struct ti_bandgap {
203207
int irq;
204208
struct gpio_desc *tshut_gpiod;
205209
u32 clk_rate;
210+
struct notifier_block nb;
211+
unsigned int is_suspended:1;
206212
};
207213

208214
/**

0 commit comments

Comments
 (0)