• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/arch/arm/mach-netx/
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 <linux/io.h>
26#include <mach/hardware.h>
27#include <asm/mach/map.h>
28#include <asm/hardware/vic.h>
29#include <mach/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	while (stat) {
77		if (stat & 1) {
78			DEBUG_IRQ("handling irq %d\n", irq);
79			generic_handle_irq(irq);
80		}
81		irq++;
82		stat >>= 1;
83	}
84}
85
86static int
87netx_hif_irq_type(unsigned int _irq, unsigned int type)
88{
89	unsigned int val, irq;
90
91	val = readl(NETX_DPMAS_IF_CONF1);
92
93	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
94
95	if (type & IRQ_TYPE_EDGE_RISING) {
96		DEBUG_IRQ("rising edges\n");
97		val |= (1 << 26) << irq;
98	}
99	if (type & IRQ_TYPE_EDGE_FALLING) {
100		DEBUG_IRQ("falling edges\n");
101		val &= ~((1 << 26) << irq);
102	}
103	if (type & IRQ_TYPE_LEVEL_LOW) {
104		DEBUG_IRQ("low level\n");
105		val &= ~((1 << 26) << irq);
106	}
107	if (type & IRQ_TYPE_LEVEL_HIGH) {
108		DEBUG_IRQ("high level\n");
109		val |= (1 << 26) << irq;
110	}
111
112	writel(val, NETX_DPMAS_IF_CONF1);
113
114	return 0;
115}
116
117static void
118netx_hif_ack_irq(unsigned int _irq)
119{
120	unsigned int val, irq;
121
122	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
123	writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);
124
125	val = readl(NETX_DPMAS_INT_EN);
126	val &= ~((1 << 24) << irq);
127	writel(val, NETX_DPMAS_INT_EN);
128
129	DEBUG_IRQ("%s: irq %d\n", __func__, _irq);
130}
131
132static void
133netx_hif_mask_irq(unsigned int _irq)
134{
135	unsigned int val, irq;
136
137	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
138	val = readl(NETX_DPMAS_INT_EN);
139	val &= ~((1 << 24) << irq);
140	writel(val, NETX_DPMAS_INT_EN);
141	DEBUG_IRQ("%s: irq %d\n", __func__, _irq);
142}
143
144static void
145netx_hif_unmask_irq(unsigned int _irq)
146{
147	unsigned int val, irq;
148
149	irq = _irq - NETX_IRQ_HIF_CHAINED(0);
150	val = readl(NETX_DPMAS_INT_EN);
151	val |= (1 << 24) << irq;
152	writel(val, NETX_DPMAS_INT_EN);
153	DEBUG_IRQ("%s: irq %d\n", __func__, _irq);
154}
155
156static struct irq_chip netx_hif_chip = {
157	.ack = netx_hif_ack_irq,
158	.mask = netx_hif_mask_irq,
159	.unmask = netx_hif_unmask_irq,
160	.set_type = netx_hif_irq_type,
161};
162
163void __init netx_init_irq(void)
164{
165	int irq;
166
167	vic_init(__io(io_p2v(NETX_PA_VIC)), 0, ~0, 0);
168
169	for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
170		set_irq_chip(irq, &netx_hif_chip);
171		set_irq_handler(irq, handle_level_irq);
172		set_irq_flags(irq, IRQF_VALID);
173	}
174
175	writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
176	set_irq_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
177}
178
179static int __init netx_init(void)
180{
181	return platform_add_devices(devices, ARRAY_SIZE(devices));
182}
183
184subsys_initcall(netx_init);
185