2009-04-10 18:15:10 +02:00
|
|
|
/*
|
|
|
|
mini - a Free Software replacement for the Nintendo/BroadOn IOS.
|
|
|
|
IRQ support
|
|
|
|
|
|
|
|
Copyright (C) 2008, 2009 Hector Martin "marcan" <marcan@marcansoft.com>
|
2009-04-13 23:13:51 +02:00
|
|
|
Copyright (C) 2008, 2009 Sven Peter <svenpeter@gmail.com>
|
2009-04-13 23:38:37 +02:00
|
|
|
Copyright (C) 2009 Andre Heider "dhewg" <dhewg@wiibrew.org>
|
2009-04-10 18:15:10 +02:00
|
|
|
|
2009-05-11 07:53:16 +02:00
|
|
|
# This code is licensed to you under the terms of the GNU GPL, version 2;
|
|
|
|
# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
2009-04-10 18:15:10 +02:00
|
|
|
*/
|
2009-05-11 07:53:16 +02:00
|
|
|
|
2009-01-08 23:27:22 +01:00
|
|
|
#include "irq.h"
|
|
|
|
#include "hollywood.h"
|
|
|
|
#include "gecko.h"
|
|
|
|
#include "utils.h"
|
2009-01-16 08:51:51 +01:00
|
|
|
#include "ipc.h"
|
2009-01-17 15:05:13 +01:00
|
|
|
#include "crypto.h"
|
2009-01-30 13:43:35 +01:00
|
|
|
#include "nand.h"
|
2009-04-11 18:20:16 +02:00
|
|
|
#include "sdhcvar.h"
|
2009-01-08 23:27:22 +01:00
|
|
|
|
2009-04-10 11:25:10 +02: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();
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQMASK, 0);
|
|
|
|
write32(HW_ARMIRQFLAG, 0xffffffff);
|
2009-01-08 23:27:22 +01:00
|
|
|
irq_restore(CPSR_FIQDIS);
|
|
|
|
|
|
|
|
//???
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQMASK+0x04, 0);
|
|
|
|
write32(HW_ARMIRQMASK+0x20, 0);
|
2009-04-10 11:25:10 +02:00
|
|
|
|
|
|
|
write32(HW_ALARM, 0);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void irq_shutdown(void)
|
|
|
|
{
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQMASK, 0);
|
|
|
|
write32(HW_ARMIRQFLAG, 0xffffffff);
|
2009-01-08 23:27:22 +01:00
|
|
|
irq_kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
void irq_handler(void)
|
|
|
|
{
|
2009-03-18 18:05:23 +01:00
|
|
|
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) {
|
2009-04-10 11:25:10 +02:00
|
|
|
if (_alarm_frequency) {
|
|
|
|
// currently we use the alarm timer only for lame usbgecko polling
|
|
|
|
gecko_timer();
|
|
|
|
write32(HW_ALARM, read32(HW_TIMER) + _alarm_frequency);
|
|
|
|
}
|
2009-03-18 18:05:23 +01:00
|
|
|
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
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_NAND);
|
2009-01-17 15:05:13 +01:00
|
|
|
nand_irq();
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
if(flags & IRQF_GPIO1B) {
|
2009-04-15 01:43:52 +02:00
|
|
|
// gecko_printf("IRQ: GPIO1B\n");
|
2009-01-08 23:27:22 +01:00
|
|
|
write32(HW_GPIO1BINTFLAG, 0xFFFFFF); // shut it up
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_GPIO1B);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
if(flags & IRQF_GPIO1) {
|
2009-04-15 01:43:52 +02:00
|
|
|
// gecko_printf("IRQ: GPIO1\n");
|
2009-01-08 23:27:22 +01:00
|
|
|
write32(HW_GPIO1INTFLAG, 0xFFFFFF); // shut it up
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_GPIO1);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
if(flags & IRQF_RESET) {
|
2009-04-15 01:43:52 +02:00
|
|
|
// gecko_printf("IRQ: RESET\n");
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_RESET);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
if(flags & IRQF_IPC) {
|
2009-01-16 08:51:51 +01:00
|
|
|
//gecko_printf("IRQ: IPC\n");
|
|
|
|
ipc_irq();
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_IPC);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
2009-01-17 15:05:13 +01:00
|
|
|
if(flags & IRQF_AES) {
|
2009-04-15 01:43:52 +02:00
|
|
|
// gecko_printf("IRQ: AES\n");
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_AES);
|
2009-01-17 15:05:13 +01:00
|
|
|
}
|
2009-04-11 18:20:16 +02:00
|
|
|
if (flags & IRQF_SDHC) {
|
2009-04-12 02:21:32 +02:00
|
|
|
// gecko_printf("IRQ: SDHC\n");
|
2009-04-11 18:20:16 +02:00
|
|
|
write32(HW_ARMIRQFLAG, IRQF_SDHC);
|
|
|
|
sdhc_irq();
|
|
|
|
}
|
|
|
|
|
2009-01-08 23:27:22 +01:00
|
|
|
flags &= ~IRQF_ALL;
|
|
|
|
if(flags) {
|
2009-01-16 08:51:51 +01:00
|
|
|
gecko_printf("IRQ: unknown 0x%08x\n", flags);
|
2009-03-18 18:05:23 +01:00
|
|
|
write32(HW_ARMIRQFLAG, flags);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void irq_enable(u32 irq)
|
|
|
|
{
|
2009-03-18 18:05:23 +01:00
|
|
|
set32(HW_ARMIRQMASK, 1<<irq);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void irq_disable(u32 irq)
|
|
|
|
{
|
2009-03-18 18:05:23 +01:00
|
|
|
clear32(HW_ARMIRQMASK, 1<<irq);
|
2009-01-08 23:27:22 +01:00
|
|
|
}
|
2009-04-10 11:25:10 +02: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);
|
|
|
|
}
|
|
|
|
|