linux/arch/s390/lib/delay.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/*
   3 *    Precise Delay Loops for S390
   4 *
   5 *    Copyright IBM Corp. 1999, 2008
   6 *    Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
   7 *               Heiko Carstens <heiko.carstens@de.ibm.com>,
   8 */
   9
  10#include <linux/processor.h>
  11#include <linux/delay.h>
  12#include <asm/div64.h>
  13#include <asm/timex.h>
  14
  15void __delay(unsigned long loops)
  16{
  17        /*
  18         * To end the bloody studid and useless discussion about the
  19         * BogoMips number I took the liberty to define the __delay
  20         * function in a way that that resulting BogoMips number will
  21         * yield the megahertz number of the cpu. The important function
  22         * is udelay and that is done using the tod clock. -- martin.
  23         */
  24        asm volatile("0: brct %0,0b" : : "d" ((loops/2) + 1));
  25}
  26EXPORT_SYMBOL(__delay);
  27
  28static void delay_loop(unsigned long delta)
  29{
  30        unsigned long end;
  31
  32        end = get_tod_clock_monotonic() + delta;
  33        while (!tod_after(get_tod_clock_monotonic(), end))
  34                cpu_relax();
  35}
  36
  37void __udelay(unsigned long usecs)
  38{
  39        delay_loop(usecs << 12);
  40}
  41EXPORT_SYMBOL(__udelay);
  42
  43void __ndelay(unsigned long nsecs)
  44{
  45        nsecs <<= 9;
  46        do_div(nsecs, 125);
  47        delay_loop(nsecs);
  48}
  49EXPORT_SYMBOL(__ndelay);
  50