cns3420vb.c 6.1 KB

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