2
* linux/arch/arm/mach-aaec2000/core.c
4
* Code common to all AAEC-2000 machines
6
* Copyright (c) 2005 Nicolas Bellido Y Ortega
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 2 as
10
* published by the Free Software Foundation.
12
#include <linux/module.h>
13
#include <linux/kernel.h>
14
#include <linux/init.h>
15
#include <linux/platform_device.h>
16
#include <linux/list.h>
17
#include <linux/errno.h>
18
#include <linux/dma-mapping.h>
19
#include <linux/interrupt.h>
20
#include <linux/timex.h>
21
#include <linux/signal.h>
22
#include <linux/clk.h>
23
#include <linux/gfp.h>
25
#include <mach/hardware.h>
27
#include <asm/sizes.h>
29
#include <asm/mach/flash.h>
30
#include <asm/mach/irq.h>
31
#include <asm/mach/time.h>
32
#include <asm/mach/map.h>
39
* Static virtual address mappings are as follow:
41
* 0xf8000000-0xf8001ffff: Devices connected to APB bus
42
* 0xf8002000-0xf8003ffff: Devices connected to AHB bus
44
* Below 0xe8000000 is reserved for vm allocation.
46
* The machine specific code must provide the extra mapping beside the
47
* default mapping provided here.
49
static struct map_desc standard_io_desc[] __initdata = {
51
.virtual = VIO_APB_BASE,
52
.pfn = __phys_to_pfn(PIO_APB_BASE),
53
.length = IO_APB_LENGTH,
56
.virtual = VIO_AHB_BASE,
57
.pfn = __phys_to_pfn(PIO_AHB_BASE),
58
.length = IO_AHB_LENGTH,
63
void __init aaec2000_map_io(void)
65
iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
69
* Interrupt handling routines
71
static void aaec2000_int_ack(struct irq_data *d)
73
IRQ_INTSR = 1 << d->irq;
76
static void aaec2000_int_mask(struct irq_data *d)
78
IRQ_INTENC |= (1 << d->irq);
81
static void aaec2000_int_unmask(struct irq_data *d)
83
IRQ_INTENS |= (1 << d->irq);
86
static struct irq_chip aaec2000_irq_chip = {
87
.irq_ack = aaec2000_int_ack,
88
.irq_mask = aaec2000_int_mask,
89
.irq_unmask = aaec2000_int_unmask,
92
void __init aaec2000_init_irq(void)
96
for (i = 0; i < NR_IRQS; i++) {
97
set_irq_handler(i, handle_level_irq);
98
set_irq_chip(i, &aaec2000_irq_chip);
99
set_irq_flags(i, IRQF_VALID);
102
/* Disable all interrupts */
103
IRQ_INTENC = 0xffffffff;
105
/* Clear any pending interrupts */
106
IRQ_INTSR = IRQ_INTSR;
112
/* IRQs are disabled before entering here from do_gettimeofday() */
113
static unsigned long aaec2000_gettimeoffset(void)
115
unsigned long ticks_to_match, elapsed, usec;
117
/* Get ticks before next timer match */
118
ticks_to_match = TIMER1_LOAD - TIMER1_VAL;
120
/* We need elapsed ticks since last match */
121
elapsed = LATCH - ticks_to_match;
123
/* Now, convert them to usec */
124
usec = (unsigned long)(elapsed * (tick_nsec / 1000))/LATCH;
129
/* We enter here with IRQs enabled */
131
aaec2000_timer_interrupt(int irq, void *dev_id)
133
/* TODO: Check timer accuracy */
140
static struct irqaction aaec2000_timer_irq = {
141
.name = "AAEC-2000 Timer Tick",
142
.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
143
.handler = aaec2000_timer_interrupt,
146
static void __init aaec2000_timer_init(void)
148
/* Disable timer 1 */
151
/* We have somehow to generate a 100Hz clock.
152
* We then use the 508KHz timer in periodic mode.
155
TIMER1_CLEAR = 1; /* Clear interrupt */
157
setup_irq(INT_TMR1_OFL, &aaec2000_timer_irq);
159
TIMER1_CTRL = TIMER_CTRL_ENABLE |
160
TIMER_CTRL_PERIODIC |
161
TIMER_CTRL_CLKSEL_508K;
164
struct sys_timer aaec2000_timer = {
165
.init = aaec2000_timer_init,
166
.offset = aaec2000_gettimeoffset,
169
static struct clcd_panel mach_clcd_panel;
171
static int aaec2000_clcd_setup(struct clcd_fb *fb)
175
fb->panel = &mach_clcd_panel;
177
fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, SZ_1M,
180
if (!fb->fb.screen_base) {
181
printk(KERN_ERR "CLCD: unable to map framebuffer\n");
185
fb->fb.fix.smem_start = dma;
186
fb->fb.fix.smem_len = SZ_1M;
191
static int aaec2000_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
193
return dma_mmap_writecombine(&fb->dev->dev, vma,
195
fb->fb.fix.smem_start,
196
fb->fb.fix.smem_len);
199
static void aaec2000_clcd_remove(struct clcd_fb *fb)
201
dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
202
fb->fb.screen_base, fb->fb.fix.smem_start);
205
static struct clcd_board clcd_plat_data = {
207
.check = clcdfb_check,
208
.decode = clcdfb_decode,
209
.setup = aaec2000_clcd_setup,
210
.mmap = aaec2000_clcd_mmap,
211
.remove = aaec2000_clcd_remove,
214
static struct amba_device clcd_device = {
216
.init_name = "mb:16",
217
.coherent_dma_mask = ~0,
218
.platform_data = &clcd_plat_data,
221
.start = AAEC_CLCD_PHYS,
222
.end = AAEC_CLCD_PHYS + SZ_4K - 1,
223
.flags = IORESOURCE_MEM,
225
.irq = { INT_LCD, NO_IRQ },
229
static struct amba_device *amba_devs[] __initdata = {
233
void clk_disable(struct clk *clk)
237
int clk_set_rate(struct clk *clk, unsigned long rate)
242
int clk_enable(struct clk *clk)
247
struct clk *clk_get(struct device *dev, const char *id)
249
return dev && strcmp(dev_name(dev), "mb:16") == 0 ? NULL : ERR_PTR(-ENOENT);
252
void clk_put(struct clk *clk)
256
void __init aaec2000_set_clcd_plat_data(struct aaec2000_clcd_info *clcd)
258
clcd_plat_data.enable = clcd->enable;
259
clcd_plat_data.disable = clcd->disable;
260
memcpy(&mach_clcd_panel, &clcd->panel, sizeof(struct clcd_panel));
263
static struct flash_platform_data aaec2000_flash_data = {
264
.map_name = "cfi_probe",
268
static struct resource aaec2000_flash_resource = {
269
.start = AAEC_FLASH_BASE,
270
.end = AAEC_FLASH_BASE + AAEC_FLASH_SIZE,
271
.flags = IORESOURCE_MEM,
274
static struct platform_device aaec2000_flash_device = {
278
.platform_data = &aaec2000_flash_data,
281
.resource = &aaec2000_flash_resource,
284
static int __init aaec2000_init(void)
288
for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
289
struct amba_device *d = amba_devs[i];
290
amba_device_register(d, &iomem_resource);
293
platform_device_register(&aaec2000_flash_device);
297
arch_initcall(aaec2000_init);