Skip to content

Commit a8ffaa0

Browse files
adithya2306karthik558
authored andcommitted
drivers/misc: Introduce kernelspace battery saver mode
Change-Id: I4ed95be27f8059804ad6a90dc928f30ce84c679f Signed-off-by: K A R T H I K <karthik.lal558@gmail.com>
1 parent 628f0a7 commit a8ffaa0

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

drivers/misc/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ config FORCE_FAST_CHARGE
606606
help
607607
This allows users to override default charge rate for USB
608608

609+
config BATTERY_SAVER
610+
bool "Battery saver mode for kernelspace"
611+
help
612+
This driver creates a sysfs toggle that can be enabled when
613+
battery saver mode is activated in userspace, and provides
614+
functions to check the status of battery saver and to activate
615+
it from anywhere in the kernel.
616+
617+
The former can be used to disable features that may otherwise
618+
drain battery faster, such as CPU and DDR boosting.
619+
620+
If in doubt, say N.
621+
609622
source "drivers/misc/c2port/Kconfig"
610623
source "drivers/misc/eeprom/Kconfig"
611624
source "drivers/misc/cb710/Kconfig"

drivers/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ obj-$(CONFIG_UID_SYS_STATS) += uid_sys_stats.o
6666
obj-$(CONFIG_MEMORY_STATE_TIME) += memory_state_time.o
6767
obj-$(CONFIG_QPNP_MISC) += qpnp-misc.o
6868
obj-$(CONFIG_ANT_CHECK) += ant_check.o
69+
obj-$(CONFIG_BATTERY_SAVER) += battery_saver.o
6970

7071
obj-$(CONFIG_OKL4_USER_VIRQ) += okl4-virq.o
7172
obj-$(CONFIG_OKL4_RINGBUF) += okl4-ringbuf.o

drivers/misc/battery_saver.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (C) 2020 Adithya R <gh0strider.2k18.reborn@gmail.com>.
4+
*/
5+
6+
#include <linux/module.h>
7+
#include <linux/moduleparam.h>
8+
#include <linux/battery_saver.h>
9+
10+
static bool enabled = false;
11+
module_param(enabled, bool, 0644);
12+
13+
// returns whether battery saver is enabled or disabled
14+
bool is_battery_saver_on(void)
15+
{
16+
return enabled;
17+
}
18+
19+
// enable or disable battery saver mode
20+
void update_battery_saver(bool status)
21+
{
22+
enabled = status;
23+
}

include/linux/battery_saver.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (C) 2020 Adithya R <gh0strider.2k18.reborn@gmail.com>.
4+
*/
5+
6+
#ifndef _BATTERY_SAVER_H_
7+
#define _BATTERY_SAVER_H_
8+
9+
#include <linux/types.h>
10+
11+
#ifdef CONFIG_BATTERY_SAVER
12+
bool is_battery_saver_on(void);
13+
void enable_battery_saver(bool status);
14+
#else
15+
static inline bool is_battery_saver_on()
16+
{
17+
return false;
18+
}
19+
static inline void update_battery_saver(bool status)
20+
{
21+
}
22+
#endif
23+
24+
#endif /* _BATTERY_SAVER_H_ */

0 commit comments

Comments
 (0)