blob: 842302df99c1bfdcdf0a0c00fa8131e30206562d [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>
Rob Herring9e47b8b2013-01-07 09:45:59 -060026#include <linux/irqchip/arm-vic.h>
Robin Holt7b6d8642013-07-08 16:01:40 -070027#include <linux/reboot.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010029#include <asm/mach/map.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010030#include <mach/netx-regs.h>
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010031#include <asm/mach/irq.h>
32
33static struct map_desc netx_io_desc[] __initdata = {
34 {
35 .virtual = NETX_IO_VIRT,
36 .pfn = __phys_to_pfn(NETX_IO_PHYS),
37 .length = NETX_IO_SIZE,
38 .type = MT_DEVICE
39 }
40};
41
42void __init netx_map_io(void)
43{
44 iotable_init(netx_io_desc, ARRAY_SIZE(netx_io_desc));
45}
46
47static struct resource netx_rtc_resources[] = {
48 [0] = {
49 .start = 0x00101200,
50 .end = 0x00101220,
51 .flags = IORESOURCE_MEM,
52 },
53};
54
55static struct platform_device netx_rtc_device = {
56 .name = "netx-rtc",
57 .id = 0,
58 .num_resources = ARRAY_SIZE(netx_rtc_resources),
59 .resource = netx_rtc_resources,
60};
61
62static struct platform_device *devices[] __initdata = {
63 &netx_rtc_device,
64};
65
66#if 0
67#define DEBUG_IRQ(fmt...) printk(fmt)
68#else
69#define DEBUG_IRQ(fmt...) while (0) {}
70#endif
71
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +020072static void netx_hif_demux_handler(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
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010080 while (stat) {
81 if (stat & 1) {
82 DEBUG_IRQ("handling irq %d\n", irq);
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +010083 generic_handle_irq(irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010084 }
85 irq++;
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010086 stat >>= 1;
87 }
88}
89
90static int
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +010091netx_hif_irq_type(struct irq_data *d, unsigned int type)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010092{
93 unsigned int val, irq;
94
95 val = readl(NETX_DPMAS_IF_CONF1);
96
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +010097 irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +010098
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +010099 if (type & IRQ_TYPE_EDGE_RISING) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100100 DEBUG_IRQ("rising edges\n");
101 val |= (1 << 26) << irq;
102 }
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100103 if (type & IRQ_TYPE_EDGE_FALLING) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100104 DEBUG_IRQ("falling edges\n");
105 val &= ~((1 << 26) << irq);
106 }
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100107 if (type & IRQ_TYPE_LEVEL_LOW) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100108 DEBUG_IRQ("low level\n");
109 val &= ~((1 << 26) << irq);
110 }
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100111 if (type & IRQ_TYPE_LEVEL_HIGH) {
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100112 DEBUG_IRQ("high level\n");
113 val |= (1 << 26) << irq;
114 }
115
116 writel(val, NETX_DPMAS_IF_CONF1);
117
118 return 0;
119}
120
121static void
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100122netx_hif_ack_irq(struct irq_data *d)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100123{
124 unsigned int val, irq;
125
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100126 irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100127 writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);
128
129 val = readl(NETX_DPMAS_INT_EN);
130 val &= ~((1 << 24) << irq);
131 writel(val, NETX_DPMAS_INT_EN);
132
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100133 DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100134}
135
136static void
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100137netx_hif_mask_irq(struct irq_data *d)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100138{
139 unsigned int val, irq;
140
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100141 irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100142 val = readl(NETX_DPMAS_INT_EN);
143 val &= ~((1 << 24) << irq);
144 writel(val, NETX_DPMAS_INT_EN);
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100145 DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100146}
147
148static void
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100149netx_hif_unmask_irq(struct irq_data *d)
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100150{
151 unsigned int val, irq;
152
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100153 irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100154 val = readl(NETX_DPMAS_INT_EN);
155 val |= (1 << 24) << irq;
156 writel(val, NETX_DPMAS_INT_EN);
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100157 DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100158}
159
Russell King10dd5ce2006-11-23 11:41:32 +0000160static struct irq_chip netx_hif_chip = {
Lennert Buytenhek4f8d7542010-11-29 10:38:10 +0100161 .irq_ack = netx_hif_ack_irq,
162 .irq_mask = netx_hif_mask_irq,
163 .irq_unmask = netx_hif_unmask_irq,
164 .irq_set_type = netx_hif_irq_type,
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100165};
166
167void __init netx_init_irq(void)
168{
169 int irq;
170
Linus Walleij30a1b5e2013-02-08 23:02:33 +0100171 vic_init(io_p2v(NETX_PA_VIC), NETX_IRQ_VIC_START, ~0, 0);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100172
173 for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100174 irq_set_chip_and_handler(irq, &netx_hif_chip,
175 handle_level_irq);
Rob Herringe8d36d52015-07-27 15:55:13 -0500176 irq_clear_status_flags(irq, IRQ_NOREQUEST);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100177 }
178
179 writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100180 irq_set_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
Sascha Hauerbb6d8c82006-06-19 15:27:53 +0100181}
182
183static int __init netx_init(void)
184{
185 return platform_add_devices(devices, ARRAY_SIZE(devices));
186}
187
188subsys_initcall(netx_init);
189
Robin Holt7b6d8642013-07-08 16:01:40 -0700190void netx_restart(enum reboot_mode mode, const char *cmd)
Russell King8fb06b12011-11-11 15:12:17 +0000191{
192 writel(NETX_SYSTEM_RES_CR_FIRMW_RES_EN | NETX_SYSTEM_RES_CR_FIRMW_RES,
193 NETX_SYSTEM_RES_CR);
194}