developer | e0cea0f | 2021-12-16 16:08:26 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | #include <linux/delay.h> |
| 4 | #include <linux/ktime.h> |
| 5 | #include <linux/timekeeping.h> |
| 6 | |
| 7 | #include "proslic_sys.h" |
| 8 | |
| 9 | /*****************************************************************************************************/ |
| 10 | static int proslic_sys_delay(void *hTimer, int timeInMsec) |
| 11 | { |
| 12 | if(likely(timeInMsec < SILABS_MIN_MSLEEP_TIME)) |
| 13 | { |
| 14 | mdelay(timeInMsec); |
| 15 | } |
| 16 | else |
| 17 | { |
| 18 | msleep((timeInMsec-SILABS_MSLEEP_SLOP)); |
| 19 | } |
| 20 | return PROSLIC_SPI_OK; |
| 21 | } |
| 22 | |
| 23 | /*****************************************************************************************************/ |
| 24 | /* Code assumes time value has been allocated */ |
| 25 | static int proslic_sys_getTime(void *hTimer, void *time) |
| 26 | { |
| 27 | if(time != NULL) |
| 28 | { |
| 29 | ktime_get_coarse_real_ts64(&((proslic_timeStamp *)time)->timerObj); |
| 30 | return PROSLIC_SPI_OK; |
| 31 | } |
| 32 | else |
| 33 | { |
| 34 | return PROSLIC_TIMER_ERROR; |
| 35 | } |
| 36 | } |
| 37 | /*****************************************************************************************************/ |
| 38 | |
| 39 | static int proslic_sys_timeElapsed(void *hTimer, void *startTime, int *timeInMsec) |
| 40 | { |
| 41 | if( (startTime != NULL) && (timeInMsec != NULL) ) |
| 42 | { |
| 43 | struct timespec64 now; |
| 44 | struct timespec64 ts_delta; |
| 45 | ktime_get_coarse_real_ts64(&now); |
| 46 | ts_delta = timespec64_sub(now, (((proslic_timeStamp *) startTime)->timerObj)); |
| 47 | *timeInMsec = (int)( (ts_delta.tv_sec *1000) + (ts_delta.tv_nsec / NSEC_PER_MSEC) ); |
| 48 | return PROSLIC_SPI_OK; |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | return PROSLIC_TIMER_ERROR; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | |
| 57 | proslic_timer_fptrs_t proslic_timer_if = |
| 58 | { |
| 59 | proslic_sys_delay, |
| 60 | proslic_sys_timeElapsed, |
| 61 | proslic_sys_getTime |
| 62 | }; |