2008-10-12 16:46:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-11-26 16:46:12 +00:00
|
|
|
* Copyright (C) 2008 Rafaël Carré
|
2008-10-12 16:46:01 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef SYSTEM_TARGET_H
|
|
|
|
#define SYSTEM_TARGET_H
|
|
|
|
|
|
|
|
#include "system-arm.h"
|
2009-07-05 01:17:25 +00:00
|
|
|
#include "mmu-arm.h"
|
2010-04-27 09:34:29 +00:00
|
|
|
#include "panic.h"
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2008-12-04 20:04:31 +00:00
|
|
|
#include "clock-target.h" /* CPUFREQ_* are defined here */
|
2008-10-12 16:46:01 +00:00
|
|
|
|
2010-04-27 10:11:52 +00:00
|
|
|
/* We can use a interrupt-based mechanism on the fuzev2 */
|
|
|
|
#define INCREASED_SCROLLWHEEL_POLLING \
|
|
|
|
(defined(HAVE_SCROLLWHEEL) && (CONFIG_CPU == AS3525))
|
|
|
|
|
|
|
|
#if INCREASED_SCROLLWHEEL_POLLING
|
2010-04-27 09:34:29 +00:00
|
|
|
/* let the timer interrupt twice as often for the scrollwheel polling */
|
|
|
|
#define KERNEL_TIMER_FREQ (TIMER_FREQ/2)
|
|
|
|
#else
|
|
|
|
#define KERNEL_TIMER_FREQ TIMER_FREQ
|
|
|
|
#endif
|
|
|
|
|
2009-06-08 23:05:33 +00:00
|
|
|
#ifdef BOOTLOADER
|
2010-05-19 18:13:06 +00:00
|
|
|
#define AS3525_UNCACHED_ADDR(a) (a)
|
2009-06-08 23:05:33 +00:00
|
|
|
#else
|
2010-05-19 18:13:06 +00:00
|
|
|
#define AS3525_UNCACHED_ADDR(a) ((typeof(a)) ((uintptr_t)(a) + 0x10000000))
|
2009-06-08 23:05:33 +00:00
|
|
|
#endif
|
|
|
|
|
2010-04-06 18:32:47 +00:00
|
|
|
#ifdef SANSA_C200V2
|
|
|
|
/* 0: Backlight on A5, 1: Backlight on A7 */
|
|
|
|
extern int c200v2_variant;
|
2010-04-27 09:34:29 +00:00
|
|
|
/* c200v2 changes the timer interval often due to software pwm */
|
|
|
|
#define TIMER_PERIOD TIMER2_BGLOAD
|
|
|
|
#else
|
|
|
|
#define TIMER_PERIOD (KERNEL_TIMER_FREQ/HZ)
|
2010-04-06 18:32:47 +00:00
|
|
|
#endif
|
|
|
|
|
2010-04-27 09:34:29 +00:00
|
|
|
/*
|
|
|
|
* This function is not overly accurate, so rather call it with an usec more
|
|
|
|
* than less (see below comment)
|
|
|
|
*
|
|
|
|
* if inlined it expands to a really small and fast function if it's called
|
|
|
|
* with compile time constants */
|
|
|
|
static inline void udelay(unsigned usecs) __attribute__((always_inline));
|
|
|
|
static inline void udelay(unsigned usecs)
|
|
|
|
{
|
2010-04-27 18:18:30 +00:00
|
|
|
unsigned now;
|
|
|
|
int end;
|
2010-04-27 09:34:29 +00:00
|
|
|
|
|
|
|
/**
|
2010-05-02 02:30:06 +00:00
|
|
|
* we're limited to 0.666us multiplies due to the odd timer frequency (1.5MHz),
|
2010-04-27 09:34:29 +00:00
|
|
|
* to avoid calculating which is safer (need to round up for small values)
|
|
|
|
* and saves spending time in the divider we have a lut for
|
2010-05-02 02:30:06 +00:00
|
|
|
* small us values, it should be roughly us*3/2
|
2010-04-27 09:34:29 +00:00
|
|
|
**/
|
|
|
|
static const unsigned char udelay_lut[] =
|
|
|
|
{
|
2010-05-02 02:30:06 +00:00
|
|
|
0, 2, 3, 5, 6, 8, 9, 11, 12, 14,
|
|
|
|
15, 17, 18, 20, 21, 23, 24, 26, 27, 29,
|
2010-04-27 09:34:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
now = TIMER2_VALUE;
|
|
|
|
/* we don't want to handle multiple overflows, so limit the numbers
|
|
|
|
* (if you want to wait more than a tick just poll current_tick, or
|
|
|
|
* call sleep()) */
|
2010-05-02 02:30:06 +00:00
|
|
|
if (UNLIKELY(usecs >= (TIMER_PERIOD*2/3)))
|
2010-04-27 09:34:29 +00:00
|
|
|
panicf("%s(): %d too high!", __func__, usecs);
|
|
|
|
if (UNLIKELY(usecs <= 0))
|
|
|
|
return;
|
|
|
|
if (usecs < ARRAYLEN(udelay_lut))
|
|
|
|
{ /* the timer decrements */
|
|
|
|
end = now - udelay_lut[usecs];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* to usecs */
|
2010-05-02 02:30:06 +00:00
|
|
|
int delay = usecs * 3 / 2; /* us * 0.666 = us*timer_period */
|
2010-04-27 09:34:29 +00:00
|
|
|
end = now - delay;
|
|
|
|
}
|
2010-04-27 18:18:30 +00:00
|
|
|
|
|
|
|
unsigned old;
|
|
|
|
|
2010-04-27 09:34:29 +00:00
|
|
|
/* underrun ? */
|
|
|
|
if (end < 0)
|
2010-04-27 18:18:30 +00:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
old = now;
|
|
|
|
now = TIMER2_VALUE;
|
|
|
|
} while(now <= old); /* if the new value is higher then we wrapped */
|
|
|
|
|
2010-04-27 09:34:29 +00:00
|
|
|
end += TIMER_PERIOD;
|
2010-04-27 18:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* if timer wraps then we missed our end value */
|
|
|
|
old = now;
|
|
|
|
now = TIMER2_VALUE;
|
|
|
|
} while(now > (unsigned)end && now <= old);
|
2010-04-27 09:34:29 +00:00
|
|
|
}
|
2008-10-12 16:46:01 +00:00
|
|
|
#endif /* SYSTEM_TARGET_H */
|