mirror of
https://github.com/S3NEO/android_kernel_samsung_msm8226.git
synced 2024-11-07 03:47:13 +00:00
battery: sec_battery: Migrate to alarmtimer interface
Change-Id: If211b431adb97a496c13d824a6d3da2898ad6d5c Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>
This commit is contained in:
parent
945451f25e
commit
596fa615e0
2 changed files with 47 additions and 37 deletions
|
@ -211,7 +211,6 @@ static int sec_bat_set_charge(
|
|||
bool enable)
|
||||
{
|
||||
union power_supply_propval val;
|
||||
ktime_t current_time;
|
||||
struct timespec ts;
|
||||
#ifdef CONFIG_CONTROL_OTG_POPUP
|
||||
if(battery->cable_type == POWER_SUPPLY_TYPE_OTG)
|
||||
|
@ -221,8 +220,7 @@ static int sec_bat_set_charge(
|
|||
psy_do_property(battery->pdata->charger_name, set,
|
||||
POWER_SUPPLY_PROP_STATUS, val);
|
||||
|
||||
current_time = alarm_get_elapsed_realtime();
|
||||
ts = ktime_to_timespec(current_time);
|
||||
get_monotonic_boottime(&ts);
|
||||
|
||||
if (enable) {
|
||||
val.intval = battery->cable_type;
|
||||
|
@ -1308,23 +1306,28 @@ static void sec_bat_event_program_alarm(
|
|||
struct sec_battery_info *battery, int seconds)
|
||||
{
|
||||
ktime_t low_interval = ktime_set(seconds - 10, 0);
|
||||
ktime_t slack = ktime_set(20, 0);
|
||||
ktime_t next;
|
||||
|
||||
next = ktime_add(battery->last_event_time, low_interval);
|
||||
alarm_start_range(&battery->event_termination_alarm,
|
||||
next, ktime_add(next, slack));
|
||||
/* The original slack time called for, 20 seconds, exceeds
|
||||
* the length allowed for an unsigned long in nanoseconds. Use
|
||||
* ULONG_MAX instead
|
||||
*/
|
||||
hrtimer_start_range_ns(&battery->event_termination_hrtimer,
|
||||
next, ULONG_MAX, HRTIMER_MODE_ABS);
|
||||
}
|
||||
|
||||
static void sec_bat_event_expired_timer_func(struct alarm *alarm)
|
||||
enum hrtimer_restart sec_bat_event_expired_timer_func(struct hrtimer *timer)
|
||||
{
|
||||
struct sec_battery_info *battery =
|
||||
container_of(alarm, struct sec_battery_info,
|
||||
event_termination_alarm);
|
||||
container_of(timer, struct sec_battery_info,
|
||||
event_termination_hrtimer);
|
||||
|
||||
battery->event &= (~battery->event_wait);
|
||||
dev_info(battery->dev,
|
||||
"%s: event expired (0x%x)\n", __func__, battery->event);
|
||||
|
||||
return HRTIMER_NORESTART;
|
||||
}
|
||||
|
||||
static void sec_bat_event_set(
|
||||
|
@ -1343,7 +1346,7 @@ static void sec_bat_event_set(
|
|||
return;
|
||||
}
|
||||
|
||||
alarm_cancel(&battery->event_termination_alarm);
|
||||
hrtimer_cancel(&battery->event_termination_hrtimer);
|
||||
battery->event &= (~battery->event_wait);
|
||||
|
||||
if (enable) {
|
||||
|
@ -1359,7 +1362,7 @@ static void sec_bat_event_set(
|
|||
return; /* nothing to clear */
|
||||
}
|
||||
battery->event_wait = event;
|
||||
battery->last_event_time = alarm_get_elapsed_realtime();
|
||||
battery->last_event_time = ktime_get_boottime();
|
||||
|
||||
sec_bat_event_program_alarm(battery,
|
||||
battery->pdata->event_waiting_time);
|
||||
|
@ -1489,11 +1492,9 @@ static bool sec_bat_time_management(
|
|||
struct sec_battery_info *battery)
|
||||
{
|
||||
unsigned long charging_time;
|
||||
ktime_t current_time;
|
||||
struct timespec ts;
|
||||
|
||||
current_time = alarm_get_elapsed_realtime();
|
||||
ts = ktime_to_timespec(current_time);
|
||||
get_monotonic_boottime(&ts);
|
||||
|
||||
if (battery->charging_start_time == 0) {
|
||||
dev_dbg(battery->dev,
|
||||
|
@ -1928,7 +1929,7 @@ static void sec_bat_get_battery_info(
|
|||
static struct timespec old_ts;
|
||||
struct timespec c_ts;
|
||||
|
||||
c_ts = ktime_to_timespec(alarm_get_elapsed_realtime());
|
||||
c_ts = ktime_to_timespec(ktime_get_boottime());
|
||||
#endif
|
||||
|
||||
psy_do_property(battery->pdata->fuelgauge_name, get,
|
||||
|
@ -2078,18 +2079,21 @@ static void sec_bat_program_alarm(
|
|||
struct sec_battery_info *battery, int seconds)
|
||||
{
|
||||
ktime_t low_interval = ktime_set(seconds, 0);
|
||||
ktime_t slack = ktime_set(10, 0);
|
||||
ktime_t next;
|
||||
|
||||
next = ktime_add(battery->last_poll_time, low_interval);
|
||||
alarm_start_range(&battery->polling_alarm,
|
||||
next, ktime_add(next, slack));
|
||||
/* The original slack time called for, 10 seconds, exceeds
|
||||
* the length allowed for an unsigned long in nanoseconds. Use
|
||||
* ULONG_MAX instead
|
||||
*/
|
||||
hrtimer_start_range_ns(&battery->polling_hrtimer,
|
||||
next, ULONG_MAX, HRTIMER_MODE_ABS);
|
||||
}
|
||||
|
||||
static void sec_bat_alarm(struct alarm *alarm)
|
||||
enum hrtimer_restart sec_bat_alarm(struct hrtimer *timer)
|
||||
{
|
||||
struct sec_battery_info *battery = container_of(alarm,
|
||||
struct sec_battery_info, polling_alarm);
|
||||
struct sec_battery_info *battery = container_of(timer,
|
||||
struct sec_battery_info, polling_hrtimer);
|
||||
|
||||
/* In wake up, monitor work will be queued in complete function
|
||||
* To avoid duplicated queuing of monitor work,
|
||||
|
@ -2100,6 +2104,8 @@ static void sec_bat_alarm(struct alarm *alarm)
|
|||
queue_delayed_work(battery->monitor_wqueue, &battery->monitor_work, 0);
|
||||
dev_dbg(battery->dev, "%s: Activated\n", __func__);
|
||||
}
|
||||
|
||||
return HRTIMER_NORESTART;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2240,7 +2246,7 @@ static void sec_bat_set_polling(
|
|||
polling_time_temp * HZ);
|
||||
break;
|
||||
case SEC_BATTERY_MONITOR_ALARM:
|
||||
battery->last_poll_time = alarm_get_elapsed_realtime();
|
||||
battery->last_poll_time = ktime_get_boottime();
|
||||
if (battery->pdata->monitor_initial_count) {
|
||||
battery->pdata->monitor_initial_count--;
|
||||
sec_bat_program_alarm(battery, 1);
|
||||
|
@ -2316,7 +2322,7 @@ static void sec_bat_monitor_work(
|
|||
|
||||
dev_dbg(battery->dev, "%s: Start\n", __func__);
|
||||
|
||||
c_ts = ktime_to_timespec(alarm_get_elapsed_realtime());
|
||||
c_ts = ktime_to_timespec(ktime_get_boottime());
|
||||
|
||||
/* monitor once after wakeup */
|
||||
if (battery->polling_in_sleep) {
|
||||
|
@ -4659,9 +4665,11 @@ static int __devinit sec_battery_probe(struct platform_device *pdev)
|
|||
battery->swelling_mode = false;
|
||||
battery->charging_block = false;
|
||||
#endif
|
||||
alarm_init(&battery->event_termination_alarm,
|
||||
ANDROID_ALARM_ELAPSED_REALTIME,
|
||||
sec_bat_event_expired_timer_func);
|
||||
hrtimer_init(&battery->event_termination_hrtimer,
|
||||
CLOCK_BOOTTIME,
|
||||
HRTIMER_MODE_ABS);
|
||||
battery->event_termination_hrtimer.function =
|
||||
&sec_bat_event_expired_timer_func;
|
||||
|
||||
battery->temp_highlimit_threshold =
|
||||
pdata->temp_highlimit_threshold_normal;
|
||||
|
@ -4760,10 +4768,12 @@ static int __devinit sec_battery_probe(struct platform_device *pdev)
|
|||
sec_bat_polling_work);
|
||||
break;
|
||||
case SEC_BATTERY_MONITOR_ALARM:
|
||||
battery->last_poll_time = alarm_get_elapsed_realtime();
|
||||
alarm_init(&battery->polling_alarm,
|
||||
ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
|
||||
sec_bat_alarm);
|
||||
battery->last_poll_time = ktime_get_boottime();
|
||||
hrtimer_init(&battery->polling_hrtimer,
|
||||
CLOCK_BOOTTIME,
|
||||
HRTIMER_MODE_ABS);
|
||||
battery->polling_hrtimer.function =
|
||||
&sec_bat_alarm;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -4974,13 +4984,13 @@ static int __devexit sec_battery_remove(struct platform_device *pdev)
|
|||
cancel_delayed_work(&battery->polling_work);
|
||||
break;
|
||||
case SEC_BATTERY_MONITOR_ALARM:
|
||||
alarm_cancel(&battery->polling_alarm);
|
||||
hrtimer_cancel(&battery->polling_hrtimer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
alarm_cancel(&battery->event_termination_alarm);
|
||||
hrtimer_cancel(&battery->event_termination_hrtimer);
|
||||
flush_workqueue(battery->monitor_wqueue);
|
||||
destroy_workqueue(battery->monitor_wqueue);
|
||||
wake_lock_destroy(&battery->monitor_wake_lock);
|
||||
|
@ -5019,7 +5029,7 @@ static int sec_battery_prepare(struct device *dev)
|
|||
cancel_delayed_work(&battery->polling_work);
|
||||
break;
|
||||
case SEC_BATTERY_MONITOR_ALARM:
|
||||
alarm_cancel(&battery->polling_alarm);
|
||||
hrtimer_cancel(&battery->polling_hrtimer);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -5062,7 +5072,7 @@ static void sec_battery_complete(struct device *dev)
|
|||
|
||||
/* cancel current alarm and reset after monitor work */
|
||||
if (battery->pdata->polling_type == SEC_BATTERY_MONITOR_ALARM)
|
||||
alarm_cancel(&battery->polling_alarm);
|
||||
hrtimer_cancel(&battery->polling_hrtimer);
|
||||
|
||||
wake_lock(&battery->monitor_wake_lock);
|
||||
queue_delayed_work(battery->monitor_wqueue,
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#define __SEC_BATTERY_H __FILE__
|
||||
|
||||
#include <linux/battery/sec_charging_common.h>
|
||||
#include <linux/android_alarm.h>
|
||||
#include <linux/hrtimer.h>
|
||||
#include <linux/wakelock.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/proc_fs.h>
|
||||
|
@ -99,13 +99,13 @@ struct sec_battery_info {
|
|||
bool fuelgauge_in_sleep;
|
||||
|
||||
struct delayed_work polling_work;
|
||||
struct alarm polling_alarm;
|
||||
struct hrtimer polling_hrtimer;
|
||||
ktime_t last_poll_time;
|
||||
|
||||
/* event set */
|
||||
unsigned int event;
|
||||
unsigned int event_wait;
|
||||
struct alarm event_termination_alarm;
|
||||
struct hrtimer event_termination_hrtimer;
|
||||
ktime_t last_event_time;
|
||||
|
||||
/* battery check */
|
||||
|
|
Loading…
Reference in a new issue