add hrtimer support to qpnp-sec-charger.c and msm_thermal.c (not fully)

This commit is contained in:
leonardo meitz 2018-05-12 21:30:17 +02:00 committed by Francescodario Cuzzocrea
parent 3f26a2eb2f
commit 3fdd9a3455
2 changed files with 72 additions and 56 deletions

View File

@ -32,10 +32,10 @@
#include <linux/regulator/machine.h>
#include <linux/of_batterydata.h>
#include <linux/qpnp-revid.h>
#include <linux/android_alarm.h>
#include <linux/hrtimer.h>
/* SAMSUNG charging specification */
#include <linux/android_alarm.h>
#include <linux/hrtimer.h>
#if defined(CONFIG_USB_SWITCH_RT8973)
#include <linux/platform_data/rt8973.h>
#elif defined(CONFIG_SM5502_MUIC)
@ -403,8 +403,9 @@ struct qpnp_chg_chip {
struct qpnp_vadc_chip *vadc_dev;
struct qpnp_adc_tm_chip *adc_tm_dev;
struct mutex jeita_configure_lock;
struct mutex batfet_vreg_lock;
struct alarm reduce_power_stage_alarm;
struct mutex batfet_vreg_lock;
struct hrtimer hrtimer_reduce_power_stage_alarm;
//struct alarm reduce_power_stage_alarm;
struct work_struct reduce_power_stage_work;
bool power_stage_workaround_running;
@ -426,7 +427,8 @@ struct qpnp_chg_chip {
unsigned int update_time;
unsigned int sleep_update_time;
unsigned int polling_time;
struct alarm polling_alarm;
struct hrtimer hrtimer_polling_alarm;
//struct alarm polling_alarm;
ktime_t last_update_time;
/* charging and re-charging time management */
unsigned long charging_start_time;
@ -454,7 +456,8 @@ struct qpnp_chg_chip {
/* battery event handling */
unsigned int event;
unsigned int event_wait;
struct alarm event_termination_alarm;
struct hrtimer hrtimer_event_termination_alarm;
//struct alarm event_termination_alarm;
ktime_t last_event_time;
/* Battery temperature monitoring parameters */
int temp_high_block;
@ -569,7 +572,7 @@ static void sec_bat_event_program_alarm(struct qpnp_chg_chip *chip, int seconds)
* Function to check event timer expiry
*
*/
static void sec_bat_event_expired_timer_func(struct alarm *alarm);
enum hrtimer_restart sec_bat_event_expired_timer_func(struct hrtimer *timer);
/*
@ -673,7 +676,7 @@ static void sec_bat_program_alarm(struct qpnp_chg_chip *chip, int polling_time);
* Function to be executed when battery alarm expires
* status accordingly
*/
static void sec_bat_polling_alarm_expired(struct alarm *alarm);
enum hrtimer_restart sec_bat_polling_alarm_expired(struct hrtimer *timer);
#endif
@ -4183,9 +4186,9 @@ qpnp_chg_reduce_power_stage(struct qpnp_chg_chip *chip)
if (usb_present && usb_ma_above_wall) {
getnstimeofday(&ts);
ts.tv_sec += POWER_STAGE_REDUCE_CHECK_PERIOD_SECONDS;
alarm_start_range(&chip->reduce_power_stage_alarm,
hrtimer_start_range_ns(&chip->hrtimer_reduce_power_stage_alarm,
timespec_to_ktime(ts),
timespec_to_ktime(ts));
ULONG_MAX, HRTIMER_MODE_ABS);
} else {
pr_debug("stopping power stage workaround\n");
chip->power_stage_workaround_running = false;
@ -4220,13 +4223,16 @@ qpnp_chg_reduce_power_stage_work(struct work_struct *work)
qpnp_chg_reduce_power_stage(chip);
}
static void
qpnp_chg_reduce_power_stage_callback(struct alarm *alarm)
enum hrtimer_restart
qpnp_chg_reduce_power_stage_callback(struct hrtimer *hrtimer)
{
struct qpnp_chg_chip *chip = container_of(alarm, struct qpnp_chg_chip,
reduce_power_stage_alarm);
struct qpnp_chg_chip *chip = container_of(hrtimer, struct qpnp_chg_chip,
hrtimer_reduce_power_stage_alarm);
schedule_work(&chip->reduce_power_stage_work);
return HRTIMER_NORESTART;
}
static int
@ -5792,19 +5798,19 @@ static void sec_bat_event_program_alarm(
struct qpnp_chg_chip *chip, int seconds)
{
ktime_t low_interval = ktime_set(seconds - 10, 0);
ktime_t slack = ktime_set(20, 0);
//ktime_t slack = ktime_set(20, 0);
ktime_t next;
next = ktime_add(chip->last_event_time, low_interval);
alarm_start_range(&chip->event_termination_alarm,
next, ktime_add(next, slack));
hrtimer_start_range_ns(&chip->hrtimer_event_termination_alarm,
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 *hrtimer)
{
struct qpnp_chg_chip *chip =
container_of(alarm, struct qpnp_chg_chip,
event_termination_alarm);
container_of(hrtimer, struct qpnp_chg_chip,
hrtimer_event_termination_alarm);
if(chip->event == 0) {
dev_dbg(chip->dev,
@ -5827,6 +5833,8 @@ static void sec_bat_event_expired_timer_func(struct alarm *alarm)
pr_err("SEC BTM: set normal temperature limits low_block(%d) low_recover(%d)\n",
chip->temp_low_block,chip->temp_low_recover);
}
return HRTIMER_NORESTART;
}
@ -5847,7 +5855,7 @@ static void sec_bat_event_set(
return;
}
alarm_cancel(&chip->event_termination_alarm);
hrtimer_cancel(&chip->hrtimer_event_termination_alarm);
chip->event &= (~chip->event_wait);
if (enable) {
@ -5865,7 +5873,7 @@ static void sec_bat_event_set(
__func__ , event, chip->event);
chip->event_wait = event;
chip->last_event_time = alarm_get_elapsed_realtime();
chip->last_event_time = ktime_get_boottime();
sec_bat_event_program_alarm(chip,
chip->batt_pdata->event_waiting_time);
@ -5896,7 +5904,7 @@ static bool sec_chg_time_management(struct qpnp_chg_chip *chip)
struct timespec ts;
int batt_capacity = 0;
current_time = alarm_get_elapsed_realtime();
current_time = ktime_get_boottime();
ts = ktime_to_timespec(current_time);
/* device discharging */
@ -6163,7 +6171,7 @@ static void sec_handle_cable_insertion_removal(struct qpnp_chg_chip *chip)
prev_batt_status,chip->batt_status);
}
// alarm_cancel(&chip->event_termination_alarm);
// hrtimer_cancel(&chip->event_termination_alarm);
schedule_delayed_work(&chip->sec_bat_monitor_work, 0);
wake_lock_timeout(&chip->cable_wake_lock, 3*HZ);
@ -6218,7 +6226,7 @@ static void sec_pm8226_start_charging(struct qpnp_chg_chip *chip)
ktime_t current_time;
struct timespec ts;
current_time = alarm_get_elapsed_realtime();
current_time = ktime_get_boottime();
ts = ktime_to_timespec(current_time);
if(chip->ovp_uvlo_state != 0) {
@ -6446,7 +6454,7 @@ static void sec_bat_monitor(struct work_struct *work)
if (chip->recent_reported_soc == 100) {
ktime_t current_time;
struct timespec ts;
current_time = alarm_get_elapsed_realtime();
current_time = ktime_get_boottime();
ts = ktime_to_timespec(current_time);
pr_err("first phase charging done: update battery UI FULL \n");
chip->batt_status = POWER_SUPPLY_STATUS_FULL;
@ -6676,24 +6684,26 @@ static void sec_bat_temperature_monitor(struct qpnp_chg_chip *chip)
static void sec_bat_program_alarm(struct qpnp_chg_chip *chip, int polling_time)
{
ktime_t low_interval = ktime_set(polling_time, 0);
ktime_t slack = ktime_set(10, 0);
//ktime_t slack = ktime_set(10, 0);
ktime_t next;
chip->last_update_time = alarm_get_elapsed_realtime();
chip->last_update_time = ktime_get_boottime();
next = ktime_add(chip->last_update_time, low_interval);
alarm_start_range(&chip->polling_alarm,
next, ktime_add(next, slack));
hrtimer_start_range_ns(&chip->hrtimer_polling_alarm,
next, ULONG_MAX, HRTIMER_MODE_ABS);
}
static void sec_bat_polling_alarm_expired(struct alarm *alarm)
enum hrtimer_restart sec_bat_polling_alarm_expired(struct hrtimer *timer)
{
struct qpnp_chg_chip *chip = container_of(alarm,
struct qpnp_chg_chip, polling_alarm);
struct qpnp_chg_chip *chip = container_of(timer,
struct qpnp_chg_chip, hrtimer_polling_alarm);
schedule_delayed_work(&chip->sec_bat_monitor_work, 0);
return HRTIMER_NORESTART;
}
#endif
@ -6759,8 +6769,9 @@ qpnp_charger_probe(struct spmi_device *spmi)
}
mutex_init(&chip->jeita_configure_lock);
alarm_init(&chip->reduce_power_stage_alarm, ANDROID_ALARM_RTC_WAKEUP,
qpnp_chg_reduce_power_stage_callback);
hrtimer_init(&chip->hrtimer_reduce_power_stage_alarm, CLOCK_BOOTTIME,
HRTIMER_MODE_ABS);
chip->hrtimer_reduce_power_stage_alarm.function = &qpnp_chg_reduce_power_stage_callback;
INIT_WORK(&chip->reduce_power_stage_work,
qpnp_chg_reduce_power_stage_work);
mutex_init(&chip->batfet_vreg_lock);
@ -7143,12 +7154,12 @@ qpnp_charger_probe(struct spmi_device *spmi)
sec_bat_create_attrs(chip->batt_psy.dev);
//sec_fg_create_attrs(chip->fg_psy.dev);
alarm_init(&chip->event_termination_alarm,
ANDROID_ALARM_ELAPSED_REALTIME,
sec_bat_event_expired_timer_func);
alarm_init(&chip->polling_alarm,
ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
sec_bat_polling_alarm_expired);
hrtimer_init(&chip->hrtimer_event_termination_alarm,
CLOCK_BOOTTIME, HRTIMER_MODE_ABS);
chip->hrtimer_event_termination_alarm.function = sec_bat_event_expired_timer_func;
hrtimer_init(&chip->hrtimer_polling_alarm,
CLOCK_BOOTTIME, HRTIMER_MODE_ABS);
chip->hrtimer_polling_alarm.function = sec_bat_polling_alarm_expired;
wake_lock_init(&chip->monitor_wake_lock, WAKE_LOCK_SUSPEND,
"sec-charger-monitor");
@ -7284,9 +7295,9 @@ static int sec_qpnp_chg_prepare(struct device *dev)
}
cancel_delayed_work(&chip->sec_bat_monitor_work);
alarm_cancel(&chip->polling_alarm);
hrtimer_cancel(&chip->hrtimer_polling_alarm);
chip->last_update_time = alarm_get_elapsed_realtime();
chip->last_update_time = ktime_get_boottime();
sec_bat_program_alarm(chip, chip->polling_time);
#ifdef SEC_CHARGER_DEBUG
pr_err("%s battery update time (%d seconds) !!\n",
@ -7304,7 +7315,7 @@ static void sec_qpnp_chg_complete(struct device *dev)
pr_err("%s start\n", __func__);
#endif
cancel_delayed_work(&chip->sec_bat_monitor_work);
alarm_cancel(&chip->polling_alarm);
hrtimer_cancel(&chip->hrtimer_polling_alarm);
chip->polling_time = chip->update_time;
schedule_delayed_work(&chip->sec_bat_monitor_work, 0);

View File

@ -33,7 +33,7 @@
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/io.h>
#include <linux/android_alarm.h>
#include <linux/hrtimer.h>
#include <linux/thermal.h>
#include <mach/rpm-regulator.h>
#include <mach/rpm-regulator-smd.h>
@ -58,7 +58,7 @@ static bool core_control_enabled;
static uint32_t cpus_offlined;
static DEFINE_MUTEX(core_control_mutex);
static uint32_t wakeup_ms;
static struct alarm thermal_rtc;
static struct hrtimer thermal_rtc_hrtimer;
static struct kobject *tt_kobj;
static struct kobject *cc_kobj;
static struct work_struct timer_work;
@ -1438,11 +1438,11 @@ static void thermal_rtc_setup(void)
ktime_t wakeup_time;
ktime_t curr_time;
curr_time = alarm_get_elapsed_realtime();
curr_time = ktime_get_boottime();
wakeup_time = ktime_add_us(curr_time,
(wakeup_ms * USEC_PER_MSEC));
alarm_start_range(&thermal_rtc, wakeup_time,
wakeup_time);
hrtimer_start_range_ns(&thermal_rtc_hrtimer, wakeup_time,
ULONG_MAX, HRTIMER_MODE_ABS);
pr_debug("%s: Current Time: %ld %ld, Alarm set to: %ld %ld\n",
KBUILD_MODNAME,
ktime_to_timeval(curr_time).tv_sec,
@ -1457,13 +1457,15 @@ static void timer_work_fn(struct work_struct *work)
sysfs_notify(tt_kobj, NULL, "wakeup_ms");
}
static void thermal_rtc_callback(struct alarm *al)
enum hrtimer_restart thermal_rtc_callback(struct hrtimer *timer)
{
struct timeval ts;
ts = ktime_to_timeval(alarm_get_elapsed_realtime());
struct timespec ts;
get_monotonic_boottime(&ts);
schedule_work(&timer_work);
pr_debug("%s: Time on alarm expiry: %ld %ld\n", KBUILD_MODNAME,
ts.tv_sec, ts.tv_usec);
ts.tv_sec, ts.tv_nsec / 1000);
return HRTIMER_NORESTART;
}
static int hotplug_notify(enum thermal_trip_type type, int temp, void *data)
@ -2140,7 +2142,7 @@ static ssize_t store_wakeup_ms(struct kobject *kobj,
pr_debug("%s: Timer started for %ums\n", KBUILD_MODNAME,
wakeup_ms);
} else {
ret = alarm_cancel(&thermal_rtc);
ret = hrtimer_cancel(&thermal_rtc_hrtimer);
if (ret)
pr_debug("%s: Timer canceled\n", KBUILD_MODNAME);
else
@ -3396,8 +3398,11 @@ int __init msm_thermal_late_init(void)
msm_thermal_add_vdd_rstr_nodes();
msm_thermal_add_ocr_nodes();
msm_thermal_add_default_temp_limit_nodes();
alarm_init(&thermal_rtc, ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP,
thermal_rtc_callback);
hrtimer_init(&thermal_rtc_hrtimer,
CLOCK_BOOTTIME,
HRTIMER_MODE_ABS);
thermal_rtc_hrtimer.function=
&thermal_rtc_callback;
INIT_WORK(&timer_work, timer_work_fn);
msm_thermal_add_timer_nodes();