David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* MN10300 Short delay interpolation routines |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
| 10 | */ |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <asm/div64.h> |
| 15 | |
| 16 | /* |
| 17 | * basic delay loop |
| 18 | */ |
| 19 | void __delay(unsigned long loops) |
| 20 | { |
| 21 | int d0; |
| 22 | |
| 23 | asm volatile( |
| 24 | " bra 1f \n" |
| 25 | " .align 4 \n" |
| 26 | "1: bra 2f \n" |
| 27 | " .align 4 \n" |
| 28 | "2: add -1,%0 \n" |
| 29 | " bne 2b \n" |
| 30 | : "=&d" (d0) |
Mark Salter | d6bb7a1 | 2010-01-08 14:43:16 -0800 | [diff] [blame] | 31 | : "0" (loops) |
| 32 | : "cc"); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 33 | } |
| 34 | EXPORT_SYMBOL(__delay); |
| 35 | |
| 36 | /* |
| 37 | * handle a delay specified in terms of microseconds |
| 38 | */ |
| 39 | void __udelay(unsigned long usecs) |
| 40 | { |
Akira Takeuchi | 368dd5a | 2010-10-27 17:28:55 +0100 | [diff] [blame] | 41 | unsigned long start, stop, cnt; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 42 | |
| 43 | /* usecs * CLK / 1E6 */ |
| 44 | stop = __muldiv64u(usecs, MN10300_TSCCLK, 1000000); |
Akira Takeuchi | 368dd5a | 2010-10-27 17:28:55 +0100 | [diff] [blame] | 45 | start = TMTSCBC; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 46 | |
| 47 | do { |
Akira Takeuchi | 368dd5a | 2010-10-27 17:28:55 +0100 | [diff] [blame] | 48 | cnt = start - TMTSCBC; |
| 49 | } while (cnt < stop); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 50 | } |
| 51 | EXPORT_SYMBOL(__udelay); |