core.c 7.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *  linux/arch/arm/mach-ebsa110/core.c
 *
 *  Copyright (C) 1998-2001 Russell King
 *
 * 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.
 *
 *  Extra MM routines for the EBSA-110 architecture
 */
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/serial_8250.h>
#include <linux/init.h>
17
#include <linux/io.h>
L
Linus Torvalds 已提交
18

19
#include <mach/hardware.h>
L
Linus Torvalds 已提交
20 21 22 23 24
#include <asm/irq.h>
#include <asm/setup.h>
#include <asm/mach-types.h>
#include <asm/pgtable.h>
#include <asm/page.h>
25
#include <asm/system_misc.h>
L
Linus Torvalds 已提交
26 27 28 29 30 31 32

#include <asm/mach/arch.h>
#include <asm/mach/irq.h>
#include <asm/mach/map.h>

#include <asm/mach/time.h>

33
#include "core.h"
L
Linus Torvalds 已提交
34

35
static void ebsa110_mask_irq(struct irq_data *d)
L
Linus Torvalds 已提交
36
{
37
	__raw_writeb(1 << d->irq, IRQ_MCLR);
L
Linus Torvalds 已提交
38 39
}

40
static void ebsa110_unmask_irq(struct irq_data *d)
L
Linus Torvalds 已提交
41
{
42
	__raw_writeb(1 << d->irq, IRQ_MSET);
L
Linus Torvalds 已提交
43 44
}

45
static struct irq_chip ebsa110_irq_chip = {
46 47 48
	.irq_ack	= ebsa110_mask_irq,
	.irq_mask	= ebsa110_mask_irq,
	.irq_unmask	= ebsa110_unmask_irq,
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
};
 
static void __init ebsa110_init_irq(void)
{
	unsigned long flags;
	unsigned int irq;

	local_irq_save(flags);
	__raw_writeb(0xff, IRQ_MCLR);
	__raw_writeb(0x55, IRQ_MSET);
	__raw_writeb(0x00, IRQ_MSET);
	if (__raw_readb(IRQ_MASK) != 0x55)
		while (1);
	__raw_writeb(0xff, IRQ_MCLR);	/* clear all interrupt enables */
	local_irq_restore(flags);

	for (irq = 0; irq < NR_IRQS; irq++) {
66 67
		irq_set_chip_and_handler(irq, &ebsa110_irq_chip,
					 handle_level_irq);
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75
		set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
	}
}

static struct map_desc ebsa110_io_desc[] __initdata = {
	/*
	 * sparse external-decode ISAIO space
	 */
76 77 78
	{	/* IRQ_STAT/IRQ_MCLR */
		.virtual	= IRQ_STAT,
		.pfn		= __phys_to_pfn(TRICK4_PHYS),
79
		.length		= TRICK4_SIZE,
80 81 82 83
		.type		= MT_DEVICE
	}, {	/* IRQ_MASK/IRQ_MSET */
		.virtual	= IRQ_MASK,
		.pfn		= __phys_to_pfn(TRICK3_PHYS),
84
		.length		= TRICK3_SIZE,
85 86 87 88
		.type		= MT_DEVICE
	}, {	/* SOFT_BASE */
		.virtual	= SOFT_BASE,
		.pfn		= __phys_to_pfn(TRICK1_PHYS),
89
		.length		= TRICK1_SIZE,
90 91 92 93
		.type		= MT_DEVICE
	}, {	/* PIT_BASE */
		.virtual	= PIT_BASE,
		.pfn		= __phys_to_pfn(TRICK0_PHYS),
94
		.length		= TRICK0_SIZE,
95 96
		.type		= MT_DEVICE
	},
L
Linus Torvalds 已提交
97 98 99 100

	/*
	 * self-decode ISAIO space
	 */
101 102 103 104 105 106 107 108 109 110 111
	{
		.virtual	= ISAIO_BASE,
		.pfn		= __phys_to_pfn(ISAIO_PHYS),
		.length		= ISAIO_SIZE,
		.type		= MT_DEVICE
	}, {
		.virtual	= ISAMEM_BASE,
		.pfn		= __phys_to_pfn(ISAMEM_PHYS),
		.length		= ISAMEM_SIZE,
		.type		= MT_DEVICE
	}
L
Linus Torvalds 已提交
112 113 114 115 116 117 118
};

static void __init ebsa110_map_io(void)
{
	iotable_init(ebsa110_io_desc, ARRAY_SIZE(ebsa110_io_desc));
}

119 120 121 122 123 124 125 126 127 128 129 130 131 132
static void __iomem *ebsa110_ioremap_caller(unsigned long cookie, size_t size,
					    unsigned int flags, void *caller)
{
	return (void __iomem *)cookie;
}

static void ebsa110_iounmap(volatile void __iomem *io_addr)
{}

static void __init ebsa110_init_early(void)
{
	arch_ioremap_caller = ebsa110_ioremap_caller;
	arch_iounmap = ebsa110_iounmap;
}
L
Linus Torvalds 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

#define PIT_CTRL		(PIT_BASE + 0x0d)
#define PIT_T2			(PIT_BASE + 0x09)
#define PIT_T1			(PIT_BASE + 0x05)
#define PIT_T0			(PIT_BASE + 0x01)

/*
 * This is the rate at which your MCLK signal toggles (in Hz)
 * This was measured on a 10 digit frequency counter sampling
 * over 1 second.
 */
#define MCLK	47894000

/*
 * This is the rate at which the PIT timers get clocked
 */
#define CLKBY7	(MCLK / 7)

/*
 * This is the counter value.  We tick at 200Hz on this platform.
 */
