summaryrefslogtreecommitdiff
path: root/firmware/smu.c
blob: 8831317c623e19bb89f9681d2cc7a8d2a45ff6de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Free/Libre SMU firmware
 * Copyright (C) 2015  Damien Zammit <damien@zamaudio.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, either version 3 of the License, or
 * (at your option) any later version.
 *-
 * 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.
 * See <http://www.gnu.org/licenses/>.-
 */

#include "smu.h"
#include "delay.h"
#include "servicereq.h"

void main(void)
{
	int i;
	int ie;
	int e3;

	/* disable interrupts */
	asm volatile ("rcsr %0,ie":"=r"(ie));
	ie &= (~0x1);
	asm volatile ("wcsr ie, %0"::"r"(ie));

	for (i = 0; i < 32; i++) {
		ISREntryTable[i].Callback = 0;
		ISREntryTable[i].Context = 0;
	}

	/* clear all pending interrupts */
	asm volatile ("wcsr ip, %0"::"r"(0xffffffff));
	
	/* tell x86 that interrupts are ready */
	write32(0xe0003004, INTACK | INTDONE);
	write32(0x1f380, 1);
	
	while (1) {
		e3 = read32(0xe0003000);
		if ((e3 & ~1)) {
			write32(0xe0003004, INTACK);
			smu_service_request(e3);
			write32(0xe0003004, INTACK | INTDONE);
		}

		mdelay(30);
	}
}