blob: 3555d616774c0b8f84f6c9827b0f19a2a7c50496 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-sa1100/generic.c
3 *
4 * Author: Nicolas Pitre
5 *
6 * Code common to all SA11x0 machines.
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/delay.h>
16#include <linux/pm.h>
17#include <linux/cpufreq.h>
18#include <linux/ioport.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -080019#include <linux/sched.h> /* just for sched_clock() - funny that */
Russell Kingd052d1b2005-10-29 19:07:23 +010020#include <linux/platform_device.h>
David Howellsb4f151f2008-09-24 17:48:26 +010021#include <linux/cnt32_to_63.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <asm/div64.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010024#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/system.h>
26#include <asm/pgtable.h>
27#include <asm/mach/map.h>
Russell King14e66f72005-10-29 16:08:31 +010028#include <asm/mach/flash.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/irq.h>
David Brownellaeb3f6d2007-03-18 01:26:13 -080030#include <asm/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include "generic.h"
33
Eric Miao04fef222008-07-29 14:26:00 +080034unsigned int reset_status;
35EXPORT_SYMBOL(reset_status);
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#define NR_FREQS 16
38
39/*
40 * This table is setup for a 3.6864MHz Crystal.
41 */
42static const unsigned short cclk_frequency_100khz[NR_FREQS] = {
43 590, /* 59.0 MHz */
44 737, /* 73.7 MHz */
Kristoffer Ericsonbda03082008-09-29 17:09:10 +010045 885, /* 88.5 MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 1032, /* 103.2 MHz */
47 1180, /* 118.0 MHz */
48 1327, /* 132.7 MHz */
49 1475, /* 147.5 MHz */
50 1622, /* 162.2 MHz */
51 1769, /* 176.9 MHz */
52 1917, /* 191.7 MHz */
53 2064, /* 206.4 MHz */
54 2212, /* 221.2 MHz */
Kristoffer Ericsonbda03082008-09-29 17:09:10 +010055 2359, /* 235.9 MHz */
56 2507, /* 250.7 MHz */
57 2654, /* 265.4 MHz */
58 2802 /* 280.2 MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059};
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/* rounds up(!) */
62unsigned int sa11x0_freq_to_ppcr(unsigned int khz)
63{
64 int i;
65
66 khz /= 100;
67
68 for (i = 0; i < NR_FREQS; i++)
69 if (cclk_frequency_100khz[i] >= khz)
70 break;
71
72 return i;
73}
74
75unsigned int sa11x0_ppcr_to_freq(unsigned int idx)
76{
77 unsigned int freq = 0;
78 if (idx < NR_FREQS)
79 freq = cclk_frequency_100khz[idx] * 100;
80 return freq;
81}
82
83
84/* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
85 * this platform, anyway.
86 */
87int sa11x0_verify_speed(struct cpufreq_policy *policy)
88{
89 unsigned int tmp;
90 if (policy->cpu)
91 return -EINVAL;
92
93 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
94
95 /* make sure that at least one frequency is within the policy */
96 tmp = cclk_frequency_100khz[sa11x0_freq_to_ppcr(policy->min)] * 100;
97 if (tmp > policy->max)
98 policy->max = tmp;
99
100 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
101
102 return 0;
103}
104
105unsigned int sa11x0_getspeed(unsigned int cpu)
106{
107 if (cpu)
108 return 0;
109 return cclk_frequency_100khz[PPCR & 0xf] * 100;
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*
113 * This is the SA11x0 sched_clock implementation. This has
Nicolas Pitre2f1675c2006-12-04 20:25:47 +0100114 * a resolution of 271ns, and a maximum value of 32025597s (370 days).
115 *
116 * The return value is guaranteed to be monotonic in that range as
117 * long as there is always less than 582 seconds between successive
118 * calls to this function.
119 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 * ( * 1E9 / 3686400 => * 78125 / 288)
121 */
122unsigned long long sched_clock(void)
123{
Nicolas Pitre2f1675c2006-12-04 20:25:47 +0100124 unsigned long long v = cnt32_to_63(OSCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Nicolas Pitre2f1675c2006-12-04 20:25:47 +0100126 /* the <<1 gets rid of the cnt_32_to_63 top bit saving on a bic insn */
127 v *= 78125<<1;
128 do_div(v, 288<<1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 return v;
131}
132
133/*
134 * Default power-off for SA1100
135 */
136static void sa1100_power_off(void)
137{
138 mdelay(100);
139 local_irq_disable();
140 /* disable internal oscillator, float CS lines */
141 PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
142 /* enable wake-up on GPIO0 (Assabet...) */
143 PWER = GFER = GRER = 1;
144 /*
145 * set scratchpad to zero, just in case it is used as a
146 * restart address by the bootloader.
147 */
148 PSPR = 0;
149 /* enter sleep mode */
150 PMCR = PMCR_SF;
151}
152
Russell King7a5b4e12009-10-06 14:55:53 +0100153static void sa11x0_register_device(struct platform_device *dev, void *data)
154{
155 int err;
156 dev->dev.platform_data = data;
157 err = platform_device_register(dev);
158 if (err)
159 printk(KERN_ERR "Unable to register device %s: %d\n",
160 dev->name, err);
161}
162
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164static struct resource sa11x0udc_resources[] = {
165 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100166 .start = __PREG(Ser0UDCCR),
167 .end = __PREG(Ser0UDCCR) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 .flags = IORESOURCE_MEM,
169 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100170 [1] = {
171 .start = IRQ_Ser0UDC,
172 .end = IRQ_Ser0UDC,
173 .flags = IORESOURCE_IRQ,
174 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175};
176
177static u64 sa11x0udc_dma_mask = 0xffffffffUL;
178
179static struct platform_device sa11x0udc_device = {
180 .name = "sa11x0-udc",
181 .id = -1,
182 .dev = {
183 .dma_mask = &sa11x0udc_dma_mask,
184 .coherent_dma_mask = 0xffffffff,
185 },
186 .num_resources = ARRAY_SIZE(sa11x0udc_resources),
187 .resource = sa11x0udc_resources,
188};
189
190static struct resource sa11x0uart1_resources[] = {
191 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100192 .start = __PREG(Ser1UTCR0),
193 .end = __PREG(Ser1UTCR0) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 .flags = IORESOURCE_MEM,
195 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100196 [1] = {
197 .start = IRQ_Ser1UART,
198 .end = IRQ_Ser1UART,
199 .flags = IORESOURCE_IRQ,
200 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201};
202
203static struct platform_device sa11x0uart1_device = {
204 .name = "sa11x0-uart",
205 .id = 1,
206 .num_resources = ARRAY_SIZE(sa11x0uart1_resources),
207 .resource = sa11x0uart1_resources,
208};
209
210static struct resource sa11x0uart3_resources[] = {
211 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100212 .start = __PREG(Ser3UTCR0),
213 .end = __PREG(Ser3UTCR0) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .flags = IORESOURCE_MEM,
215 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100216 [1] = {
217 .start = IRQ_Ser3UART,
218 .end = IRQ_Ser3UART,
219 .flags = IORESOURCE_IRQ,
220 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221};
222
223static struct platform_device sa11x0uart3_device = {
224 .name = "sa11x0-uart",
225 .id = 3,
226 .num_resources = ARRAY_SIZE(sa11x0uart3_resources),
227 .resource = sa11x0uart3_resources,
228};
229
230static struct resource sa11x0mcp_resources[] = {
231 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100232 .start = __PREG(Ser4MCCR0),
233 .end = __PREG(Ser4MCCR0) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 .flags = IORESOURCE_MEM,
235 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100236 [1] = {
237 .start = IRQ_Ser4MCP,
238 .end = IRQ_Ser4MCP,
239 .flags = IORESOURCE_IRQ,
240 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241};
242
243static u64 sa11x0mcp_dma_mask = 0xffffffffUL;
244
245static struct platform_device sa11x0mcp_device = {
246 .name = "sa11x0-mcp",
247 .id = -1,
248 .dev = {
249 .dma_mask = &sa11x0mcp_dma_mask,
250 .coherent_dma_mask = 0xffffffff,
251 },
252 .num_resources = ARRAY_SIZE(sa11x0mcp_resources),
253 .resource = sa11x0mcp_resources,
254};
255
Russell King7a5b4e12009-10-06 14:55:53 +0100256void sa11x0_register_mcp(struct mcp_plat_data *data)
Russell King323cdfc2005-08-18 10:10:46 +0100257{
Russell King7a5b4e12009-10-06 14:55:53 +0100258 sa11x0_register_device(&sa11x0mcp_device, data);
Russell King323cdfc2005-08-18 10:10:46 +0100259}
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261static struct resource sa11x0ssp_resources[] = {
262 [0] = {
263 .start = 0x80070000,
264 .end = 0x8007ffff,
265 .flags = IORESOURCE_MEM,
266 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100267 [1] = {
268 .start = IRQ_Ser4SSP,
269 .end = IRQ_Ser4SSP,
270 .flags = IORESOURCE_IRQ,
271 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272};
273
274static u64 sa11x0ssp_dma_mask = 0xffffffffUL;
275
276static struct platform_device sa11x0ssp_device = {
277 .name = "sa11x0-ssp",
278 .id = -1,
279 .dev = {
280 .dma_mask = &sa11x0ssp_dma_mask,
281 .coherent_dma_mask = 0xffffffff,
282 },
283 .num_resources = ARRAY_SIZE(sa11x0ssp_resources),
284 .resource = sa11x0ssp_resources,
285};
286
287static struct resource sa11x0fb_resources[] = {
288 [0] = {
289 .start = 0xb0100000,
290 .end = 0xb010ffff,
291 .flags = IORESOURCE_MEM,
292 },
293 [1] = {
294 .start = IRQ_LCD,
295 .end = IRQ_LCD,
296 .flags = IORESOURCE_IRQ,
297 },
298};
299
300static struct platform_device sa11x0fb_device = {
301 .name = "sa11x0-fb",
302 .id = -1,
303 .dev = {
304 .coherent_dma_mask = 0xffffffff,
305 },
306 .num_resources = ARRAY_SIZE(sa11x0fb_resources),
307 .resource = sa11x0fb_resources,
308};
309
310static struct platform_device sa11x0pcmcia_device = {
311 .name = "sa11x0-pcmcia",
312 .id = -1,
313};
314
315static struct platform_device sa11x0mtd_device = {
Uwe Kleine-Königbcc8f3e2009-01-31 01:21:58 +0100316 .name = "sa1100-mtd",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 .id = -1,
318};
319
Russell King7a5b4e12009-10-06 14:55:53 +0100320void sa11x0_register_mtd(struct flash_platform_data *flash,
321 struct resource *res, int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Russell King14e66f72005-10-29 16:08:31 +0100323 flash->name = "sa1100";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 sa11x0mtd_device.resource = res;
325 sa11x0mtd_device.num_resources = nr;
Russell King7a5b4e12009-10-06 14:55:53 +0100326 sa11x0_register_device(&sa11x0mtd_device, flash);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
329static struct resource sa11x0ir_resources[] = {
330 {
331 .start = __PREG(Ser2UTCR0),
332 .end = __PREG(Ser2UTCR0) + 0x24 - 1,
333 .flags = IORESOURCE_MEM,
334 }, {
335 .start = __PREG(Ser2HSCR0),
336 .end = __PREG(Ser2HSCR0) + 0x1c - 1,
337 .flags = IORESOURCE_MEM,
338 }, {
339 .start = __PREG(Ser2HSCR2),
340 .end = __PREG(Ser2HSCR2) + 0x04 - 1,
341 .flags = IORESOURCE_MEM,
342 }, {
343 .start = IRQ_Ser2ICP,
344 .end = IRQ_Ser2ICP,
345 .flags = IORESOURCE_IRQ,
346 }
347};
348
349static struct platform_device sa11x0ir_device = {
350 .name = "sa11x0-ir",
351 .id = -1,
352 .num_resources = ARRAY_SIZE(sa11x0ir_resources),
353 .resource = sa11x0ir_resources,
354};
355
Russell King7a5b4e12009-10-06 14:55:53 +0100356void sa11x0_register_irda(struct irda_platform_data *irda)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Russell King7a5b4e12009-10-06 14:55:53 +0100358 sa11x0_register_device(&sa11x0ir_device, irda);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Richard Purdiee842f1c2006-03-27 01:16:46 -0800361static struct platform_device sa11x0rtc_device = {
362 .name = "sa1100-rtc",
363 .id = -1,
364};
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366static struct platform_device *sa11x0_devices[] __initdata = {
367 &sa11x0udc_device,
368 &sa11x0uart1_device,
369 &sa11x0uart3_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 &sa11x0ssp_device,
371 &sa11x0pcmcia_device,
372 &sa11x0fb_device,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800373 &sa11x0rtc_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374};
375
376static int __init sa1100_init(void)
377{
378 pm_power_off = sa1100_power_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
380}
381
382arch_initcall(sa1100_init);
383
384void (*sa1100fb_backlight_power)(int on);
385void (*sa1100fb_lcd_power)(int on);
386
387EXPORT_SYMBOL(sa1100fb_backlight_power);
388EXPORT_SYMBOL(sa1100fb_lcd_power);
389
390
391/*
392 * Common I/O mapping:
393 *
394 * Typically, static virtual address mappings are as follow:
395 *
396 * 0xf0000000-0xf3ffffff: miscellaneous stuff (CPLDs, etc.)
397 * 0xf4000000-0xf4ffffff: SA-1111
398 * 0xf5000000-0xf5ffffff: reserved (used by cache flushing area)
399 * 0xf6000000-0xfffeffff: reserved (internal SA1100 IO defined above)
400 * 0xffff0000-0xffff0fff: SA1100 exception vectors
401 * 0xffff2000-0xffff2fff: Minicache copy_user_page area
402 *
403 * Below 0xe8000000 is reserved for vm allocation.
404 *
405 * The machine specific code must provide the extra mapping beside the
406 * default mapping provided here.
407 */
408
409static struct map_desc standard_io_desc[] __initdata = {
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100410 { /* PCM */
Deepak Saxena92519d82005-10-28 15:19:04 +0100411 .virtual = 0xf8000000,
412 .pfn = __phys_to_pfn(0x80000000),
413 .length = 0x00100000,
414 .type = MT_DEVICE
415 }, { /* SCM */
416 .virtual = 0xfa000000,
417 .pfn = __phys_to_pfn(0x90000000),
418 .length = 0x00100000,
419 .type = MT_DEVICE
420 }, { /* MER */
421 .virtual = 0xfc000000,
422 .pfn = __phys_to_pfn(0xa0000000),
423 .length = 0x00100000,
424 .type = MT_DEVICE
425 }, { /* LCD + DMA */
426 .virtual = 0xfe000000,
427 .pfn = __phys_to_pfn(0xb0000000),
428 .length = 0x00200000,
429 .type = MT_DEVICE
430 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431};
432
433void __init sa1100_map_io(void)
434{
435 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
436}
437
438/*
439 * Disable the memory bus request/grant signals on the SA1110 to
440 * ensure that we don't receive spurious memory requests. We set
441 * the MBGNT signal false to ensure the SA1111 doesn't own the
442 * SDRAM bus.
443 */
444void __init sa1110_mb_disable(void)
445{
446 unsigned long flags;
447
448 local_irq_save(flags);
449
450 PGSR &= ~GPIO_MBGNT;
451 GPCR = GPIO_MBGNT;
452 GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
453
454 GAFR &= ~(GPIO_MBGNT | GPIO_MBREQ);
455
456 local_irq_restore(flags);
457}
458
459/*
460 * If the system is going to use the SA-1111 DMA engines, set up
461 * the memory bus request/grant pins.
462 */
Kristoffer Ericson85e6c7a2008-02-03 22:08:10 +0100463void __devinit sa1110_mb_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 unsigned long flags;
466
467 local_irq_save(flags);
468
469 PGSR &= ~GPIO_MBGNT;
470 GPCR = GPIO_MBGNT;
471 GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
472
473 GAFR |= (GPIO_MBGNT | GPIO_MBREQ);
474 TUCR |= TUCR_MR;
475
476 local_irq_restore(flags);
477}
478