diff options
author | Mao Jinlong <jinlmao@codeaurora.org> | 2017-10-27 11:15:55 +0800 |
---|---|---|
committer | Mao Jinlong <jinlmao@codeaurora.org> | 2018-12-27 18:22:40 +0530 |
commit | 5e0025e7664769fd15e6d968e10e800a88aabcfb (patch) | |
tree | e682e375e6a44f0b616eef1cb8280dc4551bfb14 | |
parent | 86bc01ea1bf42a60ef21bdba5ecdb5a50b6a7a25 (diff) |
Revert "rtc: alarm: Add power-on alarm feature"
This reverts commit 2e1a4aefef66db901f9a906b79e30187f10dbecb.
Power off alarm is not set via alarmtimer now. Remove the changes
of power off alarm's previous design.
Change-Id: I0f60bec0d94c93c4f2a89ae86a1b0a0d04aa9e48
Signed-off-by: Mao Jinlong <jinlmao@codeaurora.org>
-rw-r--r-- | drivers/rtc/qpnp-rtc.c | 4 | ||||
-rw-r--r-- | fs/timerfd.c | 32 | ||||
-rw-r--r-- | include/linux/alarmtimer.h | 5 | ||||
-rw-r--r-- | include/uapi/linux/time.h | 1 | ||||
-rw-r--r-- | kernel/time/alarmtimer.c | 145 |
5 files changed, 15 insertions, 172 deletions
diff --git a/drivers/rtc/qpnp-rtc.c b/drivers/rtc/qpnp-rtc.c index bafcebb810de..af51225a9066 100644 --- a/drivers/rtc/qpnp-rtc.c +++ b/drivers/rtc/qpnp-rtc.c @@ -22,7 +22,6 @@ #include <linux/spmi.h> #include <linux/platform_device.h> #include <linux/spinlock.h> -#include <linux/alarmtimer.h> /* RTC/ALARM Register offsets */ #define REG_OFFSET_ALARM_RW 0x40 @@ -608,9 +607,6 @@ static int qpnp_rtc_probe(struct platform_device *pdev) goto fail_rtc_enable; } - /* Init power_on_alarm after adding rtc device */ - power_on_alarm_init(); - /* Request the alarm IRQ */ rc = request_any_context_irq(rtc_dd->rtc_alarm_irq, qpnp_alarm_trigger, IRQF_TRIGGER_RISING, diff --git a/fs/timerfd.c b/fs/timerfd.c index 0548c572839c..1327a02ec778 100644 --- a/fs/timerfd.c +++ b/fs/timerfd.c @@ -50,8 +50,7 @@ static DEFINE_SPINLOCK(cancel_lock); static inline bool isalarm(struct timerfd_ctx *ctx) { return ctx->clockid == CLOCK_REALTIME_ALARM || - ctx->clockid == CLOCK_BOOTTIME_ALARM || - ctx->clockid == CLOCK_POWEROFF_ALARM; + ctx->clockid == CLOCK_BOOTTIME_ALARM; } /* @@ -143,8 +142,7 @@ static void timerfd_setup_cancel(struct timerfd_ctx *ctx, int flags) { spin_lock(&ctx->cancel_lock); if ((ctx->clockid == CLOCK_REALTIME || - ctx->clockid == CLOCK_REALTIME_ALARM || - ctx->clockid == CLOCK_POWEROFF_ALARM) && + ctx->clockid == CLOCK_REALTIME_ALARM) && (flags & TFD_TIMER_ABSTIME) && (flags & TFD_TIMER_CANCEL_ON_SET)) { if (!ctx->might_cancel) { ctx->might_cancel = true; @@ -176,7 +174,6 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags, enum hrtimer_mode htmode; ktime_t texp; int clockid = ctx->clockid; - enum alarmtimer_type type; htmode = (flags & TFD_TIMER_ABSTIME) ? HRTIMER_MODE_ABS: HRTIMER_MODE_REL; @@ -187,8 +184,10 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags, ctx->tintv = timespec_to_ktime(ktmr->it_interval); if (isalarm(ctx)) { - type = clock2alarm(ctx->clockid); - alarm_init(&ctx->t.alarm, type, timerfd_alarmproc); + alarm_init(&ctx->t.alarm, + ctx->clockid == CLOCK_REALTIME_ALARM ? + ALARM_REALTIME : ALARM_BOOTTIME, + timerfd_alarmproc); } else { hrtimer_init(&ctx->t.tmr, clockid, htmode); hrtimer_set_expires(&ctx->t.tmr, texp); @@ -388,7 +387,6 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) { int ufd; struct timerfd_ctx *ctx; - enum alarmtimer_type type; /* Check the TFD_* constants for consistency. */ BUILD_BUG_ON(TFD_CLOEXEC != O_CLOEXEC); @@ -399,8 +397,7 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) clockid != CLOCK_REALTIME && clockid != CLOCK_REALTIME_ALARM && clockid != CLOCK_BOOTTIME && - clockid != CLOCK_BOOTTIME_ALARM && - clockid != CLOCK_POWEROFF_ALARM)) + clockid != CLOCK_BOOTTIME_ALARM)) return -EINVAL; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -411,12 +408,13 @@ SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags) spin_lock_init(&ctx->cancel_lock); ctx->clockid = clockid; - if (isalarm(ctx)) { - type = clock2alarm(ctx->clockid); - alarm_init(&ctx->t.alarm, type, timerfd_alarmproc); - } else { + if (isalarm(ctx)) + alarm_init(&ctx->t.alarm, + ctx->clockid == CLOCK_REALTIME_ALARM ? + ALARM_REALTIME : ALARM_BOOTTIME, + timerfd_alarmproc); + else hrtimer_init(&ctx->t.tmr, clockid, HRTIMER_MODE_ABS); - } ctx->moffs = ktime_mono_to_real((ktime_t){ .tv64 = 0 }); @@ -488,10 +486,6 @@ static int do_timerfd_settime(int ufd, int flags, ret = timerfd_setup(ctx, flags, new); spin_unlock_irq(&ctx->wqh.lock); - - if (ctx->clockid == CLOCK_POWEROFF_ALARM) - set_power_on_alarm(); - fdput(f); return ret; } diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h index 38a75b5d4792..9333ae59c8c8 100644 --- a/include/linux/alarmtimer.h +++ b/include/linux/alarmtimer.h @@ -5,12 +5,10 @@ #include <linux/hrtimer.h> #include <linux/timerqueue.h> #include <linux/rtc.h> -#include <linux/types.h> enum alarmtimer_type { ALARM_REALTIME, ALARM_BOOTTIME, - ALARM_POWEROFF_REALTIME, ALARM_NUMTYPE, }; @@ -50,9 +48,6 @@ void alarm_start_relative(struct alarm *alarm, ktime_t start); void alarm_restart(struct alarm *alarm); int alarm_try_to_cancel(struct alarm *alarm); int alarm_cancel(struct alarm *alarm); -void set_power_on_alarm(void); -void power_on_alarm_init(void); -enum alarmtimer_type clock2alarm(clockid_t clockid); u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval); u64 alarm_forward_now(struct alarm *alarm, ktime_t interval); diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 7fe799e867d4..e75e1b6ff27f 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -56,7 +56,6 @@ struct itimerval { #define CLOCK_BOOTTIME_ALARM 9 #define CLOCK_SGI_CYCLE 10 /* Hardware specific */ #define CLOCK_TAI 11 -#define CLOCK_POWEROFF_ALARM 12 #define MAX_CLOCKS 16 #define CLOCKS_MASK (CLOCK_REALTIME | CLOCK_MONOTONIC) diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c index 271b37995a89..4ac0a040e4ef 100644 --- a/kernel/time/alarmtimer.c +++ b/kernel/time/alarmtimer.c @@ -29,7 +29,6 @@ #ifdef CONFIG_MSM_PM #include "lpm-levels.h" #endif -#include <linux/workqueue.h> /** * struct alarm_base - Alarm timer bases @@ -51,116 +50,12 @@ static ktime_t freezer_delta; static DEFINE_SPINLOCK(freezer_delta_lock); static struct wakeup_source *ws; -static struct delayed_work work; -static struct workqueue_struct *power_off_alarm_workqueue; #ifdef CONFIG_RTC_CLASS /* rtc timer and device for setting alarm wakeups at suspend */ static struct rtc_timer rtctimer; static struct rtc_device *rtcdev; static DEFINE_SPINLOCK(rtcdev_lock); -static struct mutex power_on_alarm_lock; -static struct alarm init_alarm; - -/** - * power_on_alarm_init - Init power on alarm value - * - * Read rtc alarm value after device booting up and add this alarm - * into alarm queue. - */ -void power_on_alarm_init(void) -{ - struct rtc_wkalrm rtc_alarm; - struct rtc_time rt; - unsigned long alarm_time; - struct rtc_device *rtc; - ktime_t alarm_ktime; - - rtc = alarmtimer_get_rtcdev(); - - if (!rtc) - return; - - rtc_read_alarm(rtc, &rtc_alarm); - rt = rtc_alarm.time; - - rtc_tm_to_time(&rt, &alarm_time); - - if (alarm_time) { - alarm_ktime = ktime_set(alarm_time, 0); - alarm_init(&init_alarm, ALARM_POWEROFF_REALTIME, NULL); - alarm_start(&init_alarm, alarm_ktime); - } -} - -/** - * set_power_on_alarm - set power on alarm value into rtc register - * - * Get the soonest power off alarm timer and set the alarm value into rtc - * register. - */ -void set_power_on_alarm(void) -{ - int rc; - struct timespec wall_time, alarm_ts; - long alarm_secs = 0l; - long rtc_secs, alarm_time, alarm_delta; - struct rtc_time rtc_time; - struct rtc_wkalrm alarm; - struct rtc_device *rtc; - struct timerqueue_node *next; - unsigned long flags; - struct alarm_base *base = &alarm_bases[ALARM_POWEROFF_REALTIME]; - - rc = mutex_lock_interruptible(&power_on_alarm_lock); - if (rc != 0) - return; - - spin_lock_irqsave(&base->lock, flags); - next = timerqueue_getnext(&base->timerqueue); - spin_unlock_irqrestore(&base->lock, flags); - - if (next) { - alarm_ts = ktime_to_timespec(next->expires); - alarm_secs = alarm_ts.tv_sec; - } - - if (!alarm_secs) - goto disable_alarm; - - getnstimeofday(&wall_time); - - /* - * alarm_secs have to be bigger than "wall_time +1". - * It is to make sure that alarm time will be always - * bigger than wall time. - */ - if (alarm_secs <= wall_time.tv_sec + 1) - goto disable_alarm; - - rtc = alarmtimer_get_rtcdev(); - if (!rtc) - goto exit; - - rtc_read_time(rtc, &rtc_time); - rtc_tm_to_time(&rtc_time, &rtc_secs); - alarm_delta = wall_time.tv_sec - rtc_secs; - alarm_time = alarm_secs - alarm_delta; - - rtc_time_to_tm(alarm_time, &alarm.time); - alarm.enabled = 1; - rc = rtc_set_alarm(rtcdev, &alarm); - if (rc) - goto disable_alarm; - - mutex_unlock(&power_on_alarm_lock); - return; - -disable_alarm: - rtc_alarm_irq_enable(rtcdev, 0); -exit: - mutex_unlock(&power_on_alarm_lock); -} static void alarmtimer_triggered_func(void *p) { @@ -232,8 +127,6 @@ static void alarmtimer_rtc_remove_device(struct device *dev, static inline void alarmtimer_rtc_timer_init(void) { - mutex_init(&power_on_alarm_lock); - rtc_timer_init(&rtctimer, NULL, NULL); } @@ -260,14 +153,8 @@ struct rtc_device *alarmtimer_get_rtcdev(void) static inline int alarmtimer_rtc_interface_setup(void) { return 0; } static inline void alarmtimer_rtc_interface_remove(void) { } static inline void alarmtimer_rtc_timer_init(void) { } -void set_power_on_alarm(void) { } #endif -static void alarm_work_func(struct work_struct *unused) -{ - set_power_on_alarm(); -} - /** * alarmtimer_enqueue - Adds an alarm timer to an alarm_base timerqueue * @base: pointer to the base where the timer is being run @@ -337,10 +224,6 @@ static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer) } spin_unlock_irqrestore(&base->lock, flags); - /* set next power off alarm */ - if (alarm->type == ALARM_POWEROFF_REALTIME) - queue_delayed_work(power_off_alarm_workqueue, &work, 0); - return ret; } @@ -434,8 +317,6 @@ static int alarmtimer_suspend(struct device *dev) int i; int ret; - cancel_delayed_work_sync(&work); - spin_lock_irqsave(&freezer_delta_lock, flags); min = freezer_delta; freezer_delta = ktime_set(0, 0); @@ -492,7 +373,6 @@ static int alarmtimer_resume(struct device *dev) return 0; rtc_timer_cancel(rtc, &rtctimer); - queue_delayed_work(power_off_alarm_workqueue, &work, 0); return 0; } @@ -673,14 +553,12 @@ EXPORT_SYMBOL_GPL(alarm_forward_now); * clock2alarm - helper that converts from clockid to alarmtypes * @clockid: clockid. */ -enum alarmtimer_type clock2alarm(clockid_t clockid) +static enum alarmtimer_type clock2alarm(clockid_t clockid) { if (clockid == CLOCK_REALTIME_ALARM) return ALARM_REALTIME; if (clockid == CLOCK_BOOTTIME_ALARM) return ALARM_BOOTTIME; - if (clockid == CLOCK_POWEROFF_ALARM) - return ALARM_POWEROFF_REALTIME; return -1; } @@ -1077,13 +955,10 @@ static int __init alarmtimer_init(void) posix_timers_register_clock(CLOCK_REALTIME_ALARM, &alarm_clock); posix_timers_register_clock(CLOCK_BOOTTIME_ALARM, &alarm_clock); - posix_timers_register_clock(CLOCK_POWEROFF_ALARM, &alarm_clock); /* Initialize alarm bases */ alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME; alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real; - alarm_bases[ALARM_POWEROFF_REALTIME].base_clockid = CLOCK_REALTIME; - alarm_bases[ALARM_POWEROFF_REALTIME].gettime = &ktime_get_real; alarm_bases[ALARM_BOOTTIME].base_clockid = CLOCK_BOOTTIME; alarm_bases[ALARM_BOOTTIME].gettime = &ktime_get_boottime; for (i = 0; i < ALARM_NUMTYPE; i++) { @@ -1105,24 +980,8 @@ static int __init alarmtimer_init(void) goto out_drv; } ws = wakeup_source_register("alarmtimer"); - if (!ws) { - error = -ENOMEM; - goto out_ws; - } - - INIT_DELAYED_WORK(&work, alarm_work_func); - power_off_alarm_workqueue = - create_singlethread_workqueue("power_off_alarm"); - if (!power_off_alarm_workqueue) { - error = -ENOMEM; - goto out_wq; - } - return 0; -out_wq: - wakeup_source_unregister(ws); -out_ws: - platform_device_unregister(pdev); + out_drv: platform_driver_unregister(&alarmtimer_driver); out_if: |