platform.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * ARC FPGA Platform support code
  3. *
  4. * Copyright (C) 2012 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/init.h>
  12. #include <linux/device.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/io.h>
  15. #include <linux/console.h>
  16. #include <linux/of_platform.h>
  17. #include <asm/setup.h>
  18. #include <asm/clk.h>
  19. #include <asm/mach_desc.h>
  20. #include <plat/memmap.h>
  21. #include <plat/smp.h>
  22. #include <plat/irq.h>
  23. /*----------------------- Platform Devices -----------------------------*/
  24. #if IS_ENABLED(CONFIG_SERIAL_ARC)
  25. static unsigned long arc_uart_info[] = {
  26. 0, /* uart->is_emulated (runtime @running_on_hw) */
  27. 0, /* uart->port.uartclk */
  28. 0, /* uart->baud */
  29. 0
  30. };
  31. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  32. /*
  33. * static platform data - but only for early serial
  34. * TBD: derive this from a special DT node
  35. */
  36. static struct resource arc_uart0_res[] = {
  37. {
  38. .start = UART0_BASE,
  39. .end = UART0_BASE + 0xFF,
  40. .flags = IORESOURCE_MEM,
  41. },
  42. {
  43. .start = UART0_IRQ,
  44. .end = UART0_IRQ,
  45. .flags = IORESOURCE_IRQ,
  46. },
  47. };
  48. static struct platform_device arc_uart0_dev = {
  49. .name = "arc-uart",
  50. .id = 0,
  51. .num_resources = ARRAY_SIZE(arc_uart0_res),
  52. .resource = arc_uart0_res,
  53. .dev = {
  54. .platform_data = &arc_uart_info,
  55. },
  56. };
  57. static struct platform_device *fpga_early_devs[] __initdata = {
  58. &arc_uart0_dev,
  59. };
  60. #endif /* CONFIG_SERIAL_ARC_CONSOLE */
  61. static void arc_fpga_serial_init(void)
  62. {
  63. /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */
  64. arc_uart_info[0] = !running_on_hw;
  65. arc_uart_info[1] = arc_get_core_freq();
  66. arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD;
  67. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  68. early_platform_add_devices(fpga_early_devs,
  69. ARRAY_SIZE(fpga_early_devs));
  70. /*
  71. * ARC console driver registers (build time) as an early platform driver
  72. * of class "earlyprintk". However it needs explicit cmdline toggle
  73. * "earlyprintk=ttyARC0" to be successfuly runtime registered.
  74. * Otherwise the early probe below fails to find the driver
  75. */
  76. early_platform_driver_probe("earlyprintk", 1, 0);
  77. /*
  78. * This is to make sure that arc uart would be preferred console
  79. * despite one/more of following:
  80. * -command line lacked "console=ttyARC0" or
  81. * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever)
  82. * Note that this needs to be done after above early console is reg,
  83. * otherwise the early console never gets a chance to run.
  84. */
  85. add_preferred_console("ttyARC", 0, "115200");
  86. #endif /* CONFIG_SERIAL_ARC_CONSOLE */
  87. }
  88. #else /* !IS_ENABLED(CONFIG_SERIAL_ARC) */
  89. static void arc_fpga_serial_init(void)
  90. {
  91. }
  92. #endif
  93. static void __init plat_fpga_early_init(void)
  94. {
  95. pr_info("[plat-arcfpga]: registering early dev resources\n");
  96. arc_fpga_serial_init();
  97. #ifdef CONFIG_ISS_SMP_EXTN
  98. iss_model_init_early_smp();
  99. #endif
  100. }
  101. static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = {
  102. #if IS_ENABLED(CONFIG_SERIAL_ARC)
  103. OF_DEV_AUXDATA("snps,arc-uart", UART0_BASE, "arc-uart", arc_uart_info),
  104. #endif
  105. {}
  106. };
  107. static void __init plat_fpga_populate_dev(void)
  108. {
  109. pr_info("[plat-arcfpga]: registering device resources\n");
  110. /*
  111. * Traverses flattened DeviceTree - registering platform devices
  112. * complete with their resources
  113. */
  114. of_platform_populate(NULL, of_default_bus_match_table,
  115. plat_auxdata_lookup, NULL);
  116. }
  117. /*----------------------- Machine Descriptions ------------------------------
  118. *
  119. * Machine description is simply a set of platform/board specific callbacks
  120. * This is not directly related to DeviceTree based dynamic device creation,
  121. * however as part of early device tree scan, we also select the right
  122. * callback set, by matching the DT compatible name.
  123. */
  124. static const char *aa4_compat[] __initconst = {
  125. "snps,arc-angel4",
  126. NULL,
  127. };
  128. MACHINE_START(ANGEL4, "angel4")
  129. .dt_compat = aa4_compat,
  130. .init_early = plat_fpga_early_init,
  131. .init_machine = plat_fpga_populate_dev,
  132. .init_irq = plat_fpga_init_IRQ,
  133. #ifdef CONFIG_ISS_SMP_EXTN
  134. .init_smp = iss_model_init_smp,
  135. #endif
  136. MACHINE_END
  137. static const char *ml509_compat[] __initconst = {
  138. "snps,arc-ml509",
  139. NULL,
  140. };
  141. MACHINE_START(ML509, "ml509")
  142. .dt_compat = ml509_compat,
  143. .init_early = plat_fpga_early_init,
  144. .init_machine = plat_fpga_populate_dev,
  145. .init_irq = plat_fpga_init_IRQ,
  146. #ifdef CONFIG_SMP
  147. .init_smp = iss_model_init_smp,
  148. #endif
  149. MACHINE_END
  150. static const char *nsimosci_compat[] __initconst = {
  151. "snps,nsimosci",
  152. NULL,
  153. };
  154. MACHINE_START(NSIMOSCI, "nsimosci")
  155. .dt_compat = nsimosci_compat,
  156. .init_early = NULL,
  157. .init_machine = plat_fpga_populate_dev,
  158. .init_irq = NULL,
  159. MACHINE_END