]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/arm/mach-vexpress/v2m.c
ARM: vexpress: add sched_clock() for Versatile Express
[mv-sheeva.git] / arch / arm / mach-vexpress / v2m.c
1 /*
2  * Versatile Express V2M Motherboard Support
3  */
4 #include <linux/device.h>
5 #include <linux/amba/bus.h>
6 #include <linux/amba/mmci.h>
7 #include <linux/io.h>
8 #include <linux/init.h>
9 #include <linux/platform_device.h>
10 #include <linux/smsc911x.h>
11 #include <linux/spinlock.h>
12 #include <linux/sysdev.h>
13 #include <linux/usb/isp1760.h>
14
15 #include <asm/clkdev.h>
16 #include <asm/sizes.h>
17 #include <asm/mach/flash.h>
18 #include <asm/mach/map.h>
19 #include <asm/mach/time.h>
20 #include <asm/hardware/arm_timer.h>
21
22 #include <mach/clkdev.h>
23 #include <mach/motherboard.h>
24
25 #include <plat/sched_clock.h>
26
27 #include <plat/timer-sp.h>
28
29 #include "core.h"
30
31 #define V2M_PA_CS0      0x40000000
32 #define V2M_PA_CS1      0x44000000
33 #define V2M_PA_CS2      0x48000000
34 #define V2M_PA_CS3      0x4c000000
35 #define V2M_PA_CS7      0x10000000
36
37 static struct map_desc v2m_io_desc[] __initdata = {
38         {
39                 .virtual        = __MMIO_P2V(V2M_PA_CS7),
40                 .pfn            = __phys_to_pfn(V2M_PA_CS7),
41                 .length         = SZ_128K,
42                 .type           = MT_DEVICE,
43         },
44 };
45
46 void __init v2m_map_io(struct map_desc *tile, size_t num)
47 {
48         iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
49         iotable_init(tile, num);
50 }
51
52
53 static void __init v2m_timer_init(void)
54 {
55         versatile_sched_clock_init(MMIO_P2V(V2M_SYS_24MHZ), 24000000);
56
57         writel(0, MMIO_P2V(V2M_TIMER0) + TIMER_CTRL);
58         writel(0, MMIO_P2V(V2M_TIMER1) + TIMER_CTRL);
59
60         sp804_clocksource_init(MMIO_P2V(V2M_TIMER1));
61         sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0);
62 }
63
64 struct sys_timer v2m_timer = {
65         .init   = v2m_timer_init,
66 };
67
68
69 static DEFINE_SPINLOCK(v2m_cfg_lock);
70
71 int v2m_cfg_write(u32 devfn, u32 data)
72 {
73         /* Configuration interface broken? */
74         u32 val;
75
76         printk("%s: writing %08x to %08x\n", __func__, data, devfn);
77
78         devfn |= SYS_CFG_START | SYS_CFG_WRITE;
79
80         spin_lock(&v2m_cfg_lock);
81         val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
82         writel(val & ~SYS_CFG_COMPLETE, MMIO_P2V(V2M_SYS_CFGSTAT));
83
84         writel(data, MMIO_P2V(V2M_SYS_CFGDATA));
85         writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
86
87         do {
88                 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
89         } while (val == 0);
90         spin_unlock(&v2m_cfg_lock);
91
92         return !!(val & SYS_CFG_ERR);
93 }
94
95 int v2m_cfg_read(u32 devfn, u32 *data)
96 {
97         u32 val;
98
99         devfn |= SYS_CFG_START;
100
101         spin_lock(&v2m_cfg_lock);
102         writel(0, MMIO_P2V(V2M_SYS_CFGSTAT));
103         writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
104
105         mb();
106
107         do {
108                 cpu_relax();
109                 val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
110         } while (val == 0);
111
112         *data = readl(MMIO_P2V(V2M_SYS_CFGDATA));
113         spin_unlock(&v2m_cfg_lock);
114
115         return !!(val & SYS_CFG_ERR);
116 }
117
118
119 static struct resource v2m_pcie_i2c_resource = {
120         .start  = V2M_SERIAL_BUS_PCI,
121         .end    = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
122         .flags  = IORESOURCE_MEM,
123 };
124
125 static struct platform_device v2m_pcie_i2c_device = {
126         .name           = "versatile-i2c",
127         .id             = 0,
128         .num_resources  = 1,
129         .resource       = &v2m_pcie_i2c_resource,
130 };
131
132 static struct resource v2m_ddc_i2c_resource = {
133         .start  = V2M_SERIAL_BUS_DVI,
134         .end    = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
135         .flags  = IORESOURCE_MEM,
136 };
137
138 static struct platform_device v2m_ddc_i2c_device = {
139         .name           = "versatile-i2c",
140         .id             = 1,
141         .num_resources  = 1,
142         .resource       = &v2m_ddc_i2c_resource,
143 };
144
145 static struct resource v2m_eth_resources[] = {
146         {
147                 .start  = V2M_LAN9118,
148                 .end    = V2M_LAN9118 + SZ_64K - 1,
149                 .flags  = IORESOURCE_MEM,
150         }, {
151                 .start  = IRQ_V2M_LAN9118,
152                 .end    = IRQ_V2M_LAN9118,
153                 .flags  = IORESOURCE_IRQ,
154         },
155 };
156
157 static struct smsc911x_platform_config v2m_eth_config = {
158         .flags          = SMSC911X_USE_32BIT,
159         .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
160         .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
161         .phy_interface  = PHY_INTERFACE_MODE_MII,
162 };
163
164 static struct platform_device v2m_eth_device = {
165         .name           = "smsc911x",
166         .id             = -1,
167         .resource       = v2m_eth_resources,
168         .num_resources  = ARRAY_SIZE(v2m_eth_resources),
169         .dev.platform_data = &v2m_eth_config,
170 };
171
172 static struct resource v2m_usb_resources[] = {
173         {
174                 .start  = V2M_ISP1761,
175                 .end    = V2M_ISP1761 + SZ_128K - 1,
176                 .flags  = IORESOURCE_MEM,
177         }, {
178                 .start  = IRQ_V2M_ISP1761,
179                 .end    = IRQ_V2M_ISP1761,
180                 .flags  = IORESOURCE_IRQ,
181         },
182 };
183
184 static struct isp1760_platform_data v2m_usb_config = {
185         .is_isp1761             = true,
186         .bus_width_16           = false,
187         .port1_otg              = true,
188         .analog_oc              = false,
189         .dack_polarity_high     = false,
190         .dreq_polarity_high     = false,
191 };
192
193 static struct platform_device v2m_usb_device = {
194         .name           = "isp1760",
195         .id             = -1,
196         .resource       = v2m_usb_resources,
197         .num_resources  = ARRAY_SIZE(v2m_usb_resources),
198         .dev.platform_data = &v2m_usb_config,
199 };
200
201 static int v2m_flash_init(void)
202 {
203         writel(0, MMIO_P2V(V2M_SYS_FLASH));
204         return 0;
205 }
206
207 static void v2m_flash_exit(void)
208 {
209         writel(0, MMIO_P2V(V2M_SYS_FLASH));
210 }
211
212 static void v2m_flash_set_vpp(int on)
213 {
214         writel(on != 0, MMIO_P2V(V2M_SYS_FLASH));
215 }
216
217 static struct flash_platform_data v2m_flash_data = {
218         .map_name       = "cfi_probe",
219         .width          = 4,
220         .init           = v2m_flash_init,
221         .exit           = v2m_flash_exit,
222         .set_vpp        = v2m_flash_set_vpp,
223 };
224
225 static struct resource v2m_flash_resources[] = {
226         {
227                 .start  = V2M_NOR0,
228                 .end    = V2M_NOR0 + SZ_64M - 1,
229                 .flags  = IORESOURCE_MEM,
230         }, {
231                 .start  = V2M_NOR1,
232                 .end    = V2M_NOR1 + SZ_64M - 1,
233                 .flags  = IORESOURCE_MEM,
234         },
235 };
236
237 static struct platform_device v2m_flash_device = {
238         .name           = "armflash",
239         .id             = -1,
240         .resource       = v2m_flash_resources,
241         .num_resources  = ARRAY_SIZE(v2m_flash_resources),
242         .dev.platform_data = &v2m_flash_data,
243 };
244
245
246 static unsigned int v2m_mmci_status(struct device *dev)
247 {
248         return readl(MMIO_P2V(V2M_SYS_MCI)) & (1 << 0);
249 }
250
251 static struct mmci_platform_data v2m_mmci_data = {
252         .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
253         .status         = v2m_mmci_status,
254 };
255
256 static AMBA_DEVICE(aaci,  "mb:aaci",  V2M_AACI, NULL);
257 static AMBA_DEVICE(mmci,  "mb:mmci",  V2M_MMCI, &v2m_mmci_data);
258 static AMBA_DEVICE(kmi0,  "mb:kmi0",  V2M_KMI0, NULL);
259 static AMBA_DEVICE(kmi1,  "mb:kmi1",  V2M_KMI1, NULL);
260 static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
261 static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
262 static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
263 static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
264 static AMBA_DEVICE(wdt,   "mb:wdt",   V2M_WDT, NULL);
265 static AMBA_DEVICE(rtc,   "mb:rtc",   V2M_RTC, NULL);
266
267 static struct amba_device *v2m_amba_devs[] __initdata = {
268         &aaci_device,
269         &mmci_device,
270         &kmi0_device,
271         &kmi1_device,
272         &uart0_device,
273         &uart1_device,
274         &uart2_device,
275         &uart3_device,
276         &wdt_device,
277         &rtc_device,
278 };
279
280
281 static long v2m_osc_round(struct clk *clk, unsigned long rate)
282 {
283         return rate;
284 }
285
286 static int v2m_osc1_set(struct clk *clk, unsigned long rate)
287 {
288         return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
289 }
290
291 static const struct clk_ops osc1_clk_ops = {
292         .round  = v2m_osc_round,
293         .set    = v2m_osc1_set,
294 };
295
296 static struct clk osc1_clk = {
297         .ops    = &osc1_clk_ops,
298         .rate   = 24000000,
299 };
300
301 static struct clk osc2_clk = {
302         .rate   = 24000000,
303 };
304
305 static struct clk dummy_apb_pclk;
306
307 static struct clk_lookup v2m_lookups[] = {
308         {       /* AMBA bus clock */
309                 .con_id         = "apb_pclk",
310                 .clk            = &dummy_apb_pclk,
311         }, {    /* UART0 */
312                 .dev_id         = "mb:uart0",
313                 .clk            = &osc2_clk,
314         }, {    /* UART1 */
315                 .dev_id         = "mb:uart1",
316                 .clk            = &osc2_clk,
317         }, {    /* UART2 */
318                 .dev_id         = "mb:uart2",
319                 .clk            = &osc2_clk,
320         }, {    /* UART3 */
321                 .dev_id         = "mb:uart3",
322                 .clk            = &osc2_clk,
323         }, {    /* KMI0 */
324                 .dev_id         = "mb:kmi0",
325                 .clk            = &osc2_clk,
326         }, {    /* KMI1 */
327                 .dev_id         = "mb:kmi1",
328                 .clk            = &osc2_clk,
329         }, {    /* MMC0 */
330                 .dev_id         = "mb:mmci",
331                 .clk            = &osc2_clk,
332         }, {    /* CLCD */
333                 .dev_id         = "mb:clcd",
334                 .clk            = &osc1_clk,
335         },
336 };
337
338 static void v2m_power_off(void)
339 {
340         if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
341                 printk(KERN_EMERG "Unable to shutdown\n");
342 }
343
344 static void v2m_restart(char str, const char *cmd)
345 {
346         if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
347                 printk(KERN_EMERG "Unable to reboot\n");
348 }
349
350 static int __init v2m_init(void)
351 {
352         int i;
353
354         clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
355
356         platform_device_register(&v2m_pcie_i2c_device);
357         platform_device_register(&v2m_ddc_i2c_device);
358         platform_device_register(&v2m_flash_device);
359         platform_device_register(&v2m_eth_device);
360         platform_device_register(&v2m_usb_device);
361
362         for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
363                 amba_device_register(v2m_amba_devs[i], &iomem_resource);
364
365         pm_power_off = v2m_power_off;
366         arm_pm_restart = v2m_restart;
367
368         return 0;
369 }
370 arch_initcall(v2m_init);