Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Texas Instruments <www.ti.com> |
| 4 | * |
| 5 | * (C) Copyright 2002 |
| 6 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 7 | * Marius Groeger <mgroeger@sysgo.de> |
| 8 | * |
| 9 | * (C) Copyright 2002 |
| 10 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 11 | * Alex Zuepke <azu@sysgo.de> |
| 12 | * |
| 13 | * (C) Copyright 2002-2004 |
Detlev Zundel | f1b3f2b | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 14 | * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> |
Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 15 | * |
| 16 | * (C) Copyright 2004 |
| 17 | * Philippe Robin, ARM Ltd. <philippe.robin@arm.com> |
| 18 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 19 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <common.h> |
Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 23 | |
Gururaja Hebbar K R | b675aa3 | 2008-08-25 11:11:34 +0200 | [diff] [blame] | 24 | #define TIMER_ENABLE (1 << 7) |
| 25 | #define TIMER_MODE_MSK (1 << 6) |
| 26 | #define TIMER_MODE_FR (0 << 6) |
| 27 | #define TIMER_MODE_PD (1 << 6) |
| 28 | |
| 29 | #define TIMER_INT_EN (1 << 5) |
| 30 | #define TIMER_PRS_MSK (3 << 2) |
| 31 | #define TIMER_PRS_8S (1 << 3) |
| 32 | #define TIMER_SIZE_MSK (1 << 2) |
| 33 | #define TIMER_ONE_SHT (1 << 0) |
| 34 | |
Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 35 | int timer_init (void) |
| 36 | { |
Gururaja Hebbar K R | b675aa3 | 2008-08-25 11:11:34 +0200 | [diff] [blame] | 37 | ulong tmr_ctrl_val; |
| 38 | |
| 39 | /* 1st disable the Timer */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 40 | tmr_ctrl_val = *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8); |
Gururaja Hebbar K R | b675aa3 | 2008-08-25 11:11:34 +0200 | [diff] [blame] | 41 | tmr_ctrl_val &= ~TIMER_ENABLE; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8) = tmr_ctrl_val; |
Gururaja Hebbar K R | b675aa3 | 2008-08-25 11:11:34 +0200 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * The Timer Control Register has one Undefined/Shouldn't Use Bit |
| 46 | * So we should do read/modify/write Operation |
| 47 | */ |
| 48 | |
| 49 | /* |
| 50 | * Timer Mode : Free Running |
| 51 | * Interrupt : Disabled |
| 52 | * Prescale : 8 Stage, Clk/256 |
| 53 | * Tmr Siz : 16 Bit Counter |
| 54 | * Tmr in Wrapping Mode |
| 55 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | tmr_ctrl_val = *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8); |
Gururaja Hebbar K R | b675aa3 | 2008-08-25 11:11:34 +0200 | [diff] [blame] | 57 | tmr_ctrl_val &= ~(TIMER_MODE_MSK | TIMER_INT_EN | TIMER_PRS_MSK | TIMER_SIZE_MSK | TIMER_ONE_SHT ); |
| 58 | tmr_ctrl_val |= (TIMER_ENABLE | TIMER_PRS_8S); |
| 59 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 60 | *(volatile ulong *)(CONFIG_SYS_TIMERBASE + 8) = tmr_ctrl_val; |
Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 61 | |
Wolfgang Denk | d86ec38 | 2006-03-13 12:37:35 +0100 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |