2 * linux/arch/arm/mach-realview/core.c
4 * Copyright (C) 1999 - 2003 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/init.h>
22 #include <linux/platform_device.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/device.h>
25 #include <linux/interrupt.h>
26 #include <linux/amba/bus.h>
27 #include <linux/amba/clcd.h>
29 #include <linux/smsc911x.h>
30 #include <linux/ata_platform.h>
31 #include <linux/amba/mmci.h>
32 #include <linux/gfp.h>
33 #include <linux/clkdev.h>
34 #include <linux/mtd/physmap.h>
36 #include <mach/hardware.h>
39 #include <asm/mach-types.h>
40 #include <asm/hardware/arm_timer.h>
41 #include <asm/hardware/icst.h>
43 #include <asm/mach/arch.h>
44 #include <asm/mach/irq.h>
45 #include <asm/mach/map.h>
47 #include <asm/hardware/gic.h>
49 #include <mach/platform.h>
50 #include <mach/irqs.h>
51 #include <asm/hardware/timer-sp.h>
53 #include <plat/clcd.h>
54 #include <plat/sched_clock.h>
58 #define REALVIEW_FLASHCTRL (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
60 static void realview_flash_set_vpp(struct platform_device
*pdev
, int on
)
64 val
= __raw_readl(REALVIEW_FLASHCTRL
);
66 val
|= REALVIEW_FLASHPROG_FLVPPEN
;
68 val
&= ~REALVIEW_FLASHPROG_FLVPPEN
;
69 __raw_writel(val
, REALVIEW_FLASHCTRL
);
72 static struct physmap_flash_data realview_flash_data
= {
74 .set_vpp
= realview_flash_set_vpp
,
77 struct platform_device realview_flash_device
= {
78 .name
= "physmap-flash",
81 .platform_data
= &realview_flash_data
,
85 int realview_flash_register(struct resource
*res
, u32 num
)
87 realview_flash_device
.resource
= res
;
88 realview_flash_device
.num_resources
= num
;
89 return platform_device_register(&realview_flash_device
);
92 static struct smsc911x_platform_config smsc911x_config
= {
93 .flags
= SMSC911X_USE_32BIT
,
94 .irq_polarity
= SMSC911X_IRQ_POLARITY_ACTIVE_HIGH
,
95 .irq_type
= SMSC911X_IRQ_TYPE_PUSH_PULL
,
96 .phy_interface
= PHY_INTERFACE_MODE_MII
,
99 static struct platform_device realview_eth_device
= {
105 int realview_eth_register(const char *name
, struct resource
*res
)
108 realview_eth_device
.name
= name
;
109 realview_eth_device
.resource
= res
;
110 if (strcmp(realview_eth_device
.name
, "smsc911x") == 0)
111 realview_eth_device
.dev
.platform_data
= &smsc911x_config
;
113 return platform_device_register(&realview_eth_device
);
116 struct platform_device realview_usb_device
= {
121 int realview_usb_register(struct resource
*res
)
123 realview_usb_device
.resource
= res
;
124 return platform_device_register(&realview_usb_device
);
127 static struct pata_platform_info pata_platform_data
= {
131 static struct resource pata_resources
[] = {
133 .start
= REALVIEW_CF_BASE
,
134 .end
= REALVIEW_CF_BASE
+ 0xff,
135 .flags
= IORESOURCE_MEM
,
138 .start
= REALVIEW_CF_BASE
+ 0x100,
139 .end
= REALVIEW_CF_BASE
+ SZ_4K
- 1,
140 .flags
= IORESOURCE_MEM
,
144 struct platform_device realview_cf_device
= {
145 .name
= "pata_platform",
147 .num_resources
= ARRAY_SIZE(pata_resources
),
148 .resource
= pata_resources
,
150 .platform_data
= &pata_platform_data
,
154 static struct resource realview_i2c_resource
= {
155 .start
= REALVIEW_I2C_BASE
,
156 .end
= REALVIEW_I2C_BASE
+ SZ_4K
- 1,
157 .flags
= IORESOURCE_MEM
,
160 struct platform_device realview_i2c_device
= {
161 .name
= "versatile-i2c",
164 .resource
= &realview_i2c_resource
,
167 static struct i2c_board_info realview_i2c_board_info
[] = {
169 I2C_BOARD_INFO("ds1338", 0xd0 >> 1),
173 static int __init
realview_i2c_init(void)
175 return i2c_register_board_info(0, realview_i2c_board_info
,
176 ARRAY_SIZE(realview_i2c_board_info
));
178 arch_initcall(realview_i2c_init
);
180 #define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
183 * This is only used if GPIOLIB support is disabled
185 static unsigned int realview_mmc_status(struct device
*dev
)
187 struct amba_device
*adev
= container_of(dev
, struct amba_device
, dev
);
190 if (machine_is_realview_pb1176()) {
191 static bool inserted
= false;
194 * The PB1176 does not have the status register,
195 * assume it is inserted at startup, then invert
196 * for each call so card insertion/removal will
197 * be detected anyway. This will not be called if
198 * GPIO on PL061 is active, which is the proper
199 * way to do this on the PB1176.
201 inserted
= !inserted
;
202 return inserted
? 0 : 1;
205 if (adev
->res
.start
== REALVIEW_MMCI0_BASE
)
210 return readl(REALVIEW_SYSMCI
) & mask
;
213 struct mmci_platform_data realview_mmc0_plat_data
= {
214 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
215 .status
= realview_mmc_status
,
221 struct mmci_platform_data realview_mmc1_plat_data
= {
222 .ocr_mask
= MMC_VDD_32_33
|MMC_VDD_33_34
,
223 .status
= realview_mmc_status
,
232 static const struct icst_params realview_oscvco_params
= {
234 .vco_max
= ICST307_VCO_MAX
,
235 .vco_min
= ICST307_VCO_MIN
,
240 .s2div
= icst307_s2div
,
241 .idx2s
= icst307_idx2s
,
244 static void realview_oscvco_set(struct clk
*clk
, struct icst_vco vco
)
246 void __iomem
*sys_lock
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_LOCK_OFFSET
;
249 val
= readl(clk
->vcoreg
) & ~0x7ffff;
250 val
|= vco
.v
| (vco
.r
<< 9) | (vco
.s
<< 16);
252 writel(0xa05f, sys_lock
);
253 writel(val
, clk
->vcoreg
);
257 static const struct clk_ops oscvco_clk_ops
= {
258 .round
= icst_clk_round
,
260 .setvco
= realview_oscvco_set
,
263 static struct clk oscvco_clk
= {
264 .ops
= &oscvco_clk_ops
,
265 .params
= &realview_oscvco_params
,
269 * These are fixed clocks.
271 static struct clk ref24_clk
= {
275 static struct clk sp804_clk
= {
279 static struct clk dummy_apb_pclk
;
281 static struct clk_lookup lookups
[] = {
283 .con_id
= "apb_pclk",
284 .clk
= &dummy_apb_pclk
,
286 .dev_id
= "dev:uart0",
289 .dev_id
= "dev:uart1",
292 .dev_id
= "dev:uart2",
295 .dev_id
= "fpga:uart3",
297 }, { /* UART3 is on the dev chip in PB1176 */
298 .dev_id
= "dev:uart3",
300 }, { /* UART4 only exists in PB1176 */
301 .dev_id
= "fpga:uart4",
304 .dev_id
= "fpga:kmi0",
307 .dev_id
= "fpga:kmi1",
310 .dev_id
= "fpga:mmc0",
312 }, { /* CLCD is in the PB1176 and EB DevChip */
313 .dev_id
= "dev:clcd",
316 .dev_id
= "issp:clcd",
319 .dev_id
= "dev:ssp0",
321 }, { /* SP804 timers */
327 void __init
realview_init_early(void)
329 void __iomem
*sys
= __io_address(REALVIEW_SYS_BASE
);
331 if (machine_is_realview_pb1176())
332 oscvco_clk
.vcoreg
= sys
+ REALVIEW_SYS_OSC0_OFFSET
;
334 oscvco_clk
.vcoreg
= sys
+ REALVIEW_SYS_OSC4_OFFSET
;
336 clkdev_add_table(lookups
, ARRAY_SIZE(lookups
));
338 versatile_sched_clock_init(sys
+ REALVIEW_SYS_24MHz_OFFSET
, 24000000);
344 #define SYS_CLCD_NLCDIOON (1 << 2)
345 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
346 #define SYS_CLCD_PWR3V5SWITCH (1 << 4)
347 #define SYS_CLCD_ID_MASK (0x1f << 8)
348 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
349 #define SYS_CLCD_ID_UNKNOWN_8_4 (0x01 << 8)
350 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
351 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
352 #define SYS_CLCD_ID_VGA (0x1f << 8)
355 * Disable all display connectors on the interface module.
357 static void realview_clcd_disable(struct clcd_fb
*fb
)
359 void __iomem
*sys_clcd
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_CLCD_OFFSET
;
362 val
= readl(sys_clcd
);
363 val
&= ~SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
;
364 writel(val
, sys_clcd
);
368 * Enable the relevant connector on the interface module.
370 static void realview_clcd_enable(struct clcd_fb
*fb
)
372 void __iomem
*sys_clcd
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_CLCD_OFFSET
;
378 val
= readl(sys_clcd
);
379 val
|= SYS_CLCD_NLCDIOON
| SYS_CLCD_PWR3V5SWITCH
;
380 writel(val
, sys_clcd
);
384 * Detect which LCD panel is connected, and return the appropriate
385 * clcd_panel structure. Note: we do not have any information on
386 * the required timings for the 8.4in panel, so we presently assume
389 static int realview_clcd_setup(struct clcd_fb
*fb
)
391 void __iomem
*sys_clcd
= __io_address(REALVIEW_SYS_BASE
) + REALVIEW_SYS_CLCD_OFFSET
;
392 const char *panel_name
, *vga_panel_name
;
393 unsigned long framesize
;
396 if (machine_is_realview_eb()) {
398 framesize
= 640 * 480 * 2;
399 vga_panel_name
= "VGA";
402 framesize
= 1024 * 768 * 2;
403 vga_panel_name
= "XVGA";
406 val
= readl(sys_clcd
) & SYS_CLCD_ID_MASK
;
407 if (val
== SYS_CLCD_ID_SANYO_3_8
)
408 panel_name
= "Sanyo TM38QV67A02A";
409 else if (val
== SYS_CLCD_ID_SANYO_2_5
)
410 panel_name
= "Sanyo QVGA Portrait";
411 else if (val
== SYS_CLCD_ID_EPSON_2_2
)
412 panel_name
= "Epson L2F50113T00";
413 else if (val
== SYS_CLCD_ID_VGA
)
414 panel_name
= vga_panel_name
;
416 pr_err("CLCD: unknown LCD panel ID 0x%08x, using VGA\n", val
);
417 panel_name
= vga_panel_name
;
420 fb
->panel
= versatile_clcd_get_panel(panel_name
);
424 return versatile_clcd_setup_dma(fb
, framesize
);
427 struct clcd_board clcd_plat_data
= {
429 .caps
= CLCD_CAP_ALL
,
430 .check
= clcdfb_check
,
431 .decode
= clcdfb_decode
,
432 .disable
= realview_clcd_disable
,
433 .enable
= realview_clcd_enable
,
434 .setup
= realview_clcd_setup
,
435 .mmap
= versatile_clcd_mmap_dma
,
436 .remove
= versatile_clcd_remove_dma
,
440 #define VA_LEDS_BASE (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
442 void realview_leds_event(led_event_t ledevt
)
446 u32 led
= 1 << smp_processor_id();
448 local_irq_save(flags
);
449 val
= readl(VA_LEDS_BASE
);
461 val
= val
^ REALVIEW_SYS_LED7
;
472 writel(val
, VA_LEDS_BASE
);
473 local_irq_restore(flags
);
475 #endif /* CONFIG_LEDS */
478 * Where is the timer (VA)?
480 void __iomem
*timer0_va_base
;
481 void __iomem
*timer1_va_base
;
482 void __iomem
*timer2_va_base
;
483 void __iomem
*timer3_va_base
;
486 * Set up the clock source and clock events devices
488 void __init
realview_timer_init(unsigned int timer_irq
)
493 * set clock frequency:
494 * REALVIEW_REFCLK is 32KHz
495 * REALVIEW_TIMCLK is 1MHz
497 val
= readl(__io_address(REALVIEW_SCTL_BASE
));
498 writel((REALVIEW_TIMCLK
<< REALVIEW_TIMER1_EnSel
) |
499 (REALVIEW_TIMCLK
<< REALVIEW_TIMER2_EnSel
) |
500 (REALVIEW_TIMCLK
<< REALVIEW_TIMER3_EnSel
) |
501 (REALVIEW_TIMCLK
<< REALVIEW_TIMER4_EnSel
) | val
,
502 __io_address(REALVIEW_SCTL_BASE
));
505 * Initialise to a known state (all timers off)
507 writel(0, timer0_va_base
+ TIMER_CTRL
);
508 writel(0, timer1_va_base
+ TIMER_CTRL
);
509 writel(0, timer2_va_base
+ TIMER_CTRL
);
510 writel(0, timer3_va_base
+ TIMER_CTRL
);
512 sp804_clocksource_init(timer3_va_base
, "timer3");
513 sp804_clockevents_init(timer0_va_base
, timer_irq
, "timer0");
517 * Setup the memory banks.
519 void realview_fixup(struct tag
*tags
, char **from
, struct meminfo
*meminfo
)
522 * Most RealView platforms have 512MB contiguous RAM at 0x70000000.
523 * Half of this is mirrored at 0.
525 #ifdef CONFIG_REALVIEW_HIGH_PHYS_OFFSET
526 meminfo
->bank
[0].start
= 0x70000000;
527 meminfo
->bank
[0].size
= SZ_512M
;
528 meminfo
->nr_banks
= 1;
530 meminfo
->bank
[0].start
= 0;
531 meminfo
->bank
[0].size
= SZ_256M
;
532 meminfo
->nr_banks
= 1;