cns3420vb.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Cavium Networks CNS3420 Validation Board
  3. *
  4. * Copyright 2000 Deep Blue Solutions Ltd
  5. * Copyright 2008 ARM Limited
  6. * Copyright 2008 Cavium Networks
  7. * Scott Shu
  8. * Copyright 2010 MontaVista Software, LLC.
  9. * Anton Vorontsov <avorontsov@mvista.com>
  10. *
  11. * This file is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License, Version 2, as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/compiler.h>
  18. #include <linux/io.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/serial_core.h>
  21. #include <linux/serial_8250.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/physmap.h>
  25. #include <linux/mtd/partitions.h>
  26. #include <linux/usb/ehci_pdriver.h>
  27. #include <linux/usb/ohci_pdriver.h>
  28. #include <asm/setup.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <asm/mach/time.h>
  33. #include "cns3xxx.h"
  34. #include "pm.h"
  35. #include "core.h"
  36. #include "devices.h"
  37. /*
  38. * NOR Flash
  39. */
  40. static struct mtd_partition cns3420_nor_partitions[] = {
  41. {
  42. .name = "uboot",
  43. .size = 0x00040000,
  44. .offset = 0,
  45. .mask_flags = MTD_WRITEABLE,
  46. }, {
  47. .name = "kernel",
  48. .size = 0x004C0000,
  49. .offset = MTDPART_OFS_APPEND,
  50. }, {
  51. .name = "filesystem",
  52. .size = 0x7000000,
  53. .offset = MTDPART_OFS_APPEND,
  54. }, {
  55. .name = "filesystem2",
  56. .size = 0x0AE0000,
  57. .offset = MTDPART_OFS_APPEND,
  58. }, {
  59. .name = "ubootenv",
  60. .size = MTDPART_SIZ_FULL,
  61. .offset = MTDPART_OFS_APPEND,
  62. },
  63. };
  64. static struct physmap_flash_data cns3420_nor_pdata = {
  65. .width = 2,
  66. .parts = cns3420_nor_partitions,
  67. .nr_parts = ARRAY_SIZE(cns3420_nor_partitions),
  68. };
  69. static struct resource cns3420_nor_res = {
  70. .start = CNS3XXX_FLASH_BASE,
  71. .end = CNS3XXX_FLASH_BASE + SZ_128M - 1,
  72. .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
  73. };
  74. static struct platform_device cns3420_nor_pdev = {
  75. .name = "physmap-flash",
  76. .id = 0,
  77. .resource = &cns3420_nor_res,
  78. .num_resources = 1,
  79. .dev = {
  80. .platform_data = &cns3420_nor_pdata,
  81. },
  82. };
  83. /*
  84. * UART
  85. */
  86. static void __init cns3420_early_serial_setup(void)
  87. {
  88. #ifdef CONFIG_SERIAL_8250_CONSOLE
  89. static struct uart_port cns3420_serial_port = {
  90. .membase = (void __iomem *)CNS3XXX_UART0_BASE_VIRT,
  91. .mapbase = CNS3XXX_UART0_BASE,
  92. .irq = IRQ_CNS3XXX_UART0,
  93. .iotype = UPIO_MEM,
  94. .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
  95. .regshift = 2,
  96. .uartclk = 24000000,
  97. .line = 0,
  98. .type = PORT_16550A,
  99. .fifosize = 16,
  100. };
  101. early_serial_setup(&cns3420_serial_port);
  102. #endif
  103. }
  104. /*
  105. * USB
  106. */
  107. static struct resource cns3xxx_usb_ehci_resources[] = {
  108. [0] = {
  109. .start = CNS3XXX_USB_BASE,
  110. .end = CNS3XXX_USB_BASE + SZ_16M - 1,
  111. .flags = IORESOURCE_MEM,
  112. },
  113. [1] = {
  114. .start = IRQ_CNS3XXX_USB_EHCI,
  115. .flags = IORESOURCE_IRQ,
  116. },
  117. };
  118. static u64 cns3xxx_usb_ehci_dma_mask = DMA_BIT_MASK(32);
  119. static int csn3xxx_usb_power_on(struct platform_device *pdev)
  120. {
  121. /*
  122. * EHCI and OHCI share the same clock and power,
  123. * resetting twice would cause the 1st controller been reset.
  124. * Therefore only do power up at the first up device, and
  125. * power down at the last down device.
  126. *
  127. * Set USB AHB INCR length to 16
  128. */
  129. if (atomic_inc_return(&usb_pwr_ref) == 1) {
  130. cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
  131. cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  132. cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
  133. __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
  134. MISC_CHIP_CONFIG_REG);
  135. }
  136. return 0;
  137. }
  138. static void csn3xxx_usb_power_off(struct platform_device *pdev)
  139. {
  140. /*
  141. * EHCI and OHCI share the same clock and power,
  142. * resetting twice would cause the 1st controller been reset.
  143. * Therefore only do power up at the first up device, and
  144. * power down at the last down device.
  145. */
  146. if (atomic_dec_return(&usb_pwr_ref) == 0)
  147. cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  148. }
  149. static struct usb_ehci_pdata cns3xxx_usb_ehci_pdata = {
  150. .power_on = csn3xxx_usb_power_on,
  151. .power_off = csn3xxx_usb_power_off,
  152. };
  153. static struct platform_device cns3xxx_usb_ehci_device = {
  154. .name = "ehci-platform",
  155. .num_resources = ARRAY_SIZE(cns3xxx_usb_ehci_resources),
  156. .resource = cns3xxx_usb_ehci_resources,
  157. .dev = {
  158. .dma_mask = &cns3xxx_usb_ehci_dma_mask,
  159. .coherent_dma_mask = DMA_BIT_MASK(32),
  160. .platform_data = &cns3xxx_usb_ehci_pdata,
  161. },
  162. };
  163. static struct resource cns3xxx_usb_ohci_resources[] = {
  164. [0] = {
  165. .start = CNS3XXX_USB_OHCI_BASE,
  166. .end = CNS3XXX_USB_OHCI_BASE + SZ_16M - 1,
  167. .flags = IORESOURCE_MEM,
  168. },
  169. [1] = {
  170. .start = IRQ_CNS3XXX_USB_OHCI,
  171. .flags = IORESOURCE_IRQ,
  172. },
  173. };
  174. static u64 cns3xxx_usb_ohci_dma_mask = DMA_BIT_MASK(32);
  175. static struct usb_ohci_pdata cns3xxx_usb_ohci_pdata = {
  176. .num_ports = 1,
  177. .power_on = csn3xxx_usb_power_on,
  178. .power_off = csn3xxx_usb_power_off,
  179. };
  180. static struct platform_device cns3xxx_usb_ohci_device = {
  181. .name = "ohci-platform",
  182. .num_resources = ARRAY_SIZE(cns3xxx_usb_ohci_resources),
  183. .resource = cns3xxx_usb_ohci_resources,
  184. .dev = {
  185. .dma_mask = &cns3xxx_usb_ohci_dma_mask,
  186. .coherent_dma_mask = DMA_BIT_MASK(32),
  187. .platform_data = &cns3xxx_usb_ohci_pdata,
  188. },
  189. };
  190. /*
  191. * Initialization
  192. */
  193. static struct platform_device *cns3420_pdevs[] __initdata = {
  194. &cns3420_nor_pdev,
  195. &cns3xxx_usb_ehci_device,
  196. &cns3xxx_usb_ohci_device,
  197. };
  198. static void __init cns3420_init(void)
  199. {
  200. cns3xxx_l2x0_init();
  201. platform_add_devices(cns3420_pdevs, ARRAY_SIZE(cns3420_pdevs));
  202. cns3xxx_ahci_init();
  203. cns3xxx_sdhci_init();
  204. pm_power_off = cns3xxx_power_off;
  205. }
  206. static struct map_desc cns3420_io_desc[] __initdata = {
  207. {
  208. .virtual = CNS3XXX_UART0_BASE_VIRT,
  209. .pfn = __phys_to_pfn(CNS3XXX_UART0_BASE),
  210. .length = SZ_4K,
  211. .type = MT_DEVICE,
  212. },
  213. };
  214. static void __init cns3420_map_io(void)
  215. {
  216. cns3xxx_map_io();
  217. iotable_init(cns3420_io_desc, ARRAY_SIZE(cns3420_io_desc));
  218. cns3420_early_serial_setup();
  219. }
  220. MACHINE_START(CNS3420VB, "Cavium Networks CNS3420 Validation Board")
  221. .atag_offset = 0x100,
  222. .map_io = cns3420_map_io,
  223. .init_irq = cns3xxx_init_irq,
  224. .init_time = cns3xxx_timer_init,
  225. .init_machine = cns3420_init,
  226. .init_late = cns3xxx_pcie_init_late,
  227. .restart = cns3xxx_restart,
  228. MACHINE_END