blob: acc232dcf21d50aac2c6b75eb3d6babce8e4ed17 [file] [log] [blame]
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +02001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2002 (440 port)
6 * Scott McNutt, Artesyn Communication Producs, smcnutt@artsyncp.com
7 *
8 * (C) Copyright 2003 (440GX port)
9 * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com
10 *
11 * (C) Copyright 2008 (PPC440X05 port for Virtex 5 FX)
Ricardo Ribalda Delgado5712d042016-01-26 11:24:08 +010012 * Ricardo Ribalda-Universidad Autonoma de Madrid-ricardo.ribalda@gmail.com
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020013 * Work supported by Qtechnology (htpp://qtec.com)
14 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020015 * SPDX-License-Identifier: GPL-2.0+
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020016 */
17
18#include <common.h>
19#include <watchdog.h>
20#include <command.h>
21#include <asm/processor.h>
22#include <asm/interrupt.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020023#include <asm/ppc4xx.h>
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020024#include <ppc_asm.tmpl>
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020025
26#if (UIC_MAX > 3)
27#define UICB0_ALL (UIC_MASK(VECNUM_UIC1CI) | UIC_MASK(VECNUM_UIC1NCI) | \
28 UIC_MASK(VECNUM_UIC2CI) | UIC_MASK(VECNUM_UIC2NCI) | \
29 UIC_MASK(VECNUM_UIC3CI) | UIC_MASK(VECNUM_UIC3NCI))
30#elif (UIC_MAX > 2)
31#define UICB0_ALL (UIC_MASK(VECNUM_UIC1CI) | UIC_MASK(VECNUM_UIC1NCI) | \
32 UIC_MASK(VECNUM_UIC2CI) | UIC_MASK(VECNUM_UIC2NCI))
33#elif (UIC_MAX > 1)
34#define UICB0_ALL (UIC_MASK(VECNUM_UIC1CI) | UIC_MASK(VECNUM_UIC1NCI))
35#else
36#define UICB0_ALL 0
37#endif
38
39u32 get_dcr(u16);
40
41DECLARE_GLOBAL_DATA_PTR;
42
43void pic_enable(void)
44{
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020045#if (UIC_MAX > 1)
46 /* Install the UIC1 handlers */
Stefan Roese1fbbe602008-07-18 12:24:41 +020047 irq_install_handler(VECNUM_UIC1NCI, (void *)(void *)external_interrupt, 0);
48 irq_install_handler(VECNUM_UIC1CI, (void *)(void *)external_interrupt, 0);
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020049#endif
50#if (UIC_MAX > 2)
Stefan Roese1fbbe602008-07-18 12:24:41 +020051 irq_install_handler(VECNUM_UIC2NCI, (void *)(void *)external_interrupt, 0);
52 irq_install_handler(VECNUM_UIC2CI, (void *)(void *)external_interrupt, 0);
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020053#endif
54#if (UIC_MAX > 3)
Stefan Roese1fbbe602008-07-18 12:24:41 +020055 irq_install_handler(VECNUM_UIC3NCI, (void *)(void *)external_interrupt, 0);
56 irq_install_handler(VECNUM_UIC3CI, (void *)(void *)external_interrupt, 0);
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020057#endif
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020058}
59
60/* Handler for UIC interrupt */
61static void uic_interrupt(u32 uic_base, int vec_base)
62{
63 u32 uic_msr;
64 u32 msr_shift;
65 int vec;
66
67 /*
68 * Read masked interrupt status register to determine interrupt source
69 */
70 uic_msr = get_dcr(uic_base + UIC_MSR);
71 msr_shift = uic_msr;
72 vec = vec_base;
73
74 while (msr_shift != 0) {
75 if (msr_shift & 0x80000000)
76 interrupt_run_handler(vec);
77 /*
78 * Shift msr to next position and increment vector
79 */
80 msr_shift <<= 1;
81 vec++;
82 }
83}
84
85/*
86 * Handle external interrupts
87 */
88void external_interrupt(struct pt_regs *regs)
89{
90 u32 uic_msr;
91
92 /*
93 * Read masked interrupt status register to determine interrupt source
94 */
Stefan Roese707fd362009-09-24 09:55:50 +020095 uic_msr = mfdcr(UIC0MSR);
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +020096
97#if (UIC_MAX > 1)
98 if ((UIC_MASK(VECNUM_UIC1CI) & uic_msr) ||
99 (UIC_MASK(VECNUM_UIC1NCI) & uic_msr))
100 uic_interrupt(UIC1_DCR_BASE, 32);
101#endif
102
103#if (UIC_MAX > 2)
104 if ((UIC_MASK(VECNUM_UIC2CI) & uic_msr) ||
105 (UIC_MASK(VECNUM_UIC2NCI) & uic_msr))
106 uic_interrupt(UIC2_DCR_BASE, 64);
107#endif
108
109#if (UIC_MAX > 3)
110 if ((UIC_MASK(VECNUM_UIC3CI) & uic_msr) ||
111 (UIC_MASK(VECNUM_UIC3NCI) & uic_msr))
112 uic_interrupt(UIC3_DCR_BASE, 96);
113#endif
114
Stefan Roese707fd362009-09-24 09:55:50 +0200115 mtdcr(UIC0SR, (uic_msr & UICB0_ALL));
Victor Gallardo61fa3ab2008-08-28 16:03:28 -0700116
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200117 if (uic_msr & ~(UICB0_ALL))
118 uic_interrupt(UIC0_DCR_BASE, 0);
119
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200120 return;
121}
122
123void pic_irq_ack(unsigned int vec)
124{
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200125 if ((vec >= 0) && (vec < 32))
Stefan Roese707fd362009-09-24 09:55:50 +0200126 mtdcr(UIC0SR, UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200127 else if ((vec >= 32) && (vec < 64))
Stefan Roese707fd362009-09-24 09:55:50 +0200128 mtdcr(UIC1SR, UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200129 else if ((vec >= 64) && (vec < 96))
Stefan Roese707fd362009-09-24 09:55:50 +0200130 mtdcr(UIC2SR, UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200131 else if (vec >= 96)
Stefan Roese707fd362009-09-24 09:55:50 +0200132 mtdcr(UIC3SR, UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200133}
134
135/*
136 * Install and free a interrupt handler.
137 */
138void pic_irq_enable(unsigned int vec)
139{
140
141 if ((vec >= 0) && (vec < 32))
Stefan Roese707fd362009-09-24 09:55:50 +0200142 mtdcr(UIC0ER, mfdcr(UIC0ER) | UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200143 else if ((vec >= 32) && (vec < 64))
Stefan Roese707fd362009-09-24 09:55:50 +0200144 mtdcr(UIC1ER, mfdcr(UIC1ER) | UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200145 else if ((vec >= 64) && (vec < 96))
Stefan Roese707fd362009-09-24 09:55:50 +0200146 mtdcr(UIC2ER, mfdcr(UIC2ER) | UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200147 else if (vec >= 96)
Stefan Roese707fd362009-09-24 09:55:50 +0200148 mtdcr(UIC3ER, mfdcr(UIC3ER) | UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200149
Alessio Centazzo71d4e3c2009-07-01 22:20:51 -0700150 debug("Install interrupt vector %d\n", vec);
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200151}
152
153void pic_irq_disable(unsigned int vec)
154{
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200155 if ((vec >= 0) && (vec < 32))
Stefan Roese707fd362009-09-24 09:55:50 +0200156 mtdcr(UIC0ER, mfdcr(UIC0ER) & ~UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200157 else if ((vec >= 32) && (vec < 64))
Stefan Roese707fd362009-09-24 09:55:50 +0200158 mtdcr(UIC1ER, mfdcr(UIC1ER) & ~UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200159 else if ((vec >= 64) && (vec < 96))
Stefan Roese707fd362009-09-24 09:55:50 +0200160 mtdcr(UIC2ER, mfdcr(UIC2ER) & ~UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200161 else if (vec >= 96)
Stefan Roese707fd362009-09-24 09:55:50 +0200162 mtdcr(UIC3ER, mfdcr(UIC3ER) & ~UIC_MASK(vec));
Ricardo Ribalda Delgado95c50202008-07-17 11:44:12 +0200163}