2 * carl9170 firmware - used by the ar9170 wireless device
4 * Clock, Timer & Timing
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-2011 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.
26 #ifndef __CARL9170FW_TIMER_H
27 #define __CARL9170FW_TIMER_H
38 static inline __inline uint32_t get_clock_counter(void)
40 return (get(AR9170_TIMER_REG_CLOCK_HIGH) << 16) | get(AR9170_TIMER_REG_CLOCK_LOW);
44 * works only up to 97 secs [44 MHz] or 107 secs for 40 MHz
45 * Also, the delay wait will be affected by 2.4GHz<->5GHz
48 static inline __inline bool is_after_msecs(const uint32_t t0, const uint32_t msecs)
50 return ((get_clock_counter() - t0) / 1000) > (msecs * fw.ticks_per_msec);
54 * Note: Be careful with [u]delay. They won't service the
55 * hardware watchdog timer. It might trigger if you
56 * wait long enough. Also they don't terminate if sec is
57 * above 97 sec [44MHz] or more than 107 sec [40MHz].
59 static inline __inline void delay(const uint32_t msec)
61 uint32_t t1, t2, dt, wt;
63 wt = msec * fw.ticks_per_msec;
65 t1 = get_clock_counter();
67 t2 = get_clock_counter();
68 dt = (t2 - t1) / 1000;
74 static inline __inline void udelay(const uint32_t usec)
78 t1 = get_clock_counter();
80 t2 = get_clock_counter();
82 if (dt >= (usec * fw.ticks_per_msec))
87 static inline void clock_set(enum cpu_clock_t _clock, bool on)
91 * This setting does more than just mess with the CPU Clock.
92 * So watch out, if you need _stable_ timer interrupts.
95 fw.ticks_per_msec = GET_VAL(AR9170_PWR_PLL_ADDAC_DIV, get(AR9170_PWR_REG_PLL_ADDAC)) >> 1;
97 set(AR9170_PWR_REG_CLOCK_SEL, (uint32_t) ((on ? 0x70 : 0x600) | _clock));
100 #endif /* __CARL9170FW_TIMER_H */