| /* |
| * Copyright Codito Technologies (www.codito.com) |
| * |
| * board/aa3/aa3.c |
| * |
| * Copyright (C) |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation. |
| * |
| * Authors : Sandeep Patil (sandeep.patil@codito.com) |
| * Pradeep Sawlani (pradeep.sawlani@codito.com) |
| */ |
| |
| #include <asm/arcregs.h> |
| |
| #include <linux/types.h> |
| #include <config.h> |
| #include <asm/global_data.h> /* For global data structre */ |
| #include <asm/sys_ctrl.h> |
| |
| #define TIMER_WRAP 0xffffffff /* Maximum limit for timer */ |
| |
| #if ARC_BOARD_TIMER==0 |
| #define BOARD_REG_TIMER_LIMIT ARC_REG_TIMER0_LIMIT |
| #define BOARD_REG_TIMER_CTRL ARC_REG_TIMER0_CTRL |
| #define BOARD_REG_TIMER_CNT ARC_REG_TIMER0_CNT |
| #else |
| #define BOARD_REG_TIMER_LIMIT ARC_REG_TIMER1_LIMIT |
| #define BOARD_REG_TIMER_CTRL ARC_REG_TIMER1_CTRL |
| #define BOARD_REG_TIMER_CNT ARC_REG_TIMER1_CNT |
| #endif |
| |
| static ulong timestamp; |
| |
| #ifdef CONFIG_ARC_SYS_CTRL_DEV |
| static sys_ctrl_reg_t *sys_ctrl_dev = SYS_CTRL_DEVICE_ADDRESS; |
| #endif |
| |
| /* Function to start timer from 'count' */ |
| void set_timer (ulong count) |
| { |
| /* Set up the LIMIT , COUNT and CONTROL registers for timer without interrupt */ |
| write_new_aux_reg(BOARD_REG_TIMER_CTRL, 0); |
| write_new_aux_reg(BOARD_REG_TIMER_LIMIT, TIMER_WRAP); |
| write_new_aux_reg(BOARD_REG_TIMER_CTRL, 2); |
| write_new_aux_reg(BOARD_REG_TIMER_CNT, count); |
| } |
| |
| /* Function to get the current count value */ |
| ulong get_timer (ulong base) |
| { |
| /* Read the count value from COUNT0 */ |
| timestamp = read_new_aux_reg(BOARD_REG_TIMER_CNT); |
| return timestamp - base; |
| } |
| |
| void reset_timer(void) |
| { |
| set_timer(0); |
| } |
| |
| void uninit_timer(void) |
| { |
| write_new_aux_reg(BOARD_REG_TIMER_LIMIT, TIMER_WRAP); |
| write_new_aux_reg(BOARD_REG_TIMER_CNT, 0); |
| write_new_aux_reg(BOARD_REG_TIMER_CTRL, 0); |
| } |
| |
| /* Delay function */ |
| void udelay (unsigned long usec) |
| { |
| DECLARE_GLOBAL_DATA_PTR; |
| ulong uTicks; |
| set_timer(0); |
| uTicks = (gd->cpu_clk/1000000) * usec; |
| /* Continue looping till the timer count is more thean the required delay */ |
| while(get_timer(0) < uTicks); |
| } |
| |
| int board_init(void) |
| { |
| DECLARE_GLOBAL_DATA_PTR; |
| |
| gd->cpu_clk = CONFIG_ARC_CLK; |
| /* Intialise the timer */ |
| reset_timer(); |
| |
| /* address of kernel parameters */ |
| gd->bd->bi_boot_params = TEXT_BASE - CONFIG_SYS_MALLOC_LEN + CONFIG_SYS_ENV_SIZE; |
| |
| return 0; |
| } |