2007-09-21 15:51:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by James Espinoza
|
|
|
|
*
|
2008-06-28 18:10:04 +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.
|
2007-09-21 15:51:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "system.h"
|
|
|
|
#include "imx31l.h"
|
|
|
|
#include "avic-imx31.h"
|
2008-02-05 04:43:19 +00:00
|
|
|
#include "panic.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
2010-05-07 02:29:18 +00:00
|
|
|
#define avic ((unsigned long * const)AVIC_BASE_ADDR)
|
|
|
|
#define INTCNTL (0x000 / sizeof (unsigned long)) /* 000h */
|
|
|
|
#define NIMASK (0x004 / sizeof (unsigned long)) /* 004h */
|
|
|
|
#define INTENNUM (0x008 / sizeof (unsigned long)) /* 008h */
|
|
|
|
#define INTDISNUM (0x00c / sizeof (unsigned long)) /* 00Ch */
|
|
|
|
#define INTENABLE (0x010 / sizeof (unsigned long)) /* 010h H,L */
|
|
|
|
#define INTTYPE (0x018 / sizeof (unsigned long)) /* 018h H,L */
|
|
|
|
#define NIPRIORITY (0x020 / sizeof (unsigned long)) /* 020h 7-0 */
|
|
|
|
#define NIVECSR (0x040 / sizeof (unsigned long)) /* 040h */
|
|
|
|
#define FIVECSR (0x044 / sizeof (unsigned long)) /* 044h */
|
|
|
|
#define INTSRC (0x048 / sizeof (unsigned long)) /* 048h H,L */
|
|
|
|
#define INTFRC (0x050 / sizeof (unsigned long)) /* 050h H,L */
|
|
|
|
#define NIPND (0x058 / sizeof (unsigned long)) /* 058h H,L */
|
|
|
|
#define FIPND (0x060 / sizeof (unsigned long)) /* 060h H,L */
|
|
|
|
#define VECTOR (0x100 / sizeof (unsigned long)) /* 100h */
|
|
|
|
|
|
|
|
static const char * const avic_int_names[64] =
|
2008-02-05 04:43:19 +00:00
|
|
|
{
|
|
|
|
"RESERVED0", "RESERVED1", "RESERVED2", "I2C3",
|
|
|
|
"I2C2", "MPEG4_ENCODER", "RTIC", "FIR",
|
|
|
|
"MMC/SDHC2", "MMC/SDHC1", "I2C1", "SSI2",
|
|
|
|
"SSI1", "CSPI2", "CSPI1", "ATA",
|
|
|
|
"MBX", "CSPI3", "UART3", "IIM",
|
|
|
|
"SIM1", "SIM2", "RNGA", "EVTMON",
|
|
|
|
"KPP", "RTC", "PWN", "EPIT2",
|
|
|
|
"EPIT1", "GPT", "PWR_FAIL", "CCM_DVFS",
|
|
|
|
"UART2", "NANDFC", "SDMA", "USB_HOST1",
|
|
|
|
"USB_HOST2", "USB_OTG", "RESERVED3", "MSHC1",
|
|
|
|
"MSHC2", "IPU_ERR", "IPU", "RESERVED4",
|
|
|
|
"RESERVED5", "UART1", "UART4", "UART5",
|
|
|
|
"ETC_IRQ", "SCC_SCM", "SCC_SMN", "GPIO2",
|
|
|
|
"GPIO1", "CCM_CLK", "PCMCIA", "WDOG",
|
|
|
|
"GPIO3", "RESERVED6", "EXT_PWMG", "EXT_TEMP",
|
|
|
|
"EXT_SENS1", "EXT_SENS2", "EXT_WDOG", "EXT_TV"
|
|
|
|
};
|
|
|
|
|
2008-04-12 16:56:45 +00:00
|
|
|
void UIE_VECTOR(void)
|
2008-02-05 04:43:19 +00:00
|
|
|
{
|
2010-05-07 02:29:18 +00:00
|
|
|
unsigned long mode;
|
2008-04-27 22:01:25 +00:00
|
|
|
int offset;
|
2008-02-05 04:43:19 +00:00
|
|
|
|
2008-02-05 07:17:56 +00:00
|
|
|
asm volatile (
|
|
|
|
"mrs %0, cpsr \n" /* Mask core IRQ/FIQ */
|
|
|
|
"orr %0, %0, #0xc0 \n"
|
|
|
|
"msr cpsr_c, %0 \n"
|
|
|
|
"and %0, %0, #0x1f \n" /* Get mode bits */
|
|
|
|
: "=&r"(mode)
|
|
|
|
);
|
|
|
|
|
2010-05-07 02:29:18 +00:00
|
|
|
offset = mode == 0x11 ? (long)avic[FIVECSR] : ((long)avic[NIVECSR] >> 16);
|
2008-02-05 04:43:19 +00:00
|
|
|
|
2008-04-27 22:01:25 +00:00
|
|
|
panicf("Unhandled %s %d: %s",
|
2008-02-05 07:17:56 +00:00
|
|
|
mode == 0x11 ? "FIQ" : "IRQ", offset,
|
|
|
|
offset >= 0 ? avic_int_names[offset] : "<Unknown>");
|
2008-02-05 04:43:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-03 07:48:00 +00:00
|
|
|
#if 0
|
2008-02-05 04:43:19 +00:00
|
|
|
/* We use the AVIC */
|
2008-11-27 11:49:49 +00:00
|
|
|
void __attribute__((interrupt("IRQ"))) irq_handler(void)
|
2008-02-05 04:43:19 +00:00
|
|
|
{
|
2010-05-07 02:29:18 +00:00
|
|
|
int offset = (long)avic[NIVECSR] >> 16;
|
2008-11-27 11:49:49 +00:00
|
|
|
|
|
|
|
if (offset == -1)
|
|
|
|
{
|
|
|
|
/* This is called occasionally for some unknown reason even with the
|
|
|
|
* avic enabled but returning normally appears to cause no harm. The
|
|
|
|
* KPP and ATA seem to have a part in it (common but multiplexed pins
|
|
|
|
* that can interfere). It will be investigated more thoroughly but
|
|
|
|
* for now it is simply an occasional irritant. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-27 22:01:25 +00:00
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
|
|
|
panicf("Unhandled IRQ %d in irq_handler: %s", offset,
|
|
|
|
offset >= 0 ? avic_int_names[offset] : "<Unknown>");
|
2008-02-05 04:43:19 +00:00
|
|
|
}
|
2010-05-03 07:48:00 +00:00
|
|
|
#endif /* 0 */
|
2008-02-05 04:43:19 +00:00
|
|
|
|
|
|
|
/* Accoring to section 9.3.5 of the UM, the AVIC doesn't accelerate
|
|
|
|
* fast interrupts and they must be dispatched */
|
|
|
|
void __attribute__((naked)) fiq_handler(void)
|
|
|
|
{
|
|
|
|
asm volatile (
|
2008-04-27 21:32:10 +00:00
|
|
|
"mov r10, #0x68000000 \n" /* load AVIC base address */
|
2008-02-05 04:43:19 +00:00
|
|
|
"ldr r9, [r10, #0x44] \n" /* read FIVECSR of AVIC */
|
2008-04-27 21:32:10 +00:00
|
|
|
"add r10, r10, #0x100 \n" /* move pointer to base of VECTOR table */
|
2008-02-05 04:43:19 +00:00
|
|
|
"ldr r8, [r10, r9, lsl #2] \n" /* read FIQ vector from VECTOR table */
|
|
|
|
"bx r8 \n" /* jump to FIQ service routine */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-02-05 05:17:33 +00:00
|
|
|
void avic_init(void)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-02-08 02:20:05 +00:00
|
|
|
int i;
|
|
|
|
|
2008-02-05 05:17:33 +00:00
|
|
|
/* Disable all interrupts and set to unhandled */
|
2009-03-22 01:50:48 +00:00
|
|
|
avic_disable_int(INT_ALL);
|
2008-02-05 05:17:33 +00:00
|
|
|
|
2008-02-08 02:20:05 +00:00
|
|
|
/* Reset AVIC control */
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[INTCNTL] = 0;
|
2008-02-08 02:20:05 +00:00
|
|
|
|
2008-02-05 05:17:33 +00:00
|
|
|
/* Init all interrupts to type IRQ */
|
2009-03-22 01:50:48 +00:00
|
|
|
avic_set_int_type(INT_ALL, INT_TYPE_IRQ);
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-02-08 02:20:05 +00:00
|
|
|
/* Set all normal to lowest priority */
|
|
|
|
for (i = 0; i < 8; i++)
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[NIPRIORITY + i] = 0;
|
2008-02-08 02:20:05 +00:00
|
|
|
|
2010-05-06 03:23:51 +00:00
|
|
|
/* Set NM bit to enable VIC. Mask fast interrupts. Core arbiter rise
|
|
|
|
* for normal interrupts (for lowest latency). */
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[INTCNTL] |= AVIC_INTCNTL_NM | AVIC_INTCNTL_FIDIS |
|
|
|
|
AVIC_INTCNTL_NIAD;
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2008-02-05 05:17:33 +00:00
|
|
|
/* Enable VE bit in CP15 Control reg to enable VIC */
|
|
|
|
asm volatile (
|
2008-02-05 04:43:19 +00:00
|
|
|
"mrc p15, 0, r0, c1, c0, 0 \n"
|
2008-02-05 05:17:33 +00:00
|
|
|
"orr r0, r0, #(1 << 24) \n"
|
|
|
|
"mcr p15, 0, r0, c1, c0, 0 \n"
|
2008-02-05 04:43:19 +00:00
|
|
|
: : : "r0");
|
|
|
|
|
|
|
|
/* Enable normal interrupts at all priorities */
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[NIMASK] = AVIC_NIL_ENABLE;
|
2008-02-08 02:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void avic_set_int_priority(enum IMX31_INT_LIST ints,
|
|
|
|
unsigned long ni_priority)
|
|
|
|
{
|
2010-05-07 02:29:18 +00:00
|
|
|
volatile unsigned long * const reg = &avic[NIPRIORITY + 7 - (ints >> 3)];
|
2008-04-27 21:32:10 +00:00
|
|
|
unsigned int shift = (ints & 0x7) << 2;
|
2010-05-07 02:29:18 +00:00
|
|
|
unsigned long mask = 0xful << shift;
|
2008-02-08 02:20:05 +00:00
|
|
|
*reg = (*reg & ~mask) | ((ni_priority << shift) & mask);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void avic_enable_int(enum IMX31_INT_LIST ints, enum INT_TYPE intstype,
|
2008-02-08 02:20:05 +00:00
|
|
|
unsigned long ni_priority, void (*handler)(void))
|
2008-02-05 04:43:19 +00:00
|
|
|
{
|
2008-03-31 06:00:23 +00:00
|
|
|
int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
|
2007-09-21 15:51:53 +00:00
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
if (ints != INT_ALL) /* No mass-enable allowed */
|
2008-02-05 05:17:33 +00:00
|
|
|
{
|
2008-02-05 04:43:19 +00:00
|
|
|
avic_set_int_type(ints, intstype);
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[VECTOR + ints] = (unsigned long)handler;
|
|
|
|
avic[INTENNUM] = ints;
|
2008-02-08 02:20:05 +00:00
|
|
|
avic_set_int_priority(ints, ni_priority);
|
2008-02-05 04:43:19 +00:00
|
|
|
}
|
|
|
|
|
2008-03-31 06:00:23 +00:00
|
|
|
restore_interrupt(oldstatus);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void avic_disable_int(enum IMX31_INT_LIST ints)
|
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
if (ints == INT_ALL)
|
2008-02-05 05:17:33 +00:00
|
|
|
{
|
2010-05-07 02:29:18 +00:00
|
|
|
int i;
|
2008-02-05 05:17:33 +00:00
|
|
|
for (i = 0; i < 64; i++)
|
2008-02-05 04:43:19 +00:00
|
|
|
{
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[INTDISNUM] = i;
|
|
|
|
avic[VECTOR + i] = (unsigned long)UIE_VECTOR;
|
2008-02-05 04:43:19 +00:00
|
|
|
}
|
2008-02-05 05:17:33 +00:00
|
|
|
}
|
2008-02-05 04:43:19 +00:00
|
|
|
else
|
|
|
|
{
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[INTDISNUM] = ints;
|
|
|
|
avic[VECTOR + ints] = (unsigned long)UIE_VECTOR;
|
2008-02-05 04:43:19 +00:00
|
|
|
}
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 04:43:19 +00:00
|
|
|
static void set_int_type(int i, enum INT_TYPE intstype)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-04-27 21:32:10 +00:00
|
|
|
/* INTTYPEH: vectors 63-32, INTTYPEL: vectors 31-0 */
|
2010-05-07 02:29:18 +00:00
|
|
|
volatile unsigned long * const reg = &avic[INTTYPE + 1 - (i >> 5)];
|
|
|
|
unsigned long val = 1L << (i & 0x1f);
|
2008-02-05 04:43:19 +00:00
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
if (intstype == INT_TYPE_IRQ)
|
2008-02-05 04:43:19 +00:00
|
|
|
val = *reg & ~val;
|
|
|
|
else
|
|
|
|
val = *reg | val;
|
|
|
|
|
|
|
|
*reg = val;
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
|
|
|
|
2008-02-05 04:43:19 +00:00
|
|
|
void avic_set_int_type(enum IMX31_INT_LIST ints, enum INT_TYPE intstype)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
2008-03-31 06:00:23 +00:00
|
|
|
int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
|
2008-02-05 04:43:19 +00:00
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
if (ints == INT_ALL)
|
2008-02-05 05:17:33 +00:00
|
|
|
{
|
2008-02-05 04:43:19 +00:00
|
|
|
int i;
|
2008-02-05 05:17:33 +00:00
|
|
|
for (i = 0; i < 64; i++)
|
2008-02-05 04:43:19 +00:00
|
|
|
set_int_type(i, intstype);
|
2008-02-05 05:17:33 +00:00
|
|
|
}
|
2008-02-05 04:43:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
set_int_type(ints, intstype);
|
|
|
|
}
|
|
|
|
|
2008-03-31 06:00:23 +00:00
|
|
|
restore_interrupt(oldstatus);
|
2007-09-21 15:51:53 +00:00
|
|
|
}
|
2010-04-23 15:32:50 +00:00
|
|
|
|
2010-05-06 03:23:51 +00:00
|
|
|
void avic_set_ni_level(int level)
|
2010-04-23 15:32:50 +00:00
|
|
|
{
|
2010-05-06 03:23:51 +00:00
|
|
|
if (level < 0)
|
|
|
|
level = 0x1f; /* -1 */
|
|
|
|
else if (level > 15)
|
|
|
|
level = 15;
|
|
|
|
|
2010-05-07 02:29:18 +00:00
|
|
|
avic[NIMASK] = level;
|
2010-04-23 15:32:50 +00:00
|
|
|
}
|