wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000, 2001 |
| 3 | * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com. |
| 4 | * base on code by |
| 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <ppc_asm.tmpl> |
| 11 | #include <ppc_defs.h> |
| 12 | #include <config.h> |
| 13 | #include <watchdog.h> |
| 14 | |
| 15 | /* |
| 16 | * unsigned long long get_ticks(void); |
| 17 | * |
| 18 | * read timebase as "long long" |
| 19 | */ |
| 20 | .globl get_ticks |
| 21 | get_ticks: |
| 22 | 1: mftbu r3 |
| 23 | mftb r4 |
| 24 | mftbu r5 |
| 25 | cmp 0,r3,r5 |
| 26 | bne 1b |
| 27 | blr |
| 28 | |
| 29 | /* |
| 30 | * Delay for a number of ticks |
| 31 | */ |
| 32 | .globl wait_ticks |
| 33 | wait_ticks: |
Joakim Tjernlund | 194c3bf | 2012-07-16 21:25:40 +0000 | [diff] [blame] | 34 | stwu r1, -16(r1) |
| 35 | mflr r0 /* save link register */ |
| 36 | stw r0, 20(r1) /* Use r0 or GDB will be unhappy */ |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 37 | stw r14, 12(r1) /* save used registers */ |
| 38 | stw r15, 8(r1) |
| 39 | mr r14, r3 /* save tick count */ |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 40 | bl get_ticks /* Get start time */ |
| 41 | |
| 42 | /* Calculate end time */ |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 43 | addc r14, r4, r14 /* Compute end time lower */ |
| 44 | addze r15, r3 /* and end time upper */ |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 45 | |
| 46 | WATCHDOG_RESET /* Trigger watchdog, if needed */ |
| 47 | 1: bl get_ticks /* Get current time */ |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 48 | subfc r4, r4, r14 /* Subtract current time from end time */ |
| 49 | subfe. r3, r3, r15 |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 50 | bge 1b /* Loop until time expired */ |
| 51 | |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 52 | lwz r15, 8(r1) /* restore saved registers */ |
| 53 | lwz r14, 12(r1) |
| 54 | lwz r0, 20(r1) |
Joakim Tjernlund | 194c3bf | 2012-07-16 21:25:40 +0000 | [diff] [blame] | 55 | addi r1,r1,16 |
Mats Kärrman | d1cdc1b | 2013-04-09 17:10:59 +0200 | [diff] [blame] | 56 | mtlr r0 |
wdenk | 12e4407 | 2001-11-26 22:06:16 +0000 | [diff] [blame] | 57 | blr |