platform.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 itself as an early platform driver
  72. * of class "earlyprintk".
  73. * Install it here, followed by probe of devices.
  74. * The installation here doesn't require earlyprintk in command line
  75. * To do so however, replace the lines below with
  76. * parse_early_param();
  77. * early_platform_driver_probe("earlyprintk", 1, 1);
  78. * ^^
  79. */
  80. early_platform_driver_register_all("earlyprintk");
  81. early_platform_driver_probe("earlyprintk", 1, 0);
  82. /*
  83. * This is to make sure that arc uart would be preferred console
  84. * despite one/more of following:
  85. * -command line lacked "console=ttyARC0" or
  86. * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever)
  87. * Note that this needs to be done after above early console is reg,
  88. * otherwise the early console never gets a chance to run.
  89. */
  90. add_preferred_console("ttyARC", 0, "115200");
  91. #endif /* CONFIG_SERIAL_ARC_CONSOLE */
  92. }
  93. #else /* !IS_ENABLED(CONFIG_SERIAL_ARC) */
  94. static void arc_fpga_serial_init(void)
  95. {
  96. }
  97. #endif
  98. static void __init plat_fpga_early_init(void)
  99. {
  100. pr_info("[plat-arcfpga]: registering early dev resources\n");
  101. arc_fpga_serial_init();
  102. #ifdef CONFIG_ISS_SMP_EXTN
  103. iss_model_init_early_smp();
  104. #endif
  105. }
  106. static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = {
  107. #if IS_ENABLED(CONFIG_SERIAL_ARC)
  108. OF_DEV_AUXDATA("snps,arc-uart", UART0_BASE, "arc-uart", arc_uart_info),
  109. #endif
  110. {}
  111. };
  112. static void __init plat_fpga_populate_dev(void)
  113. {
  114. pr_info("[plat-arcfpga]: registering device resources\n");
  115. /*
  116. * Traverses flattened DeviceTree - registering platform devices
  117. * complete with their resources
  118. */
  119. of_platform_populate(NULL, of_default_bus_match_table,
  120. plat_auxdata_lookup, NULL);
  121. }
  122. /*----------------------- Machine Descriptions ------------------------------
  123. *
  124. * Machine description is simply a set of platform/board specific callbacks
  125. * This is not directly related to DeviceTree based dynamic device creation,
  126. * however as part of early device tree scan, we also select the right
  127. * callback set, by matching the DT compatible name.
  128. */
  129. static const char *aa4_compat[] __initconst = {
  130. "snps,arc-angel4",
  131. NULL,
  132. };
  133. MACHINE_START(ANGEL4, "angel4")
  134. .dt_compat = aa4_compat,
  135. .init_early = plat_fpga_early_init,
  136. .init_machine = plat_fpga_populate_dev,
  137. .init_irq = plat_fpga_init_IRQ,
  138. #ifdef CONFIG_ISS_SMP_EXTN
  139. .init_smp = iss_model_init_smp,
  140. #endif
  141. MACHINE_END
  142. static const char *ml509_compat[] __initconst = {
  143. "snps,arc-ml509",
  144. NULL,
  145. };
  146. MACHINE_START(ML509, "ml509")
  147. .dt_compat = ml509_compat,
  148. .init_early = plat_fpga_early_init,
  149. .init_machine = plat_fpga_populate_dev,
  150. .init_irq = plat_fpga_init_IRQ,
  151. #ifdef CONFIG_SMP
  152. .init_smp = iss_model_init_smp,
  153. #endif
  154. MACHINE_END
  155. static const char *nsimosci_compat[] __initconst = {
  156. "snps,nsimosci",
  157. NULL,
  158. };
  159. MACHINE_START(NSIMOSCI, "nsimosci")
  160. .dt_compat = nsimosci_compat,
  161. .init_early = NULL,
  162. .init_machine = plat_fpga_populate_dev,
  163. .init_irq = NULL,
  164. MACHINE_END