From: Viktor Barna <viktor.barna@xxxxxxxxxx> (Part of the split. Please, take a look at the cover letter for more details). Signed-off-by: Viktor Barna <viktor.barna@xxxxxxxxxx> --- .../net/wireless/celeno/cl8k/utils/timer.c | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/utils/timer.c diff --git a/drivers/net/wireless/celeno/cl8k/utils/timer.c b/drivers/net/wireless/celeno/cl8k/utils/timer.c new file mode 100644 index 000000000000..8ab8b44ef085 --- /dev/null +++ b/drivers/net/wireless/celeno/cl8k/utils/timer.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: MIT +/* Copyright(c) 2019-2021, Celeno Communications Ltd. */ + +#include "utils/timer.h" + +static void cl_timer_func(struct timer_list *t) +{ + struct cl_timer *timer = from_timer(timer, t, obj); + + timer->f(timer->data); + if (timer->enable && timer->periodic) + cl_timer_enable(timer); +} + +void cl_timer_init(struct cl_timer *timer, + void (*f)(unsigned long), + unsigned long data, + unsigned long period, + bool periodic) +{ + timer_setup(&timer->obj, cl_timer_func, 0); + cl_timer_period_set(timer, period); + timer->data = data; + timer->f = f; + timer->periodic = periodic; + timer->enable = false; +} + +void cl_timer_period_set(struct cl_timer *timer, unsigned long period) +{ + atomic_set(&timer->period, msecs_to_jiffies(period)); +} + +void cl_timer_enable(struct cl_timer *timer) +{ + if (timer_pending(&timer->obj)) + return; + + timer->obj.expires = jiffies + atomic_read(&timer->period); + timer->enable = true; + add_timer(&timer->obj); +} + +void cl_timer_disable(struct cl_timer *timer) +{ + if (timer->enable) { + timer->enable = false; + del_timer(&timer->obj); + } +} + +void cl_timer_disable_sync(struct cl_timer *timer) +{ + if (timer->enable) { + timer->enable = false; + del_timer_sync(&timer->obj); + } +} + +void cl_timer_rearm(struct cl_timer *timer) +{ + timer->enable = true; + + mod_timer(&timer->obj, jiffies + atomic_read(&timer->period)); +} + +int cl_timer_rearm_offset(struct cl_timer *timer, unsigned long time_offset) +{ + timer->enable = true; + + return mod_timer(&timer->obj, time_offset + atomic_read(&timer->period)); +} -- 2.30.0 ________________________________ The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any retransmission, dissemination, copying or other use of, or taking of any action in reliance upon this information is prohibited. If you received this in error, please contact the sender and delete the material from any computer. Nothing contained herein shall be deemed as a representation, warranty or a commitment by Celeno. No warranties are expressed or implied, including, but not limited to, any implied warranties of non-infringement, merchantability and fitness for a particular purpose. ________________________________