v2m.c 9.9 KB

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