2 * carl9170 firmware - used by the ar9170 wireless device
4 * Clock, Timer & Timing functions
6 * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7 * Copyright (c) 2007-2009 Atheros Communications, Inc.
8 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
9 * Copyright 2009, 2010 Christian Lamparter <chunkeey@googlemail.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 void timer_init(const unsigned int timer, const unsigned int interval)
34 /* Set timer to periodic mode */
35 orl(AR9170_TIMER_REG_CONTROL, BIT(timer));
37 /* Set time interval */
38 set(AR9170_TIMER_REG_TIMER0 + (timer << 2), interval - 1);
40 /* Clear timer interrupt flag */
41 orl(AR9170_TIMER_REG_INTERRUPT, BIT(timer));
44 void clock_set(const bool on, const enum cpu_clock_t _clock)
48 * This setting does more than just mess with the CPU Clock.
49 * So watch out, if you need _stable_ timer interrupts.
52 set(AR9170_PWR_REG_CLOCK_SEL, (uint32_t) ((on ? 0x70 : 0x600) | _clock));
55 static void timer0_isr(void)
59 #ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT
61 #endif /* CONFIG_CARL9170FW_GPIO_INTERRUPT */
63 #ifdef CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT
64 set(AR9170_GPIO_REG_PORT_DATA, get(AR9170_GPIO_REG_PORT_DATA) ^ 1);
65 #endif /* CONFIG_CARL9170FW_DEBUG_LED_HEARTBEAT */
68 void handle_timer(void)
72 intr = get(AR9170_TIMER_REG_INTERRUPT);
74 /* ACK timer interrupt */
75 set(AR9170_TIMER_REG_INTERRUPT, intr);
77 #define HANDLER(intr, flag, func) \
79 if ((intr & flag) != 0) { \
85 HANDLER(intr, BIT(0), timer0_isr);
88 DBG("Unhandled Timer Event %x", (unsigned int) intr);