v2m.c 8.0 KB

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