Linux 5.7.7
[linux/fpc-iii.git] / arch / arm / mach-ebsa110 / core.c
blob575b2e2b6759f624ddb74e892e6de64fd02b1940
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * linux/arch/arm/mach-ebsa110/core.c
5 * Copyright (C) 1998-2001 Russell King
7 * Extra MM routines for the EBSA-110 architecture
8 */
9 #include <linux/kernel.h>
10 #include <linux/mm.h>
11 #include <linux/interrupt.h>
12 #include <linux/serial_8250.h>
13 #include <linux/init.h>
14 #include <linux/io.h>
16 #include <mach/hardware.h>
17 #include <asm/irq.h>
18 #include <asm/setup.h>
19 #include <asm/mach-types.h>
20 #include <asm/pgtable.h>
21 #include <asm/page.h>
22 #include <asm/system_misc.h>
24 #include <asm/mach/arch.h>
25 #include <asm/mach/irq.h>
26 #include <asm/mach/map.h>
28 #include <asm/mach/time.h>
30 #include "core.h"
32 static void ebsa110_mask_irq(struct irq_data *d)
34 __raw_writeb(1 << d->irq, IRQ_MCLR);
37 static void ebsa110_unmask_irq(struct irq_data *d)
39 __raw_writeb(1 << d->irq, IRQ_MSET);
42 static struct irq_chip ebsa110_irq_chip = {
43 .irq_ack = ebsa110_mask_irq,
44 .irq_mask = ebsa110_mask_irq,
45 .irq_unmask = ebsa110_unmask_irq,
48 static void __init ebsa110_init_irq(void)
50 unsigned long flags;
51 unsigned int irq;
53 local_irq_save(flags);
54 __raw_writeb(0xff, IRQ_MCLR);
55 __raw_writeb(0x55, IRQ_MSET);
56 __raw_writeb(0x00, IRQ_MSET);
57 if (__raw_readb(IRQ_MASK) != 0x55)
58 while (1);
59 __raw_writeb(0xff, IRQ_MCLR); /* clear all interrupt enables */
60 local_irq_restore(flags);
62 for (irq = 0; irq < NR_IRQS; irq++) {
63 irq_set_chip_and_handler(irq, &ebsa110_irq_chip,
64 handle_level_irq);
65 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
69 static struct map_desc ebsa110_io_desc[] __initdata = {
71 * sparse external-decode ISAIO space
73 { /* IRQ_STAT/IRQ_MCLR */
74 .virtual = (unsigned long)IRQ_STAT,
75 .pfn = __phys_to_pfn(TRICK4_PHYS),
76 .length = TRICK4_SIZE,
77 .type = MT_DEVICE
78 }, { /* IRQ_MASK/IRQ_MSET */
79 .virtual = (unsigned long)IRQ_MASK,
80 .pfn = __phys_to_pfn(TRICK3_PHYS),
81 .length = TRICK3_SIZE,
82 .type = MT_DEVICE
83 }, { /* SOFT_BASE */
84 .virtual = (unsigned long)SOFT_BASE,
85 .pfn = __phys_to_pfn(TRICK1_PHYS),
86 .length = TRICK1_SIZE,
87 .type = MT_DEVICE
88 }, { /* PIT_BASE */
89 .virtual = (unsigned long)PIT_BASE,
90 .pfn = __phys_to_pfn(TRICK0_PHYS),
91 .length = TRICK0_SIZE,
92 .type = MT_DEVICE
96 * self-decode ISAIO space
99 .virtual = ISAIO_BASE,
100 .pfn = __phys_to_pfn(ISAIO_PHYS),
101 .length = ISAIO_SIZE,
102 .type = MT_DEVICE
103 }, {
104 .virtual = ISAMEM_BASE,
105 .pfn = __phys_to_pfn(ISAMEM_PHYS),
106 .length = ISAMEM_SIZE,
107 .type = MT_DEVICE
111 static void __init ebsa110_map_io(void)
113 iotable_init(ebsa110_io_desc, ARRAY_SIZE(ebsa110_io_desc));
116 static void __iomem *ebsa110_ioremap_caller(phys_addr_t cookie, size_t size,
117 unsigned int flags, void *caller)
119 return (void __iomem *)cookie;
122 static void ebsa110_iounmap(volatile void __iomem *io_addr)
125 static void __init ebsa110_init_early(void)
127 arch_ioremap_caller = ebsa110_ioremap_caller;
128 arch_iounmap = ebsa110_iounmap;
131 #define PIT_CTRL (PIT_BASE + 0x0d)
132 #define PIT_T2 (PIT_BASE + 0x09)
133 #define PIT_T1 (PIT_BASE + 0x05)
134 #define PIT_T0 (PIT_BASE + 0x01)
137 * This is the rate at which your MCLK signal toggles (in Hz)
138 * This was measured on a 10 digit frequency counter sampling
139 * over 1 second.
141 #define MCLK 47894000
144 * This is the rate at which the PIT timers get clocked
146 #define CLKBY7 (MCLK / 7)
149 * This is the counter value. We tick at 200Hz on this platform.
151 #define COUNT ((CLKBY7 + (HZ / 2)) / HZ)
154 * Get the time offset from the system PIT. Note that if we have missed an
155 * interrupt, then the PIT counter will roll over (ie, be negative).
156 * This actually works out to be convenient.
158 static u32 ebsa110_gettimeoffset(void)
160 unsigned long offset, count;
162 __raw_writeb(0x40, PIT_CTRL);
163 count = __raw_readb(PIT_T1);
164 count |= __raw_readb(PIT_T1) << 8;
167 * If count > COUNT, make the number negative.
169 if (count > COUNT)
170 count |= 0xffff0000;
172 offset = COUNT;
173 offset -= count;
176 * `offset' is in units of timer counts. Convert
177 * offset to units of microseconds.
179 offset = offset * (1000000 / HZ) / COUNT;
181 return offset * 1000;
184 static irqreturn_t
185 ebsa110_timer_interrupt(int irq, void *dev_id)
187 u32 count;
189 /* latch and read timer 1 */
190 __raw_writeb(0x40, PIT_CTRL);
191 count = __raw_readb(PIT_T1);
192 count |= __raw_readb(PIT_T1) << 8;
194 count += COUNT;
196 __raw_writeb(count & 0xff, PIT_T1);
197 __raw_writeb(count >> 8, PIT_T1);
199 timer_tick();
201 return IRQ_HANDLED;
205 * Set up timer interrupt.
207 void __init ebsa110_timer_init(void)
209 int irq = IRQ_EBSA110_TIMER0;
211 arch_gettimeoffset = ebsa110_gettimeoffset;
214 * Timer 1, mode 2, LSB/MSB
216 __raw_writeb(0x70, PIT_CTRL);
217 __raw_writeb(COUNT & 0xff, PIT_T1);
218 __raw_writeb(COUNT >> 8, PIT_T1);
220 if (request_irq(irq, ebsa110_timer_interrupt, IRQF_TIMER | IRQF_IRQPOLL,
221 "EBSA110 Timer Tick", NULL))
222 pr_err("Failed to request irq %d (EBSA110 Timer Tick)\n", irq);
225 static struct plat_serial8250_port serial_platform_data[] = {
227 .iobase = 0x3f8,
228 .irq = 1,
229 .uartclk = 1843200,
230 .regshift = 0,
231 .iotype = UPIO_PORT,
232 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
235 .iobase = 0x2f8,
236 .irq = 2,
237 .uartclk = 1843200,
238 .regshift = 0,
239 .iotype = UPIO_PORT,
240 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
242 { },
245 static struct platform_device serial_device = {
246 .name = "serial8250",
247 .id = PLAT8250_DEV_PLATFORM,
248 .dev = {
249 .platform_data = serial_platform_data,
253 static struct resource am79c961_resources[] = {
255 .start = 0x220,
256 .end = 0x238,
257 .flags = IORESOURCE_IO,
258 }, {
259 .start = IRQ_EBSA110_ETHERNET,
260 .end = IRQ_EBSA110_ETHERNET,
261 .flags = IORESOURCE_IRQ,
265 static struct platform_device am79c961_device = {
266 .name = "am79c961",
267 .id = -1,
268 .num_resources = ARRAY_SIZE(am79c961_resources),
269 .resource = am79c961_resources,
272 static struct platform_device *ebsa110_devices[] = {
273 &serial_device,
274 &am79c961_device,
278 * EBSA110 idling methodology:
280 * We can not execute the "wait for interrupt" instruction since that
281 * will stop our MCLK signal (which provides the clock for the glue
282 * logic, and therefore the timer interrupt).
284 * Instead, we spin, polling the IRQ_STAT register for the occurrence
285 * of any interrupt with core clock down to the memory clock.
287 static void ebsa110_idle(void)
289 const char *irq_stat = (char *)0xff000000;
291 /* disable clock switching */
292 asm volatile ("mcr p15, 0, ip, c15, c2, 2" : : : "cc");
294 /* wait for an interrupt to occur */
295 while (!*irq_stat);
297 /* enable clock switching */
298 asm volatile ("mcr p15, 0, ip, c15, c1, 2" : : : "cc");
301 static int __init ebsa110_init(void)
303 arm_pm_idle = ebsa110_idle;
304 return platform_add_devices(ebsa110_devices, ARRAY_SIZE(ebsa110_devices));
307 arch_initcall(ebsa110_init);
309 static void ebsa110_restart(enum reboot_mode mode, const char *cmd)
311 soft_restart(0x80000000);
314 MACHINE_START(EBSA110, "EBSA110")
315 /* Maintainer: Russell King */
316 .atag_offset = 0x400,
317 .reserve_lp0 = 1,
318 .reserve_lp2 = 1,
319 .map_io = ebsa110_map_io,
320 .init_early = ebsa110_init_early,
321 .init_irq = ebsa110_init_irq,
322 .init_time = ebsa110_timer_init,
323 .restart = ebsa110_restart,
324 MACHINE_END