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