Add support to change the shutdown threshold.
The default value for shutdown is less than 5% of battery life left. Once the system hits this value (or the one specified by the user) the system will shutdown. The soc_shutdown value can be changed to 0 to disable this feature, just realise that the system will lose power and unsafely shutdown. Also added install and remove functionality.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
|
||||
#!/bin/bash
|
||||
sudo cp -vf oneUpPower.ko /lib/modules/`uname -r`/kernel/drivers/power/supply/oneUpPower.ko
|
||||
if ! grep -qF "oneUpPower" /etc/modules
|
||||
then
|
||||
sudo sh -c 'echo "oneUpPower" >> /etc/modules'
|
||||
fi
|
||||
sudo sh -c 'echo "options oneUpPower soc_shutdown=5" > /etc/modprobe.d/oneUpPower.conf'
|
||||
sudo depmod -a
|
||||
ls /lib/modules/`uname -r`/kernel/drivers/power/supply/
|
||||
sudo insmod oneUpPower.ko
|
||||
sync
|
||||
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ struct PowerStatus {
|
||||
static int get_battery_property(struct power_supply *psy,
|
||||
enum power_supply_property psp,
|
||||
union power_supply_propval *val);
|
||||
|
||||
static int get_ac_property(struct power_supply *psy,
|
||||
enum power_supply_property psp,
|
||||
union power_supply_propval *val );
|
||||
@@ -90,7 +91,7 @@ static int get_ac_property(struct power_supply *psy,
|
||||
//
|
||||
// Globals
|
||||
//
|
||||
static int critical_power_level = 5; // Default setting is 5% of power left for critical
|
||||
static int soc_shutdown = 5; // Default setting is 5% of power left for critical
|
||||
static int ac_online = 1; // Are we connected to an external power source?
|
||||
static bool module_initialized = false; // Has the driver been initialized?
|
||||
static struct task_struct *monitor_task = NULL; // Place to store the monito task...
|
||||
@@ -354,7 +355,7 @@ static int system_monitor( void *args )
|
||||
soc = check_battery_state( client );
|
||||
|
||||
set_current_state( TASK_INTERRUPTIBLE );
|
||||
if( !plugged_in && (soc < critical_power_level) ){
|
||||
if( !plugged_in && (soc < soc_shutdown) ){
|
||||
// not pluggged in and below critical state, shutdown
|
||||
PR_INFO( "Performing system shutdown unplugged and power is at %d\n",soc);
|
||||
shutdown_helper();
|
||||
@@ -607,6 +608,43 @@ static void __exit oneup_power_exit(void)
|
||||
}
|
||||
module_exit(oneup_power_exit);
|
||||
|
||||
static int param_set_soc_shutdown( const char *key, const struct kernel_param *kp )
|
||||
{
|
||||
long soc;
|
||||
|
||||
if( kstrtol( key, 10, &soc ) == 0 ){
|
||||
if( soc == 0 ){
|
||||
PR_INFO( "Disabling automatic shutdown when battery is below threshold.\n");
|
||||
soc_shutdown = 0;
|
||||
return 0;
|
||||
}
|
||||
else if( (soc > 1) && (soc < 20)){
|
||||
PR_INFO( "Changing automatic shutdown when battery is below %ld%%\n",soc);
|
||||
soc_shutdown = soc;
|
||||
return 0;
|
||||
} else {
|
||||
PR_INFO( "Invalid value, 0 to disable, 1 -> 20 to shutdown.\n" );
|
||||
}
|
||||
} else {
|
||||
PR_INFO( "Could not convert to integer\n" );
|
||||
}
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static int param_get_soc_shutdown( char *buffer, const struct kernel_param *kp )
|
||||
{
|
||||
return sprintf( buffer, "%d", soc_shutdown );
|
||||
}
|
||||
|
||||
static const struct kernel_param_ops param_ops_soc_shutdown = {
|
||||
.set = param_set_soc_shutdown,
|
||||
.get = param_get_soc_shutdown,
|
||||
};
|
||||
|
||||
#define param_check_soc_shutdown(name,p) __param_check(name,p,void);
|
||||
module_param( soc_shutdown, soc_shutdown, 0644 );
|
||||
MODULE_PARM_DESC(soc_shutdown, "Shutdown system when the battery state of charge is lower than this value.");
|
||||
|
||||
MODULE_DESCRIPTION("Power supply driver for Argon40 1UP");
|
||||
MODULE_AUTHOR("Jeff Curless <jeff@thecurlesses.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
#!/bin/bash
|
||||
sudo rmmod oneUpPower
|
||||
sudo rm -vf /lib/modules/`uname -r`/kernel/drivers/power/supply/oneUpPower.ko
|
||||
sudo sh -c "sed -i '/oneUpPower/d' /etc/modules"
|
||||
sudo rm -vf /etc/modprobe.d/oneUpPower.conf
|
||||
sudo depmod -a
|
||||
sync
|
||||
|
||||
Reference in New Issue
Block a user