1/*
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>
25#include <asm/hardware.h>
26#include <asm/mach/map.h>
27#include <asm/hardware/vic.h>
28#include <asm/io.h>
29#include <asm/arch/netx-regs.h>
30#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#define DEBUG_IRQ(fmt...)	while (0) {}
66
67static void
68netx_hif_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
69{
70	unsigned int irq = NETX_IRQ_HIF_CHAINED(0);
71	unsigned int stat;
72
73	stat = ((readl(NETX_DPMAS_INT_EN) &
74		readl(NETX_DPMAS_INT_STAT)) >> 24) & 0x1f;
75
76	desc = irq_desc + NETX_IRQ_HIF_CHAINED(0);
77
78	while (stat) {
79		if (stat & 1) {
80			DEBUG_IRQ("handling irq %d\n", irq);
81			desc_handle_irq(irq, desc);
82		}
83		irq++;
84		desc++;
85		stat >>= 1;
86	}
87}
88
89static int
90netx_hif_irq_type(unsigned int _irq, unsigned int type)
91{
92	unsigned int val, irq;
93
94	val = readl(NETX_DPMAS_IF_CONF1);
95
96	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
97
98	if (type & __IRQT_RISEDGE) {
99		DEBUG_IRQ("rising edges\n");
100		val |= (1 << 26) << irq;
101	}
102	if (type & __IRQT_FALEDGE) {
103		DEBUG_IRQ("falling edges\n");
104		val &= ~((1 << 26) << irq);
105	}
106	if (type & __IRQT_LOWLVL) {
107		DEBUG_IRQ("low level\n");
108		val &= ~((1 << 26) << irq);
109	}
110	if (type & __IRQT_HIGHLVL) {
111		DEBUG_IRQ("high level\n");
112		val |= (1 << 26) << irq;
113	}
114
115	writel(val, NETX_DPMAS_IF_CONF1);
116
117	return 0;
118}
119
120static void
121netx_hif_ack_irq(unsigned int _irq)
122{
123	unsigned int val, irq;
124
125	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
126	writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);
127
128	val = readl(NETX_DPMAS_INT_EN);
129	val &= ~((1 << 24) << irq);
130	writel(val, NETX_DPMAS_INT_EN);
131
132	DEBUG_IRQ("%s: irq %d\n", __FUNCTION__, _irq);
133}
134
135static void
136netx_hif_mask_irq(unsigned int _irq)
137{
138	unsigned int val, irq;
139
140	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
141	val = readl(NETX_DPMAS_INT_EN);
142	val &= ~((1 << 24) << irq);
143	writel(val, NETX_DPMAS_INT_EN);
144	DEBUG_IRQ("%s: irq %d\n", __FUNCTION__, _irq);
145}
146
147static void
148netx_hif_unmask_irq(unsigned int _irq)
149{
150	unsigned int val, irq;
151
152	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
153	val = readl(NETX_DPMAS_INT_EN);
154	val |= (1 << 24) << irq;
155	writel(val, NETX_DPMAS_INT_EN);
156	DEBUG_IRQ("%s: irq %d\n", __FUNCTION__, _irq);
157}
158
159static struct irq_chip netx_hif_chip = {
160	.ack = netx_hif_ack_irq,
161	.mask = netx_hif_mask_irq,
162	.unmask = netx_hif_unmask_irq,
163	.set_type = netx_hif_irq_type,
164};
165
166void __init netx_init_irq(void)
167{
168	int irq;
169
170	vic_init(__io(io_p2v(NETX_PA_VIC)), 0, ~0);
171
172	for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
173		set_irq_chip(irq, &netx_hif_chip);
174		set_irq_handler(irq, handle_level_irq);
175		set_irq_flags(irq, IRQF_VALID);
176	}
177
178	writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
179	set_irq_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
180}
181
182static int __init netx_init(void)
183{
184	return platform_add_devices(devices, ARRAY_SIZE(devices));
185}
186
187subsys_initcall(netx_init);
188