mini/irq.c

126 lines
2.9 KiB
C
Raw Normal View History

/*
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
IRQ support
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
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, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2009-01-08 23:27:22 +01:00
#include "irq.h"
#include "hollywood.h"
#include "gecko.h"
#include "utils.h"
#include "ipc.h"
#include "crypto.h"
2009-01-30 13:43:35 +01:00
#include "nand.h"
2009-01-08 23:27:22 +01:00
static u32 _alarm_frequency = 0;
2009-01-08 23:27:22 +01:00
void irq_setup_stack(void);
void irq_initialize(void)
{
irq_setup_stack();
write32(HW_ARMIRQMASK, 0);
write32(HW_ARMIRQFLAG, 0xffffffff);
2009-01-08 23:27:22 +01:00
irq_restore(CPSR_FIQDIS);
//???
write32(HW_ARMIRQMASK+0x04, 0);
write32(HW_ARMIRQMASK+0x20, 0);
write32(HW_ALARM, 0);
2009-01-08 23:27:22 +01:00
}
void irq_shutdown(void)
{
write32(HW_ARMIRQMASK, 0);
write32(HW_ARMIRQFLAG, 0xffffffff);
2009-01-08 23:27:22 +01:00
irq_kill();
}
void irq_handler(void)
{
u32 enabled = read32(HW_ARMIRQMASK);
u32 flags = read32(HW_ARMIRQFLAG);
2009-01-08 23:27:22 +01:00
2009-01-25 04:04:19 +01:00
//gecko_printf("In IRQ handler: 0x%08x 0x%08x 0x%08x\n", enabled, flags, flags & enabled);
2009-01-08 23:27:22 +01:00
flags = flags & enabled;
if(flags & IRQF_TIMER) {
if (_alarm_frequency) {
// currently we use the alarm timer only for lame usbgecko polling
gecko_timer();
write32(HW_ALARM, read32(HW_TIMER) + _alarm_frequency);
}
write32(HW_ARMIRQFLAG, IRQF_TIMER);
2009-01-08 23:27:22 +01:00
}
if(flags & IRQF_NAND) {
2009-01-30 13:43:35 +01:00
// gecko_printf("IRQ: NAND\n");
2009-01-08 23:27:22 +01:00
write32(NAND_CMD, 0x7fffffff); // shut it up
write32(HW_ARMIRQFLAG, IRQF_NAND);
nand_irq();
2009-01-08 23:27:22 +01:00
}
if(flags & IRQF_GPIO1B) {
gecko_printf("IRQ: GPIO1B\n");
write32(HW_GPIO1BINTFLAG, 0xFFFFFF); // shut it up
write32(HW_ARMIRQFLAG, IRQF_GPIO1B);
2009-01-08 23:27:22 +01:00
}
if(flags & IRQF_GPIO1) {
gecko_printf("IRQ: GPIO1\n");
write32(HW_GPIO1INTFLAG, 0xFFFFFF); // shut it up
write32(HW_ARMIRQFLAG, IRQF_GPIO1);
2009-01-08 23:27:22 +01:00
}
if(flags & IRQF_RESET) {
gecko_printf("IRQ: RESET\n");
write32(HW_ARMIRQFLAG, IRQF_RESET);
2009-01-08 23:27:22 +01:00
}
if(flags & IRQF_IPC) {
//gecko_printf("IRQ: IPC\n");
ipc_irq();
write32(HW_ARMIRQFLAG, IRQF_IPC);
2009-01-08 23:27:22 +01:00
}
if(flags & IRQF_AES) {
gecko_printf("IRQ: AES\n");
write32(HW_ARMIRQFLAG, IRQF_AES);
}
2009-01-08 23:27:22 +01:00
flags &= ~IRQF_ALL;
if(flags) {
gecko_printf("IRQ: unknown 0x%08x\n", flags);
write32(HW_ARMIRQFLAG, flags);
2009-01-08 23:27:22 +01:00
}
}
void irq_enable(u32 irq)
{
set32(HW_ARMIRQMASK, 1<<irq);
2009-01-08 23:27:22 +01:00
}
void irq_disable(u32 irq)
{
clear32(HW_ARMIRQMASK, 1<<irq);
2009-01-08 23:27:22 +01:00
}
void irq_set_alarm(u32 ms, u8 enable)
{
_alarm_frequency = IRQ_ALARM_MS2REG(ms);
if (enable)
write32(HW_ALARM, read32(HW_TIMER) + _alarm_frequency);
}