blob: e60c4061dc4061fff9f36ae3fb9d0033b4cf0eac [file] [log] [blame]
Sascha Hauerbb6d8c82006-06-19 15:27:53 +01001/*
2 * arch/arm/mach-netx/generic.c
3 *
4 * Copyright (C) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/device.h>
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010027#include <asm/mach/map.h>
28#include <asm/hardware/vic.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/netx-regs.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010030#include <asm/mach/irq.h>
31
32static struct map_desc netx_io_desc[] __initdata = {
33 {
34 .virtual = NETX_IO_VIRT,
35 .pfn = __phys_to_pfn(NETX_IO_PHYS),
36 .length = NETX_IO_SIZE,
37 .type = MT_DEVICE
38 }
39};
40
41void __init netx_map_io(void)
42{
43 iotable_init(netx_io_desc, ARRAY_SIZE(netx_io_desc));
44}
45
46static struct resource netx_rtc_resources[] = {
47 [0] = {
48 .start = 0x00101200,
49 .end = 0x00101220,
50 .flags = IORESOURCE_MEM,
51 },
52};
53
54static struct platform_device netx_rtc_device = {
55 .name = "netx-rtc",
56 .id = 0,
57 .num_resources = ARRAY_SIZE(netx_rtc_resources),
58 .resource = netx_rtc_resources,
59};
60
61static struct platform_device *devices[] __initdata = {
62 &netx_rtc_device,
63};
64
65#if 0
66#define DEBUG_IRQ(fmt...) printk(fmt)
67#else
68#define DEBUG_IRQ(fmt...) while (0) {}
69#endif
70
71static void
Russell King10dd5ce2006-11-23 11:41:32 +000072netx_hif_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010073{
74 unsigned int irq = NETX_IRQ_HIF_CHAINED(0);
75 unsigned int stat;
76
77 stat = ((readl(NETX_DPMAS_INT_EN) &
78 readl(NETX_DPMAS_INT_STAT)) >> 24) & 0x1f;
79
80 desc = irq_desc + NETX_IRQ_HIF_CHAINED(0);
81
82 while (stat) {
83 if (stat & 1) {
84 DEBUG_IRQ("handling irq %d\n", irq);
Linus Torvalds0cd61b62006-10-06 10:53:39 -070085 desc_handle_irq(irq, desc);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010086 }
87 irq++;
88 desc++;
89 stat >>= 1;
90 }
91}
92
93static int
94netx_hif_irq_type(unsigned int _irq, unsigned int type)
95{
96 unsigned int val, irq;
97
98 val = readl(NETX_DPMAS_IF_CONF1);
99
100 irq = _irq - NETX_IRQ_HIF_CHAINED(0);
101
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100102 if (type & IRQ_TYPE_EDGE_RISING) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100103 DEBUG_IRQ("rising edges\n");
104 val |= (1 << 26) << irq;
105 }
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100106 if (type & IRQ_TYPE_EDGE_FALLING) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100107 DEBUG_IRQ("falling edges\n");
108 val &= ~((1 << 26) << irq);
109 }
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100110 if (type & IRQ_TYPE_LEVEL_LOW) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100111 DEBUG_IRQ("low level\n");
112 val &= ~((1 << 26) << irq);
113 }
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100114 if (type & IRQ_TYPE_LEVEL_HIGH) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100115 DEBUG_IRQ("high level\n");
116 val |= (1 << 26) << irq;
117 }
118
119 writel(val, NETX_DPMAS_IF_CONF1);
120
121 return 0;
122}
123
124static void
125netx_hif_ack_irq(unsigned int _irq)
126{
127 unsigned int val, irq;
128
129 irq = _irq - NETX_IRQ_HIF_CHAINED(0);
130 writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);
131
132 val = readl(NETX_DPMAS_INT_EN);
133 val &= ~((1 << 24) << irq);
134 writel(val, NETX_DPMAS_INT_EN);
135
Harvey Harrison8e86f422008-03-04 15:08:02 -0800136 DEBUG_IRQ("%s: irq %d\n", __func__, _irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100137}
138
139static void
140netx_hif_mask_irq(unsigned int _irq)
141{
142 unsigned int val, irq;
143
144 irq = _irq - NETX_IRQ_HIF_CHAINED(0);
145 val = readl(NETX_DPMAS_INT_EN);
146 val &= ~((1 << 24) << irq);
147 writel(val, NETX_DPMAS_INT_EN);
Harvey Harrison8e86f422008-03-04 15:08:02 -0800148 DEBUG_IRQ("%s: irq %d\n", __func__, _irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100149}
150
151static void
152netx_hif_unmask_irq(unsigned int _irq)
153{
154 unsigned int val, irq;
155
156 irq = _irq - NETX_IRQ_HIF_CHAINED(0);
157 val = readl(NETX_DPMAS_INT_EN);
158 val |= (1 << 24) << irq;
159 writel(val, NETX_DPMAS_INT_EN);
Harvey Harrison8e86f422008-03-04 15:08:02 -0800160 DEBUG_IRQ("%s: irq %d\n", __func__, _irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100161}
162
Russell King10dd5ce2006-11-23 11:41:32 +0000163static struct irq_chip netx_hif_chip = {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100164 .ack = netx_hif_ack_irq,
165 .mask = netx_hif_mask_irq,
166 .unmask = netx_hif_unmask_irq,
167 .set_type = netx_hif_irq_type,
168};
169
170void __init netx_init_irq(void)
171{
172 int irq;
173
174 vic_init(__io(io_p2v(NETX_PA_VIC)), 0, ~0);
175
176 for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
177 set_irq_chip(irq, &netx_hif_chip);
Russell King10dd5ce2006-11-23 11:41:32 +0000178 set_irq_handler(irq, handle_level_irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100179 set_irq_flags(irq, IRQF_VALID);
180 }
181
182 writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
183 set_irq_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
184}
185
186static int __init netx_init(void)
187{
188 return platform_add_devices(devices, ARRAY_SIZE(devices));
189}
190
191subsys_initcall(netx_init);
192