15
#include <drivers/common/memory.h>
18
#include <drivers/irqctrl.h>
19
#include <drivers/amba_pnp.h>
21
#include <embox/unit.h>
34
static volatile struct irqmp_regs *dev_regs;
36
static int dev_regs_init(void);
38
void irqctrl_enable(unsigned int irq) {
40
REG_ORIN(&dev_regs->mask, 1 << irq);
43
void irqctrl_disable(unsigned int irq) {
45
REG_ANDIN(&dev_regs->mask, ~(1 << irq));
48
void irqctrl_clear(unsigned int irq) {
50
REG_ORIN(&dev_regs->clear, 1 << irq);
51
REG_ANDIN(&dev_regs->force, ~(1 << irq));
54
void irqctrl_force(unsigned int irq) {
56
REG_ORIN(&dev_regs->force, 1 << irq);
59
static int irqmp_init(void) {
62
assert(NULL == dev_regs);
63
if (0 != (error = dev_regs_init())) {
68
REG_STORE(&dev_regs->level, 0x0);
69
REG_STORE(&dev_regs->mask, 0x0);
70
REG_STORE(&dev_regs->pending, 0x0);
71
REG_STORE(&dev_regs->force, 0x0);
72
REG_STORE(&dev_regs->clear, ~0x0);
79
static int irqctrl_memory_map(uint32_t base, size_t len) {
82
base = ((uint32_t) base) & ~(PAGE_SIZE() - 1);
85
ptr = mmap_device_memory((void *) base, len, PROT_READ | PROT_WRITE | PROT_NOCACHE,
87
if (ptr == MAP_FAILED) {
94
static int dev_regs_init(void) {
96
if (-1 == capture_amba_dev(&amba_dev, AMBAPP_VENDOR_GAISLER,
97
AMBAPP_DEVICE_GAISLER_IRQMP, false, false)) {
100
dev_regs = (volatile struct irqmp_regs *) amba_dev.bar[0].start;
102
return irqctrl_memory_map((uint32_t) dev_regs, 0x100);
104
#elif OPTION_DEFINED(NUMBER,irqmp_base)
105
static int dev_regs_init(void) {
106
dev_regs = (volatile struct irqmp_regs *) OPTION_GET(NUMBER,irqmp_base);
110
return irqctrl_memory_map((uint32_t) dev_regs, 0x100);
113
PERIPH_MEMORY_DEFINE(irqmp, OPTION_GET(NUMBER, irqmp_base), 0x100);
114
IRQCTRL_DEF(irqmp, irqmp_init);
116
# error "Either DRIVER_AMBAPP or irqmp_base option must be defined"