Skip to content

Commit

Permalink
drivers/misc: Introduce kernelspace battery saver mode
Browse files Browse the repository at this point in the history
Change-Id: I4ed95be27f8059804ad6a90dc928f30ce84c679f
Signed-off-by: K A R T H I K <[email protected]>
  • Loading branch information
adithya2306 authored and karthik558 committed Apr 24, 2021
1 parent 628f0a7 commit a8ffaa0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions drivers/misc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,19 @@ config FORCE_FAST_CHARGE
help
This allows users to override default charge rate for USB

config BATTERY_SAVER
bool "Battery saver mode for kernelspace"
help
This driver creates a sysfs toggle that can be enabled when
battery saver mode is activated in userspace, and provides
functions to check the status of battery saver and to activate
it from anywhere in the kernel.

The former can be used to disable features that may otherwise
drain battery faster, such as CPU and DDR boosting.

If in doubt, say N.

source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions drivers/misc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ obj-$(CONFIG_UID_SYS_STATS) += uid_sys_stats.o
obj-$(CONFIG_MEMORY_STATE_TIME) += memory_state_time.o
obj-$(CONFIG_QPNP_MISC) += qpnp-misc.o
obj-$(CONFIG_ANT_CHECK) += ant_check.o
obj-$(CONFIG_BATTERY_SAVER) += battery_saver.o

obj-$(CONFIG_OKL4_USER_VIRQ) += okl4-virq.o
obj-$(CONFIG_OKL4_RINGBUF) += okl4-ringbuf.o
Expand Down
23 changes: 23 additions & 0 deletions drivers/misc/battery_saver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 Adithya R <[email protected]>.
*/

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/battery_saver.h>

static bool enabled = false;
module_param(enabled, bool, 0644);

// returns whether battery saver is enabled or disabled
bool is_battery_saver_on(void)
{
return enabled;
}

// enable or disable battery saver mode
void update_battery_saver(bool status)
{
enabled = status;
}
24 changes: 24 additions & 0 deletions include/linux/battery_saver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 Adithya R <[email protected]>.
*/

#ifndef _BATTERY_SAVER_H_
#define _BATTERY_SAVER_H_

#include <linux/types.h>

#ifdef CONFIG_BATTERY_SAVER
bool is_battery_saver_on(void);
void enable_battery_saver(bool status);
#else
static inline bool is_battery_saver_on()
{
return false;
}
static inline void update_battery_saver(bool status)
{
}
#endif

#endif /* _BATTERY_SAVER_H_ */

0 comments on commit a8ffaa0

Please sign in to comment.