blob: 3ef68330452a7e9037bb9314362130046cead895 [file] [log] [blame]
Bellido Nicolas038c5b62005-06-20 18:51:05 +01001/*
2 * linux/arch/arm/mach-aaec2000/core.c
3 *
4 * Code common to all AAEC-2000 machines
5 *
6 * Copyright (c) 2005 Nicolas Bellido Y Ortega
7 *
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.
11 */
Bellido Nicolas038c5b62005-06-20 18:51:05 +010012#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010015#include <linux/platform_device.h>
Bellido Nicolas038c5b62005-06-20 18:51:05 +010016#include <linux/list.h>
17#include <linux/errno.h>
Bellido Nicolas049eb322005-10-28 16:51:44 +010018#include <linux/dma-mapping.h>
Bellido Nicolas038c5b62005-06-20 18:51:05 +010019#include <linux/interrupt.h>
20#include <linux/timex.h>
21#include <linux/signal.h>
Russell King4ab08ec2008-11-30 17:27:20 +000022#include <linux/clk.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/gfp.h>
Bellido Nicolas038c5b62005-06-20 18:51:05 +010024
Russell Kinga09e64f2008-08-05 16:14:15 +010025#include <mach/hardware.h>
Bellido Nicolas038c5b62005-06-20 18:51:05 +010026#include <asm/irq.h>
Bellido Nicolas049eb322005-10-28 16:51:44 +010027#include <asm/sizes.h>
Bellido Nicolas038c5b62005-06-20 18:51:05 +010028
Bellido Nicolas4a91ca22005-10-28 16:51:42 +010029#include <asm/mach/flash.h>
Bellido Nicolas038c5b62005-06-20 18:51:05 +010030#include <asm/mach/irq.h>
31#include <asm/mach/time.h>
32#include <asm/mach/map.h>
33
Bellido Nicolas049eb322005-10-28 16:51:44 +010034#include "core.h"
Bellido Nicolas049eb322005-10-28 16:51:44 +010035
Bellido Nicolas038c5b62005-06-20 18:51:05 +010036/*
37 * Common I/O mapping:
38 *
39 * Static virtual address mappings are as follow:
40 *
41 * 0xf8000000-0xf8001ffff: Devices connected to APB bus
42 * 0xf8002000-0xf8003ffff: Devices connected to AHB bus
43 *
44 * Below 0xe8000000 is reserved for vm allocation.
45 *
46 * The machine specific code must provide the extra mapping beside the
47 * default mapping provided here.
48 */
49static struct map_desc standard_io_desc[] __initdata = {
Deepak Saxenaf70cd652005-10-28 15:18:56 +010050 {
51 .virtual = VIO_APB_BASE,
Bellido Nicolas16b6dd42006-05-07 22:49:21 +010052 .pfn = __phys_to_pfn(PIO_APB_BASE),
Deepak Saxenaf70cd652005-10-28 15:18:56 +010053 .length = IO_APB_LENGTH,
54 .type = MT_DEVICE
55 }, {
56 .virtual = VIO_AHB_BASE,
Bellido Nicolas16b6dd42006-05-07 22:49:21 +010057 .pfn = __phys_to_pfn(PIO_AHB_BASE),
Deepak Saxenaf70cd652005-10-28 15:18:56 +010058 .length = IO_AHB_LENGTH,
59 .type = MT_DEVICE
60 }
Bellido Nicolas038c5b62005-06-20 18:51:05 +010061};
62
63void __init aaec2000_map_io(void)
64{
65 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
66}
67
68/*
69 * Interrupt handling routines
70 */
71static void aaec2000_int_ack(unsigned int irq)
72{
73 IRQ_INTSR = 1 << irq;
74}
75
76static void aaec2000_int_mask(unsigned int irq)
77{
78 IRQ_INTENC |= (1 << irq);
79}
80
81static void aaec2000_int_unmask(unsigned int irq)
82{
83 IRQ_INTENS |= (1 << irq);
84}
85
Russell King10dd5ce2006-11-23 11:41:32 +000086static struct irq_chip aaec2000_irq_chip = {
Bellido Nicolas038c5b62005-06-20 18:51:05 +010087 .ack = aaec2000_int_ack,
88 .mask = aaec2000_int_mask,
89 .unmask = aaec2000_int_unmask,
90};
91
92void __init aaec2000_init_irq(void)
93{
94 unsigned int i;
95
96 for (i = 0; i < NR_IRQS; i++) {
Russell King10dd5ce2006-11-23 11:41:32 +000097 set_irq_handler(i, handle_level_irq);
Bellido Nicolas038c5b62005-06-20 18:51:05 +010098 set_irq_chip(i, &aaec2000_irq_chip);
99 set_irq_flags(i, IRQF_VALID);
100 }
101
102 /* Disable all interrupts */
103 IRQ_INTENC = 0xffffffff;
104
105 /* Clear any pending interrupts */
106 IRQ_INTSR = IRQ_INTSR;
107}
108
109/*
110 * Time keeping
111 */
112/* IRQs are disabled before entering here from do_gettimeofday() */
113static unsigned long aaec2000_gettimeoffset(void)
114{
115 unsigned long ticks_to_match, elapsed, usec;
116
117 /* Get ticks before next timer match */
118 ticks_to_match = TIMER1_LOAD - TIMER1_VAL;
119
120 /* We need elapsed ticks since last match */
121 elapsed = LATCH - ticks_to_match;
122
123 /* Now, convert them to usec */
124 usec = (unsigned long)(elapsed * (tick_nsec / 1000))/LATCH;
125
126 return usec;
127}
128
129/* We enter here with IRQs enabled */
130static irqreturn_t
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700131aaec2000_timer_interrupt(int irq, void *dev_id)
Bellido Nicolas038c5b62005-06-20 18:51:05 +0100132{
133 /* TODO: Check timer accuracy */
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700134 timer_tick();
Bellido Nicolas038c5b62005-06-20 18:51:05 +0100135 TIMER1_CLEAR = 1;
136
Bellido Nicolas038c5b62005-06-20 18:51:05 +0100137 return IRQ_HANDLED;
138}
139
140static struct irqaction aaec2000_timer_irq = {
141 .name = "AAEC-2000 Timer Tick",
Bernhard Walleb30faba2007-05-08 00:35:39 -0700142 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
Russell King09b8b5f2005-06-26 17:06:36 +0100143 .handler = aaec2000_timer_interrupt,
Bellido Nicolas038c5b62005-06-20 18:51:05 +0100144};
145
146static void __init aaec2000_timer_init(void)
147{
148 /* Disable timer 1 */
149 TIMER1_CTRL = 0;
150
151 /* We have somehow to generate a 100Hz clock.
152 * We then use the 508KHz timer in periodic mode.
153 */
154 TIMER1_LOAD = LATCH;
155 TIMER1_CLEAR = 1; /* Clear interrupt */
156
157 setup_irq(INT_TMR1_OFL, &aaec2000_timer_irq);
158
159 TIMER1_CTRL = TIMER_CTRL_ENABLE |
160 TIMER_CTRL_PERIODIC |
161 TIMER_CTRL_CLKSEL_508K;
162}
163
164struct sys_timer aaec2000_timer = {
165 .init = aaec2000_timer_init,
166 .offset = aaec2000_gettimeoffset,
167};
168
Bellido Nicolas049eb322005-10-28 16:51:44 +0100169static struct clcd_panel mach_clcd_panel;
170
171static int aaec2000_clcd_setup(struct clcd_fb *fb)
172{
173 dma_addr_t dma;
174
175 fb->panel = &mach_clcd_panel;
176
177 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, SZ_1M,
178 &dma, GFP_KERNEL);
179
180 if (!fb->fb.screen_base) {
181 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
182 return -ENOMEM;
183 }
184
185 fb->fb.fix.smem_start = dma;
186 fb->fb.fix.smem_len = SZ_1M;
187
188 return 0;
189}
190
191static int aaec2000_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
192{
193 return dma_mmap_writecombine(&fb->dev->dev, vma,
194 fb->fb.screen_base,
195 fb->fb.fix.smem_start,
196 fb->fb.fix.smem_len);
197}
198
199static void aaec2000_clcd_remove(struct clcd_fb *fb)
200{
201 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
202 fb->fb.screen_base, fb->fb.fix.smem_start);
203}
204
205static struct clcd_board clcd_plat_data = {
206 .name = "AAEC-2000",
207 .check = clcdfb_check,
208 .decode = clcdfb_decode,
209 .setup = aaec2000_clcd_setup,
210 .mmap = aaec2000_clcd_mmap,
211 .remove = aaec2000_clcd_remove,
212};
213
214static struct amba_device clcd_device = {
215 .dev = {
Kay Sievers1d559e22009-01-06 10:44:43 -0800216 .init_name = "mb:16",
Bellido Nicolas049eb322005-10-28 16:51:44 +0100217 .coherent_dma_mask = ~0,
218 .platform_data = &clcd_plat_data,
219 },
220 .res = {
221 .start = AAEC_CLCD_PHYS,
222 .end = AAEC_CLCD_PHYS + SZ_4K - 1,
223 .flags = IORESOURCE_MEM,
224 },
225 .irq = { INT_LCD, NO_IRQ },
226 .periphid = 0x41110,
227};
228
229static struct amba_device *amba_devs[] __initdata = {
230 &clcd_device,
231};
232
Russell King4ab08ec2008-11-30 17:27:20 +0000233void clk_disable(struct clk *clk)
234{
235}
236
237int clk_set_rate(struct clk *clk, unsigned long rate)
238{
239 return 0;
240}
241
242int clk_enable(struct clk *clk)
243{
244 return 0;
245}
246
247struct clk *clk_get(struct device *dev, const char *id)
248{
249 return dev && strcmp(dev_name(dev), "mb:16") == 0 ? NULL : ERR_PTR(-ENOENT);
250}
251
252void clk_put(struct clk *clk)
253{
254}
Bellido Nicolas049eb322005-10-28 16:51:44 +0100255
256void __init aaec2000_set_clcd_plat_data(struct aaec2000_clcd_info *clcd)
257{
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));
261}
262
Bellido Nicolas4a91ca22005-10-28 16:51:42 +0100263static struct flash_platform_data aaec2000_flash_data = {
264 .map_name = "cfi_probe",
265 .width = 4,
266};
267
268static struct resource aaec2000_flash_resource = {
269 .start = AAEC_FLASH_BASE,
270 .end = AAEC_FLASH_BASE + AAEC_FLASH_SIZE,
271 .flags = IORESOURCE_MEM,
272};
273
274static struct platform_device aaec2000_flash_device = {
275 .name = "armflash",
276 .id = 0,
277 .dev = {
278 .platform_data = &aaec2000_flash_data,
279 },
280 .num_resources = 1,
281 .resource = &aaec2000_flash_resource,
282};
283
284static int __init aaec2000_init(void)
285{
Bellido Nicolas049eb322005-10-28 16:51:44 +0100286 int i;
287
Bellido Nicolas049eb322005-10-28 16:51:44 +0100288 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
289 struct amba_device *d = amba_devs[i];
290 amba_device_register(d, &iomem_resource);
291 }
292
Bellido Nicolas4a91ca22005-10-28 16:51:42 +0100293 platform_device_register(&aaec2000_flash_device);
294
295 return 0;
296};
297arch_initcall(aaec2000_init);
298