2012-03-24 18:27:38 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* arch/arm/src/calypso/calypso_irq.c
|
|
|
|
* Driver for Calypso IRQ controller
|
|
|
|
*
|
|
|
|
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* (C) 2011 by Stefan Richter <ichgeh@l--putt.de>
|
|
|
|
*
|
|
|
|
* This source code is derivated from Osmocom-BB project and was
|
|
|
|
* relicensed as BSD with permission from original authors.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/arch.h>
|
2013-05-05 17:10:47 +02:00
|
|
|
|
2012-03-24 18:27:38 +01:00
|
|
|
#include <arch/calypso/memory.h>
|
2013-05-05 17:10:47 +02:00
|
|
|
#include <arch/calypso/clock.h>
|
2012-03-24 18:27:38 +01:00
|
|
|
|
|
|
|
#include "arm.h"
|
2012-05-02 01:03:37 +02:00
|
|
|
#include "up_arch.h"
|
2012-03-24 18:27:38 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
#define BASE_ADDR_IRQ 0xfffffa00
|
|
|
|
#define BASE_ADDR_IBOOT_EXC 0x0080001C
|
|
|
|
|
|
|
|
enum irq_reg
|
|
|
|
{
|
|
|
|
IT_REG1 = 0x00,
|
|
|
|
IT_REG2 = 0x02,
|
|
|
|
MASK_IT_REG1 = 0x08,
|
|
|
|
MASK_IT_REG2 = 0x0a,
|
|
|
|
IRQ_NUM = 0x10,
|
|
|
|
FIQ_NUM = 0x12,
|
|
|
|
IRQ_CTRL = 0x14,
|
2012-03-24 18:27:38 +01:00
|
|
|
};
|
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
#define ILR_IRQ(x) (0x20 + (x*2))
|
|
|
|
#define IRQ_REG(x) (BASE_ADDR_IRQ + (x))
|
2012-03-24 18:27:38 +01:00
|
|
|
|
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
volatile uint32_t *current_regs;
|
|
|
|
extern uint32_t _exceptions;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
static uint8_t default_irq_prio[] =
|
|
|
|
{
|
|
|
|
[IRQ_WATCHDOG] = 0xff,
|
|
|
|
[IRQ_TIMER1] = 0xff,
|
|
|
|
[IRQ_TIMER2] = 0xff,
|
|
|
|
[IRQ_TSP_RX] = 0,
|
|
|
|
[IRQ_TPU_FRAME] = 3,
|
|
|
|
[IRQ_TPU_PAGE] = 0xff,
|
|
|
|
[IRQ_SIMCARD] = 0xff,
|
|
|
|
[IRQ_UART_MODEM] = 8,
|
|
|
|
[IRQ_KEYPAD_GPIO] = 4,
|
|
|
|
[IRQ_RTC_TIMER] = 9,
|
|
|
|
[IRQ_RTC_ALARM_I2C] = 10,
|
|
|
|
[IRQ_ULPD_GAUGING] = 2,
|
|
|
|
[IRQ_EXTERNAL] = 12,
|
|
|
|
[IRQ_SPI] = 0xff,
|
|
|
|
[IRQ_DMA] = 0xff,
|
|
|
|
[IRQ_API] = 0xff,
|
|
|
|
[IRQ_SIM_DETECT] = 0,
|
|
|
|
[IRQ_EXTERNAL_FIQ] = 7,
|
|
|
|
[IRQ_UART_IRDA] = 2,
|
|
|
|
[IRQ_ULPD_GSM_TIMER] = 1,
|
|
|
|
[IRQ_GEA] = 0xff,
|
2012-03-24 18:27:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void _irq_enable(enum irq_nr nr, int enable)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
uintptr_t reg = IRQ_REG(MASK_IT_REG1);
|
|
|
|
uint16_t val;
|
|
|
|
|
|
|
|
if (nr > 15)
|
|
|
|
{
|
|
|
|
reg = IRQ_REG(MASK_IT_REG2);
|
|
|
|
nr -= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = getreg16(reg);
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
val &= ~(1 << nr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val |= (1 << nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
putreg16(val, reg);
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_default_priorities(void)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(default_irq_prio); i++)
|
|
|
|
{
|
|
|
|
uint16_t val;
|
|
|
|
uint8_t prio = default_irq_prio[i];
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
if (prio > 31)
|
|
|
|
{
|
|
|
|
prio = 31;
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
val = getreg16(IRQ_REG(ILR_IRQ(i)));
|
|
|
|
val &= ~(0x1f << 2);
|
|
|
|
val |= prio << 2;
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Make edge mode default. Hopefully causes less trouble */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
val |= 0x02;
|
|
|
|
|
|
|
|
putreg16(val, IRQ_REG(ILR_IRQ(i)));
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Install the exception handlers to where the ROM loader jumps */
|
2013-05-05 17:10:47 +02:00
|
|
|
|
2012-03-24 18:27:38 +01:00
|
|
|
static void calypso_exceptions_install(void)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
uint32_t *exceptions_dst = (uint32_t *) BASE_ADDR_IBOOT_EXC;
|
|
|
|
uint32_t *exceptions_src = &_exceptions;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
*exceptions_dst++ = *exceptions_src++;
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_irqinitialize
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Setup the IRQ and FIQ controllers
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_irqinitialize(void)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Prepare hardware */
|
|
|
|
|
|
|
|
calypso_exceptions_install();
|
|
|
|
current_regs = NULL;
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Switch to internal ROM */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
calypso_bootrom(1);
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Set default priorities */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
set_default_priorities();
|
|
|
|
|
|
|
|
/* Mask all interrupts off */
|
|
|
|
|
|
|
|
putreg16(0xffff, IRQ_REG(MASK_IT_REG1));
|
|
|
|
putreg16(0xffff, IRQ_REG(MASK_IT_REG2));
|
|
|
|
|
|
|
|
/* clear all pending interrupts */
|
|
|
|
putreg16(0, IRQ_REG(IT_REG1));
|
|
|
|
putreg16(0, IRQ_REG(IT_REG2));
|
|
|
|
|
|
|
|
/* Enable interrupts globally to the ARM core */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_SUPPRESS_INTERRUPTS
|
2013-05-05 17:10:47 +02:00
|
|
|
irqrestore(SVC_MODE | PSR_F_BIT);
|
2012-03-24 18:27:38 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_disable_irq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disable the IRQ specified by 'irq'
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_disable_irq(int irq)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
if ((unsigned)irq < NR_IRQS)
|
|
|
|
{
|
|
|
|
_irq_enable(irq, 0);
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_enable_irq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Enable the IRQ specified by 'irq'
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_enable_irq(int irq)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
if((unsigned)irq < NR_IRQS)
|
|
|
|
{
|
|
|
|
_irq_enable(irq, 1);
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_prioritize_irq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the priority of an IRQ.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_ARCH_IRQPRIO
|
|
|
|
int up_prioritize_irq(int nr, int prio)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
uint16_t val;
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
if (prio == -1)
|
|
|
|
{
|
|
|
|
prio = default_irq_prio[nr];
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
if (prio > 31)
|
|
|
|
{
|
|
|
|
prio = 31;
|
|
|
|
}
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
val = prio << 2;
|
|
|
|
putreg16(val, IRQ_REG(ILR_IRQ(nr)));
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
return 0;
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Entry point for interrupts
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void up_decodeirq(uint32_t *regs)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
uint8_t num, tmp;
|
|
|
|
uint32_t *saved_regs;
|
|
|
|
|
|
|
|
/* XXX: What is this???
|
|
|
|
* Passed to but ignored in IRQ handlers
|
|
|
|
* Only valid meaning is apparently non-NULL == IRQ context */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
saved_regs = (uint32_t *)current_regs;
|
|
|
|
current_regs = regs;
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Detect & deliver the IRQ */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
num = getreg8(IRQ_REG(IRQ_NUM)) & 0x1f;
|
|
|
|
irq_dispatch(num, regs);
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Start new IRQ agreement */
|
|
|
|
|
|
|
|
tmp = getreg8(IRQ_REG(IRQ_CTRL));
|
|
|
|
tmp |= 0x01;
|
|
|
|
putreg8(tmp, IRQ_REG(IRQ_CTRL));
|
|
|
|
|
|
|
|
current_regs = saved_regs;
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Entry point for FIQs
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void calypso_fiq(void)
|
|
|
|
{
|
2013-05-05 17:10:47 +02:00
|
|
|
uint8_t num, tmp;
|
|
|
|
uint32_t *regs;
|
|
|
|
|
|
|
|
/* XXX: What is this???
|
|
|
|
* Passed to but ignored in IRQ handlers
|
|
|
|
* Only valid meaning is apparently non-NULL == IRQ context */
|
|
|
|
|
|
|
|
regs = (uint32_t *)current_regs;
|
|
|
|
current_regs = (uint32_t *)#
|
|
|
|
|
|
|
|
/* Detect & deliver like an IRQ but we are in FIQ context */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
num = getreg8(IRQ_REG(FIQ_NUM)) & 0x1f;
|
|
|
|
irq_dispatch(num, regs);
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
/* Start new FIQ agreement */
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
tmp = getreg8(IRQ_REG(IRQ_CTRL));
|
|
|
|
tmp |= 0x02;
|
|
|
|
putreg8(tmp, IRQ_REG(IRQ_CTRL));
|
2012-03-24 18:27:38 +01:00
|
|
|
|
2013-05-05 17:10:47 +02:00
|
|
|
current_regs = regs;
|
2012-03-24 18:27:38 +01:00
|
|
|
}
|