Commit 58f60c22 authored by Max Filippov's avatar Max Filippov

xtensa: clean up udelay

Replace division with shift, use ccount_freq instead of loops_per_jiffy.
Introduce __MAX_UDELAY and (undefined) __bad_udelay, break build for too
big udelay constants.
Remove irrelevant comment, clean up code style.
Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
parent a6f3eefa
...@@ -27,18 +27,27 @@ static inline void __delay(unsigned long loops) ...@@ -27,18 +27,27 @@ static inline void __delay(unsigned long loops)
: "+r" (loops)); : "+r" (loops));
} }
/* For SMP/NUMA systems, change boot_cpu_data to something like /* Undefined function to get compile-time error */
* local_cpu_data->... where local_cpu_data points to the current void __bad_udelay(void);
* cpu. */
static __inline__ void udelay (unsigned long usecs) #define __MAX_UDELAY 30000
static inline void __udelay(unsigned long usecs)
{ {
unsigned long start = get_ccount(); unsigned long start = get_ccount();
unsigned long cycles = usecs * (loops_per_jiffy / (1000000UL / HZ)); unsigned long cycles = (usecs * (ccount_freq >> 15)) >> 5;
/* Note: all variables are unsigned (can wrap around)! */ /* Note: all variables are unsigned (can wrap around)! */
while (((unsigned long)get_ccount()) - start < cycles) while (((unsigned long)get_ccount()) - start < cycles)
; cpu_relax();
}
static inline void udelay(unsigned long usec)
{
if (__builtin_constant_p(usec) && usec >= __MAX_UDELAY)
__bad_udelay();
else
__udelay(usec);
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment