1*f27bb139SMarc Zyngier /* 2*f27bb139SMarc Zyngier * Delay loops based on the OpenRISC implementation. 3*f27bb139SMarc Zyngier * 4*f27bb139SMarc Zyngier * Copyright (C) 2012 ARM Limited 5*f27bb139SMarc Zyngier * 6*f27bb139SMarc Zyngier * This program is free software; you can redistribute it and/or modify 7*f27bb139SMarc Zyngier * it under the terms of the GNU General Public License version 2 as 8*f27bb139SMarc Zyngier * published by the Free Software Foundation. 9*f27bb139SMarc Zyngier * 10*f27bb139SMarc Zyngier * This program is distributed in the hope that it will be useful, 11*f27bb139SMarc Zyngier * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*f27bb139SMarc Zyngier * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*f27bb139SMarc Zyngier * GNU General Public License for more details. 14*f27bb139SMarc Zyngier * 15*f27bb139SMarc Zyngier * You should have received a copy of the GNU General Public License 16*f27bb139SMarc Zyngier * along with this program. If not, see <http://www.gnu.org/licenses/>. 17*f27bb139SMarc Zyngier * 18*f27bb139SMarc Zyngier * Author: Will Deacon <will.deacon@arm.com> 19*f27bb139SMarc Zyngier */ 20*f27bb139SMarc Zyngier 21*f27bb139SMarc Zyngier #include <linux/delay.h> 22*f27bb139SMarc Zyngier #include <linux/init.h> 23*f27bb139SMarc Zyngier #include <linux/kernel.h> 24*f27bb139SMarc Zyngier #include <linux/module.h> 25*f27bb139SMarc Zyngier #include <linux/timex.h> 26*f27bb139SMarc Zyngier 27*f27bb139SMarc Zyngier void __delay(unsigned long cycles) 28*f27bb139SMarc Zyngier { 29*f27bb139SMarc Zyngier cycles_t start = get_cycles(); 30*f27bb139SMarc Zyngier 31*f27bb139SMarc Zyngier while ((get_cycles() - start) < cycles) 32*f27bb139SMarc Zyngier cpu_relax(); 33*f27bb139SMarc Zyngier } 34*f27bb139SMarc Zyngier EXPORT_SYMBOL(__delay); 35*f27bb139SMarc Zyngier 36*f27bb139SMarc Zyngier inline void __const_udelay(unsigned long xloops) 37*f27bb139SMarc Zyngier { 38*f27bb139SMarc Zyngier unsigned long loops; 39*f27bb139SMarc Zyngier 40*f27bb139SMarc Zyngier loops = xloops * loops_per_jiffy * HZ; 41*f27bb139SMarc Zyngier __delay(loops >> 32); 42*f27bb139SMarc Zyngier } 43*f27bb139SMarc Zyngier EXPORT_SYMBOL(__const_udelay); 44*f27bb139SMarc Zyngier 45*f27bb139SMarc Zyngier void __udelay(unsigned long usecs) 46*f27bb139SMarc Zyngier { 47*f27bb139SMarc Zyngier __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */ 48*f27bb139SMarc Zyngier } 49*f27bb139SMarc Zyngier EXPORT_SYMBOL(__udelay); 50*f27bb139SMarc Zyngier 51*f27bb139SMarc Zyngier void __ndelay(unsigned long nsecs) 52*f27bb139SMarc Zyngier { 53*f27bb139SMarc Zyngier __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */ 54*f27bb139SMarc Zyngier } 55*f27bb139SMarc Zyngier EXPORT_SYMBOL(__ndelay); 56