blob: 52ea6229818f45e6b9bb5419e24102bac348e56f [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 */
Russell King2f8163b2011-07-26 10:53:52 +010012#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/delay.h>
Russell King7931d922012-01-09 21:45:51 +000017#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/pm.h>
19#include <linux/cpufreq.h>
20#include <linux/ioport.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010021#include <linux/platform_device.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/mach/map.h>
Russell King14e66f72005-10-29 16:08:31 +010027#include <asm/mach/flash.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/irq.h>
29
30#include "generic.h"
31
Eric Miao04fef222008-07-29 14:26:00 +080032unsigned int reset_status;
33EXPORT_SYMBOL(reset_status);
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define NR_FREQS 16
36
37/*
38 * This table is setup for a 3.6864MHz Crystal.
39 */
40static const unsigned short cclk_frequency_100khz[NR_FREQS] = {
41 590, /* 59.0 MHz */
42 737, /* 73.7 MHz */
Kristoffer Ericsonbda03082008-09-29 17:09:10 +010043 885, /* 88.5 MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 1032, /* 103.2 MHz */
45 1180, /* 118.0 MHz */
46 1327, /* 132.7 MHz */
47 1475, /* 147.5 MHz */
48 1622, /* 162.2 MHz */
49 1769, /* 176.9 MHz */
50 1917, /* 191.7 MHz */
51 2064, /* 206.4 MHz */
52 2212, /* 221.2 MHz */
Kristoffer Ericsonbda03082008-09-29 17:09:10 +010053 2359, /* 235.9 MHz */
54 2507, /* 250.7 MHz */
55 2654, /* 265.4 MHz */
56 2802 /* 280.2 MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059/* rounds up(!) */
60unsigned int sa11x0_freq_to_ppcr(unsigned int khz)
61{
62 int i;
63
64 khz /= 100;
65
66 for (i = 0; i < NR_FREQS; i++)
67 if (cclk_frequency_100khz[i] >= khz)
68 break;
69
70 return i;
71}
72
73unsigned int sa11x0_ppcr_to_freq(unsigned int idx)
74{
75 unsigned int freq = 0;
76 if (idx < NR_FREQS)
77 freq = cclk_frequency_100khz[idx] * 100;
78 return freq;
79}
80
81
82/* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
83 * this platform, anyway.
84 */
85int sa11x0_verify_speed(struct cpufreq_policy *policy)
86{
87 unsigned int tmp;
88 if (policy->cpu)
89 return -EINVAL;
90
91 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
92
93 /* make sure that at least one frequency is within the policy */
94 tmp = cclk_frequency_100khz[sa11x0_freq_to_ppcr(policy->min)] * 100;
95 if (tmp > policy->max)
96 policy->max = tmp;
97
98 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, policy->cpuinfo.max_freq);
99
100 return 0;
101}
102
103unsigned int sa11x0_getspeed(unsigned int cpu)
104{
105 if (cpu)
106 return 0;
107 return cclk_frequency_100khz[PPCR & 0xf] * 100;
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 * Default power-off for SA1100
112 */
113static void sa1100_power_off(void)
114{
115 mdelay(100);
116 local_irq_disable();
117 /* disable internal oscillator, float CS lines */
118 PCFR = (PCFR_OPDE | PCFR_FP | PCFR_FS);
119 /* enable wake-up on GPIO0 (Assabet...) */
120 PWER = GFER = GRER = 1;
121 /*
122 * set scratchpad to zero, just in case it is used as a
123 * restart address by the bootloader.
124 */
125 PSPR = 0;
126 /* enter sleep mode */
127 PMCR = PMCR_SF;
128}
129
Russell Kingd9ca5832011-11-05 10:28:50 +0000130void sa11x0_restart(char mode, const char *cmd)
131{
132 if (mode == 's') {
133 /* Jump into ROM at address 0 */
134 soft_restart(0);
135 } else {
136 /* Use on-chip reset capability */
137 RSRR = RSRR_SWR;
138 }
139}
140
Russell King7a5b4e12009-10-06 14:55:53 +0100141static void sa11x0_register_device(struct platform_device *dev, void *data)
142{
143 int err;
144 dev->dev.platform_data = data;
145 err = platform_device_register(dev);
146 if (err)
147 printk(KERN_ERR "Unable to register device %s: %d\n",
148 dev->name, err);
149}
150
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152static struct resource sa11x0udc_resources[] = {
153 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100154 .start = __PREG(Ser0UDCCR),
155 .end = __PREG(Ser0UDCCR) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .flags = IORESOURCE_MEM,
157 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100158 [1] = {
159 .start = IRQ_Ser0UDC,
160 .end = IRQ_Ser0UDC,
161 .flags = IORESOURCE_IRQ,
162 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163};
164
165static u64 sa11x0udc_dma_mask = 0xffffffffUL;
166
167static struct platform_device sa11x0udc_device = {
168 .name = "sa11x0-udc",
169 .id = -1,
170 .dev = {
171 .dma_mask = &sa11x0udc_dma_mask,
172 .coherent_dma_mask = 0xffffffff,
173 },
174 .num_resources = ARRAY_SIZE(sa11x0udc_resources),
175 .resource = sa11x0udc_resources,
176};
177
178static struct resource sa11x0uart1_resources[] = {
179 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100180 .start = __PREG(Ser1UTCR0),
181 .end = __PREG(Ser1UTCR0) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 .flags = IORESOURCE_MEM,
183 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100184 [1] = {
185 .start = IRQ_Ser1UART,
186 .end = IRQ_Ser1UART,
187 .flags = IORESOURCE_IRQ,
188 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
191static struct platform_device sa11x0uart1_device = {
192 .name = "sa11x0-uart",
193 .id = 1,
194 .num_resources = ARRAY_SIZE(sa11x0uart1_resources),
195 .resource = sa11x0uart1_resources,
196};
197
198static struct resource sa11x0uart3_resources[] = {
199 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100200 .start = __PREG(Ser3UTCR0),
201 .end = __PREG(Ser3UTCR0) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .flags = IORESOURCE_MEM,
203 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100204 [1] = {
205 .start = IRQ_Ser3UART,
206 .end = IRQ_Ser3UART,
207 .flags = IORESOURCE_IRQ,
208 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
211static struct platform_device sa11x0uart3_device = {
212 .name = "sa11x0-uart",
213 .id = 3,
214 .num_resources = ARRAY_SIZE(sa11x0uart3_resources),
215 .resource = sa11x0uart3_resources,
216};
217
218static struct resource sa11x0mcp_resources[] = {
219 [0] = {
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100220 .start = __PREG(Ser4MCCR0),
Russell King216f63c2012-01-20 17:37:21 +0000221 .end = __PREG(Ser4MCCR0) + 0xffff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .flags = IORESOURCE_MEM,
223 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100224 [1] = {
225 .start = IRQ_Ser4MCP,
226 .end = IRQ_Ser4MCP,
227 .flags = IORESOURCE_IRQ,
228 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229};
230
231static u64 sa11x0mcp_dma_mask = 0xffffffffUL;
232
233static struct platform_device sa11x0mcp_device = {
234 .name = "sa11x0-mcp",
235 .id = -1,
236 .dev = {
237 .dma_mask = &sa11x0mcp_dma_mask,
238 .coherent_dma_mask = 0xffffffff,
239 },
240 .num_resources = ARRAY_SIZE(sa11x0mcp_resources),
241 .resource = sa11x0mcp_resources,
242};
243
Russell King7a5b4e12009-10-06 14:55:53 +0100244void sa11x0_register_mcp(struct mcp_plat_data *data)
Russell King323cdfc2005-08-18 10:10:46 +0100245{
Russell King7a5b4e12009-10-06 14:55:53 +0100246 sa11x0_register_device(&sa11x0mcp_device, data);
Russell King323cdfc2005-08-18 10:10:46 +0100247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249static struct resource sa11x0ssp_resources[] = {
250 [0] = {
251 .start = 0x80070000,
252 .end = 0x8007ffff,
253 .flags = IORESOURCE_MEM,
254 },
Jochen Friedrichcf562b42011-01-03 12:19:00 +0100255 [1] = {
256 .start = IRQ_Ser4SSP,
257 .end = IRQ_Ser4SSP,
258 .flags = IORESOURCE_IRQ,
259 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260};
261
262static u64 sa11x0ssp_dma_mask = 0xffffffffUL;
263
264static struct platform_device sa11x0ssp_device = {
265 .name = "sa11x0-ssp",
266 .id = -1,
267 .dev = {
268 .dma_mask = &sa11x0ssp_dma_mask,
269 .coherent_dma_mask = 0xffffffff,
270 },
271 .num_resources = ARRAY_SIZE(sa11x0ssp_resources),
272 .resource = sa11x0ssp_resources,
273};
274
275static struct resource sa11x0fb_resources[] = {
276 [0] = {
277 .start = 0xb0100000,
278 .end = 0xb010ffff,
279 .flags = IORESOURCE_MEM,
280 },
281 [1] = {
282 .start = IRQ_LCD,
283 .end = IRQ_LCD,
284 .flags = IORESOURCE_IRQ,
285 },
286};
287
288static struct platform_device sa11x0fb_device = {
289 .name = "sa11x0-fb",
290 .id = -1,
291 .dev = {
292 .coherent_dma_mask = 0xffffffff,
293 },
294 .num_resources = ARRAY_SIZE(sa11x0fb_resources),
295 .resource = sa11x0fb_resources,
296};
297
298static struct platform_device sa11x0pcmcia_device = {
299 .name = "sa11x0-pcmcia",
300 .id = -1,
301};
302
303static struct platform_device sa11x0mtd_device = {
Uwe Kleine-Königbcc8f3e2009-01-31 01:21:58 +0100304 .name = "sa1100-mtd",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 .id = -1,
306};
307
Russell King7a5b4e12009-10-06 14:55:53 +0100308void sa11x0_register_mtd(struct flash_platform_data *flash,
309 struct resource *res, int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Russell King14e66f72005-10-29 16:08:31 +0100311 flash->name = "sa1100";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 sa11x0mtd_device.resource = res;
313 sa11x0mtd_device.num_resources = nr;
Russell King7a5b4e12009-10-06 14:55:53 +0100314 sa11x0_register_device(&sa11x0mtd_device, flash);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317static struct resource sa11x0ir_resources[] = {
318 {
319 .start = __PREG(Ser2UTCR0),
320 .end = __PREG(Ser2UTCR0) + 0x24 - 1,
321 .flags = IORESOURCE_MEM,
322 }, {
323 .start = __PREG(Ser2HSCR0),
324 .end = __PREG(Ser2HSCR0) + 0x1c - 1,
325 .flags = IORESOURCE_MEM,
326 }, {
327 .start = __PREG(Ser2HSCR2),
328 .end = __PREG(Ser2HSCR2) + 0x04 - 1,
329 .flags = IORESOURCE_MEM,
330 }, {
331 .start = IRQ_Ser2ICP,
332 .end = IRQ_Ser2ICP,
333 .flags = IORESOURCE_IRQ,
334 }
335};
336
337static struct platform_device sa11x0ir_device = {
338 .name = "sa11x0-ir",
339 .id = -1,
340 .num_resources = ARRAY_SIZE(sa11x0ir_resources),
341 .resource = sa11x0ir_resources,
342};
343
Russell King7a5b4e12009-10-06 14:55:53 +0100344void sa11x0_register_irda(struct irda_platform_data *irda)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Russell King7a5b4e12009-10-06 14:55:53 +0100346 sa11x0_register_device(&sa11x0ir_device, irda);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Richard Purdiee842f1c2006-03-27 01:16:46 -0800349static struct platform_device sa11x0rtc_device = {
350 .name = "sa1100-rtc",
351 .id = -1,
352};
353
Russell King7931d922012-01-09 21:45:51 +0000354static struct resource sa11x0dma_resources[] = {
355 DEFINE_RES_MEM(__PREG(DDAR(0)), 6 * DMASp),
356 DEFINE_RES_IRQ(IRQ_DMA0),
357 DEFINE_RES_IRQ(IRQ_DMA1),
358 DEFINE_RES_IRQ(IRQ_DMA2),
359 DEFINE_RES_IRQ(IRQ_DMA3),
360 DEFINE_RES_IRQ(IRQ_DMA4),
361 DEFINE_RES_IRQ(IRQ_DMA5),
362};
363
364static u64 sa11x0dma_dma_mask = DMA_BIT_MASK(32);
365
366static struct platform_device sa11x0dma_device = {
367 .name = "sa11x0-dma",
368 .id = -1,
369 .dev = {
370 .dma_mask = &sa11x0dma_dma_mask,
371 .coherent_dma_mask = 0xffffffff,
372 },
373 .num_resources = ARRAY_SIZE(sa11x0dma_resources),
374 .resource = sa11x0dma_resources,
375};
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377static struct platform_device *sa11x0_devices[] __initdata = {
378 &sa11x0udc_device,
379 &sa11x0uart1_device,
380 &sa11x0uart3_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 &sa11x0ssp_device,
382 &sa11x0pcmcia_device,
383 &sa11x0fb_device,
Richard Purdiee842f1c2006-03-27 01:16:46 -0800384 &sa11x0rtc_device,
Russell King7931d922012-01-09 21:45:51 +0000385 &sa11x0dma_device,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386};
387
388static int __init sa1100_init(void)
389{
390 pm_power_off = sa1100_power_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return platform_add_devices(sa11x0_devices, ARRAY_SIZE(sa11x0_devices));
392}
393
394arch_initcall(sa1100_init);
395
396void (*sa1100fb_backlight_power)(int on);
397void (*sa1100fb_lcd_power)(int on);
398
399EXPORT_SYMBOL(sa1100fb_backlight_power);
400EXPORT_SYMBOL(sa1100fb_lcd_power);
401
402
403/*
404 * Common I/O mapping:
405 *
406 * Typically, static virtual address mappings are as follow:
407 *
408 * 0xf0000000-0xf3ffffff: miscellaneous stuff (CPLDs, etc.)
409 * 0xf4000000-0xf4ffffff: SA-1111
410 * 0xf5000000-0xf5ffffff: reserved (used by cache flushing area)
411 * 0xf6000000-0xfffeffff: reserved (internal SA1100 IO defined above)
412 * 0xffff0000-0xffff0fff: SA1100 exception vectors
413 * 0xffff2000-0xffff2fff: Minicache copy_user_page area
414 *
415 * Below 0xe8000000 is reserved for vm allocation.
416 *
417 * The machine specific code must provide the extra mapping beside the
418 * default mapping provided here.
419 */
420
421static struct map_desc standard_io_desc[] __initdata = {
Kristoffer Ericsonbda03082008-09-29 17:09:10 +0100422 { /* PCM */
Deepak Saxena92519d82005-10-28 15:19:04 +0100423 .virtual = 0xf8000000,
424 .pfn = __phys_to_pfn(0x80000000),
425 .length = 0x00100000,
426 .type = MT_DEVICE
427 }, { /* SCM */
428 .virtual = 0xfa000000,
429 .pfn = __phys_to_pfn(0x90000000),
430 .length = 0x00100000,
431 .type = MT_DEVICE
432 }, { /* MER */
433 .virtual = 0xfc000000,
434 .pfn = __phys_to_pfn(0xa0000000),
435 .length = 0x00100000,
436 .type = MT_DEVICE
437 }, { /* LCD + DMA */
438 .virtual = 0xfe000000,
439 .pfn = __phys_to_pfn(0xb0000000),
440 .length = 0x00200000,
441 .type = MT_DEVICE
442 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443};
444
445void __init sa1100_map_io(void)
446{
447 iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
448}
449
450/*
451 * Disable the memory bus request/grant signals on the SA1110 to
452 * ensure that we don't receive spurious memory requests. We set
453 * the MBGNT signal false to ensure the SA1111 doesn't own the
454 * SDRAM bus.
455 */
456void __init sa1110_mb_disable(void)
457{
458 unsigned long flags;
459
460 local_irq_save(flags);
461
462 PGSR &= ~GPIO_MBGNT;
463 GPCR = GPIO_MBGNT;
464 GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
465
466 GAFR &= ~(GPIO_MBGNT | GPIO_MBREQ);
467
468 local_irq_restore(flags);
469}
470
471/*
472 * If the system is going to use the SA-1111 DMA engines, set up
473 * the memory bus request/grant pins.
474 */
Kristoffer Ericson85e6c7a2008-02-03 22:08:10 +0100475void __devinit sa1110_mb_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 unsigned long flags;
478
479 local_irq_save(flags);
480
481 PGSR &= ~GPIO_MBGNT;
482 GPCR = GPIO_MBGNT;
483 GPDR = (GPDR & ~GPIO_MBREQ) | GPIO_MBGNT;
484
485 GAFR |= (GPIO_MBGNT | GPIO_MBREQ);
486 TUCR |= TUCR_MR;
487
488 local_irq_restore(flags);
489}
490