#define COUNT	((CLKBY7 + (HZ / 2)) / HZ)

/*
 * Get the time offset from the system PIT.  Note that if we have missed an
 * interrupt, then the PIT counter will roll over (ie, be negative).
 * This actually works out to be convenient.
 */
static unsigned long ebsa110_gettimeoffset(void)
{
	unsigned long offset, count;

	__raw_writeb(0x40, PIT_CTRL);
	count = __raw_readb(PIT_T1);
	count |= __raw_readb(PIT_T1) << 8;

	/*
	 * If count > COUNT, make the number negative.
	 */
	if (count > COUNT)
		count |= 0xffff0000;

	offset = COUNT;
	offset -= count;

	/*
	 * `offset' is in units of timer counts.  Convert
	 * offset to units of microseconds.
	 */
	offset = offset * (1000000 / HZ) / COUNT;

	return offset;
}

static irqreturn_t
188
ebsa110_timer_interrupt(int irq, void *dev_id)
L
Linus Torvalds 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201
{
	u32 count;

	/* latch and read timer 1 */
	__raw_writeb(0x40, PIT_CTRL);
	count = __raw_readb(PIT_T1);
	count |= __raw_readb(PIT_T1) << 8;

	count += COUNT;

	__raw_writeb(count & 0xff, PIT_T1);
	__raw_writeb(count >> 8, PIT_T1);

202
	timer_tick();
L
Linus Torvalds 已提交
203 204 205 206 207 208

	return IRQ_HANDLED;
}

static struct irqaction ebsa110_timer_irq = {
	.name		= "EBSA110 Timer Tick",
B
Bernhard Walle 已提交
209
	.flags		= IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
210
	.handler	= ebsa110_timer_interrupt,
L
Linus Torvalds 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
};

/*
 * Set up timer interrupt.
 */
static void __init ebsa110_timer_init(void)
{
	/*
	 * Timer 1, mode 2, LSB/MSB
	 */
	__raw_writeb(0x70, PIT_CTRL);
	__raw_writeb(COUNT & 0xff, PIT_T1);
	__raw_writeb(COUNT >> 8, PIT_T1);

	setup_irq(IRQ_EBSA110_TIMER0, &ebsa110_timer_irq);
}

static struct sys_timer ebsa110_timer = {
	.init		= ebsa110_timer_init,
	.offset		= ebsa110_gettimeoffset,
};

static struct plat_serial8250_port serial_platform_data[] = {
	{
		.iobase		= 0x3f8,
		.irq		= 1,
		.uartclk	= 1843200,
		.regshift	= 0,
		.iotype		= UPIO_PORT,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
	},
	{
		.iobase		= 0x2f8,
		.irq		= 2,
		.uartclk	= 1843200,
		.regshift	= 0,
		.iotype		= UPIO_PORT,
		.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
	},
	{ },
};

static struct platform_device serial_device = {
	.name			= "serial8250",
255
	.id			= PLAT8250_DEV_PLATFORM,
L
Linus Torvalds 已提交
256 257 258 259 260
	.dev			= {
		.platform_data	= serial_platform_data,
	},
};

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
static struct resource am79c961_resources[] = {
	{
		.start		= 0x220,
		.end		= 0x238,
		.flags		= IORESOURCE_IO,
	}, {
		.start		= IRQ_EBSA110_ETHERNET,
		.end		= IRQ_EBSA110_ETHERNET,
		.flags		= IORESOURCE_IRQ,
	},
};

static struct platform_device am79c961_device = {
	.name			= "am79c961",
	.id			= -1,
	.num_resources		= ARRAY_SIZE(am79c961_resources),
	.resource		= am79c961_resources,
};

static struct platform_device *ebsa110_devices[] = {
	&serial_device,
	&am79c961_device,
};

285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
/*
 * EBSA110 idling methodology:
 *
 * We can not execute the "wait for interrupt" instruction since that
 * will stop our MCLK signal (which provides the clock for the glue
 * logic, and therefore the timer interrupt).
 *
 * Instead, we spin, polling the IRQ_STAT register for the occurrence
 * of any interrupt with core clock down to the memory clock.
 */
static void ebsa110_idle(void)
{
	const char *irq_stat = (char *)0xff000000;

	/* disable clock switching */
	asm volatile ("mcr p15, 0, ip, c15, c2, 2" : : : "cc");

	/* wait for an interrupt to occur */
	while (!*irq_stat);

	/* enable clock switching */
	asm volatile ("mcr p15, 0, ip, c15, c1, 2" : : : "cc");
}

L
Linus Torvalds 已提交
309 310
static int __init ebsa110_init(void)
{
311
	arm_pm_idle = ebsa110_idle;
312
	return platform_add_devices(ebsa110_devices, ARRAY_SIZE(ebsa110_devices));
L
Linus Torvalds 已提交
313 314 315 316
}

arch_initcall(ebsa110_init);

317 318 319 320 321
static void ebsa110_restart(char mode, const char *cmd)
{
	soft_restart(0x80000000);
}

L
Linus Torvalds 已提交
322
MACHINE_START(EBSA110, "EBSA110")
323
	/* Maintainer: Russell King */
324
	.atag_offset	= 0x400,
325 326
	.reserve_lp0	= 1,
	.reserve_lp2	= 1,
327
	.restart_mode	= 's',
328
	.map_io		= ebsa110_map_io,
329
	.init_early	= ebsa110_init_early,
330
	.init_irq	= ebsa110_init_irq,
L
Linus Torvalds 已提交
331
	.timer		= &ebsa110_timer,
332
	.restart	= ebsa110_restart,
L
Linus Torvalds 已提交
333
MACHINE_END