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