generic.c 4.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * arch/arm/mach-netx/generic.c
 *
 * Copyright (C) 2005 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <linux/device.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
25
#include <linux/io.h>
26
#include <mach/hardware.h>
27 28
#include <asm/mach/map.h>
#include <asm/hardware/vic.h>
29
#include <mach/netx-regs.h>
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#include <asm/mach/irq.h>

static struct map_desc netx_io_desc[] __initdata = {
	{
		.virtual        = NETX_IO_VIRT,
		.pfn            = __phys_to_pfn(NETX_IO_PHYS),
		.length         = NETX_IO_SIZE,
		.type           = MT_DEVICE
	}
};

void __init netx_map_io(void)
{
	iotable_init(netx_io_desc, ARRAY_SIZE(netx_io_desc));
}

static struct resource netx_rtc_resources[] = {
	[0] = {
		.start	= 0x00101200,
		.end	= 0x00101220,
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device netx_rtc_device = {
	.name		= "netx-rtc",
	.id		= 0,
	.num_resources	= ARRAY_SIZE(netx_rtc_resources),
	.resource	= netx_rtc_resources,
};

static struct platform_device *devices[] __initdata = {
	&netx_rtc_device,
};

#if 0
#define DEBUG_IRQ(fmt...)	printk(fmt)
#else
#define DEBUG_IRQ(fmt...)	while (0) {}
#endif

static void
72
netx_hif_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
73 74 75 76 77 78 79 80 81 82
{
	unsigned int irq = NETX_IRQ_HIF_CHAINED(0);
	unsigned int stat;

	stat = ((readl(NETX_DPMAS_INT_EN) &
		readl(NETX_DPMAS_INT_STAT)) >> 24) & 0x1f;

	while (stat) {
		if (stat & 1) {
			DEBUG_IRQ("handling irq %d\n", irq);
83
			generic_handle_irq(irq);
84 85 86 87 88 89 90
		}
		irq++;
		stat >>= 1;
	}
}

static int
91
netx_hif_irq_type(struct irq_data *d, unsigned int type)
92 93 94 95 96
{
	unsigned int val, irq;

	val = readl(NETX_DPMAS_IF_CONF1);

97
	irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
98

99
	if (type & IRQ_TYPE_EDGE_RISING) {
100 101 102
		DEBUG_IRQ("rising edges\n");
		val |= (1 << 26) << irq;
	}
103
	if (type & IRQ_TYPE_EDGE_FALLING) {
104 105 106
		DEBUG_IRQ("falling edges\n");
		val &= ~((1 << 26) << irq);
	}
107
	if (type & IRQ_TYPE_LEVEL_LOW) {
108 109 110
		DEBUG_IRQ("low level\n");
		val &= ~((1 << 26) << irq);
	}
111
	if (type & IRQ_TYPE_LEVEL_HIGH) {
112 113 114 115 116 117 118 119 120 121
		DEBUG_IRQ("high level\n");
		val |= (1 << 26) << irq;
	}

	writel(val, NETX_DPMAS_IF_CONF1);

	return 0;
}

static void
122
netx_hif_ack_irq(struct irq_data *d)
123 124 125
{
	unsigned int val, irq;

126
	irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
127 128 129 130 131 132
	writel((1 << 24) << irq, NETX_DPMAS_INT_STAT);

	val = readl(NETX_DPMAS_INT_EN);
	val &= ~((1 << 24) << irq);
	writel(val, NETX_DPMAS_INT_EN);

133
	DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
134 135 136
}

static void
137
netx_hif_mask_irq(struct irq_data *d)
138 139 140
{
	unsigned int val, irq;

141
	irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
142 143 144
	val = readl(NETX_DPMAS_INT_EN);
	val &= ~((1 << 24) << irq);
	writel(val, NETX_DPMAS_INT_EN);
145
	DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
146 147 148
}

static void
149
netx_hif_unmask_irq(struct irq_data *d)
150 151 152
{
	unsigned int val, irq;

153
	irq = d->irq - NETX_IRQ_HIF_CHAINED(0);
154 155 156
	val = readl(NETX_DPMAS_INT_EN);
	val |= (1 << 24) << irq;
	writel(val, NETX_DPMAS_INT_EN);
157
	DEBUG_IRQ("%s: irq %d\n", __func__, d->irq);
158 159
}

160
static struct irq_chip netx_hif_chip = {
161 162 163 164
	.irq_ack = netx_hif_ack_irq,
	.irq_mask = netx_hif_mask_irq,
	.irq_unmask = netx_hif_unmask_irq,
	.irq_set_type = netx_hif_irq_type,
165 166 167 168 169 170
};

void __init netx_init_irq(void)
{
	int irq;

R
Rob Herring 已提交
171
	vic_init(io_p2v(NETX_PA_VIC), 0, ~0, 0);
172 173

	for (irq = NETX_IRQ_HIF_CHAINED(0); irq <= NETX_IRQ_HIF_LAST; irq++) {
174 175
		irq_set_chip_and_handler(irq, &netx_hif_chip,
					 handle_level_irq);
176 177 178 179
		set_irq_flags(irq, IRQF_VALID);
	}

	writel(NETX_DPMAS_INT_EN_GLB_EN, NETX_DPMAS_INT_EN);
T
Thomas Gleixner 已提交
180
	irq_set_chained_handler(NETX_IRQ_HIF, netx_hif_demux_handler);
181 182 183 184 185 186 187 188 189
}

static int __init netx_init(void)
{
	return platform_add_devices(devices, ARRAY_SIZE(devices));
}

subsys_initcall(netx_init);

190 191 192 193 194
void netx_restart(char mode, const char *cmd)
{
	writel(NETX_SYSTEM_RES_CR_FIRMW_RES_EN | NETX_SYSTEM_RES_CR_FIRMW_RES,
	       NETX_SYSTEM_RES_CR);
}