blob: de13603dc028313966899de0154c1aa97fbaf394 [file] [log] [blame]
Russell Kingceade892010-02-11 21:44:53 +00001/*
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>
Russell King58daf182011-01-05 18:09:03 +000021#include <asm/hardware/timer-sp.h>
Russell Kingceade892010-02-11 21:44:53 +000022
23#include <mach/clkdev.h>
24#include <mach/motherboard.h>
25
Russell King0af85dd2010-12-15 21:58:50 +000026#include <plat/sched_clock.h>
Russell Kingceade892010-02-11 21:44:53 +000027
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
36static 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
45void __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
Russell Kingcdaf9a22010-10-05 11:29:28 +010052static void __init v2m_timer_init(void)
Russell Kingceade892010-02-11 21:44:53 +000053{
Russell King0af85dd2010-12-15 21:58:50 +000054 versatile_sched_clock_init(MMIO_P2V(V2M_SYS_24MHZ), 24000000);
55
Russell Kingceade892010-02-11 21:44:53 +000056 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
63struct sys_timer v2m_timer = {
64 .init = v2m_timer_init,
65};
66
67
68static DEFINE_SPINLOCK(v2m_cfg_lock);
69
70int 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
94int 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
118static 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
124static 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
131static 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
137static 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
144static 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
156static 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
163static 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
171static 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
183static 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
192static 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
200static int v2m_flash_init(void)
201{
202 writel(0, MMIO_P2V(V2M_SYS_FLASH));
203 return 0;
204}
205
206static void v2m_flash_exit(void)
207{
208 writel(0, MMIO_P2V(V2M_SYS_FLASH));
209}
210
211static void v2m_flash_set_vpp(int on)
212{
213 writel(on != 0, MMIO_P2V(V2M_SYS_FLASH));
214}
215
216static 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
224static 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
236static 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
245static unsigned int v2m_mmci_status(struct device *dev)
246{
Russell King74bc8092010-07-29 15:58:59 +0100247 return readl(MMIO_P2V(V2M_SYS_MCI)) & (1 << 0);
Russell Kingceade892010-02-11 21:44:53 +0000248}
249
250static 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
255static AMBA_DEVICE(aaci, "mb:aaci", V2M_AACI, NULL);
256static AMBA_DEVICE(mmci, "mb:mmci", V2M_MMCI, &v2m_mmci_data);
257static AMBA_DEVICE(kmi0, "mb:kmi0", V2M_KMI0, NULL);
258static AMBA_DEVICE(kmi1, "mb:kmi1", V2M_KMI1, NULL);
259static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
260static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
261static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
262static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
263static AMBA_DEVICE(wdt, "mb:wdt", V2M_WDT, NULL);
264static AMBA_DEVICE(rtc, "mb:rtc", V2M_RTC, NULL);
265
266static 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
280static long v2m_osc_round(struct clk *clk, unsigned long rate)
281{
282 return rate;
283}
284
285static 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
290static const struct clk_ops osc1_clk_ops = {
291 .round = v2m_osc_round,
292 .set = v2m_osc1_set,
293};
294
295static struct clk osc1_clk = {
296 .ops = &osc1_clk_ops,
297 .rate = 24000000,
298};
299
300static struct clk osc2_clk = {
301 .rate = 24000000,
302};
303
Russell King3126c7b2010-07-15 11:01:17 +0100304static struct clk dummy_apb_pclk;
305
Russell Kingceade892010-02-11 21:44:53 +0000306static struct clk_lookup v2m_lookups[] = {
Russell King3126c7b2010-07-15 11:01:17 +0100307 { /* AMBA bus clock */
308 .con_id = "apb_pclk",
309 .clk = &dummy_apb_pclk,
310 }, { /* UART0 */
Russell Kingceade892010-02-11 21:44:53 +0000311 .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
337static 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
343static 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
349static 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}
369arch_initcall(v2m_init);