v2m.c 10 KB

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