platform.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. /*-----------------------BVCI Latency Unit -----------------------------*/
  24. #ifdef CONFIG_ARC_HAS_BVCI_LAT_UNIT
  25. int lat_cycles = CONFIG_BVCI_LAT_CYCLES;
  26. /* BVCI Bus Profiler: Latency Unit */
  27. static void __init setup_bvci_lat_unit(void)
  28. {
  29. #define MAX_BVCI_UNITS 12
  30. unsigned int i;
  31. unsigned int *base = (unsigned int *)BVCI_LAT_UNIT_BASE;
  32. const unsigned long units_req = CONFIG_BVCI_LAT_UNITS;
  33. const unsigned int REG_UNIT = 21;
  34. const unsigned int REG_VAL = 22;
  35. /*
  36. * There are multiple Latency Units corresponding to the many
  37. * interfaces of the system bus arbiter (both CPU side as well as
  38. * the peripheral side).
  39. *
  40. * Unit 0 - System Arb and Mem Controller - adds latency to all
  41. * memory trasactions
  42. * Unit 1 - I$ and System Bus
  43. * Unit 2 - D$ and System Bus
  44. * ..
  45. * Unit 12 - IDE Disk controller and System Bus
  46. *
  47. * The programmers model requires writing to lat_unit reg first
  48. * and then the latency value (cycles) to lat_value reg
  49. */
  50. if (CONFIG_BVCI_LAT_UNITS == 0) {
  51. writel(0, base + REG_UNIT);
  52. writel(lat_cycles, base + REG_VAL);
  53. pr_info("BVCI Latency for all Memory Transactions %d cycles\n",
  54. lat_cycles);
  55. } else {
  56. for_each_set_bit(i, &units_req, MAX_BVCI_UNITS) {
  57. writel(i + 1, base + REG_UNIT); /* loop is 0 based */
  58. writel(lat_cycles, base + REG_VAL);
  59. pr_info("BVCI Latency for Unit[%d] = %d cycles\n",
  60. (i + 1), lat_cycles);
  61. }
  62. }
  63. }
  64. #else
  65. static void __init setup_bvci_lat_unit(void)
  66. {
  67. }
  68. #endif
  69. /*----------------------- Platform Devices -----------------------------*/
  70. #if IS_ENABLED(CONFIG_SERIAL_ARC)
  71. static unsigned long arc_uart_info[] = {
  72. 0, /* uart->is_emulated (runtime @running_on_hw) */
  73. 0, /* uart->port.uartclk */
  74. 0, /* uart->baud */
  75. 0
  76. };
  77. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  78. /*
  79. * static platform data - but only for early serial
  80. * TBD: derive this from a special DT node
  81. */
  82. static struct resource arc_uart0_res[] = {
  83. {
  84. .start = UART0_BASE,
  85. .end = UART0_BASE + 0xFF,
  86. .flags = IORESOURCE_MEM,
  87. },
  88. {
  89. .start = UART0_IRQ,
  90. .end = UART0_IRQ,
  91. .flags = IORESOURCE_IRQ,
  92. },
  93. };
  94. static struct platform_device arc_uart0_dev = {
  95. .name = "arc-uart",
  96. .id = 0,
  97. .num_resources = ARRAY_SIZE(arc_uart0_res),
  98. .resource = arc_uart0_res,
  99. .dev = {
  100. .platform_data = &arc_uart_info,
  101. },
  102. };
  103. static struct platform_device *fpga_early_devs[] __initdata = {
  104. &arc_uart0_dev,
  105. };
  106. #endif /* CONFIG_SERIAL_ARC_CONSOLE */
  107. static void arc_fpga_serial_init(void)
  108. {
  109. /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */
  110. arc_uart_info[0] = !running_on_hw;
  111. arc_uart_info[1] = arc_get_core_freq();
  112. arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD;
  113. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  114. early_platform_add_devices(fpga_early_devs,
  115. ARRAY_SIZE(fpga_early_devs));
  116. /*
  117. * ARC console driver registers itself as an early platform driver
  118. * of class "earlyprintk".
  119. * Install it here, followed by probe of devices.
  120. * The installation here doesn't require earlyprintk in command line
  121. * To do so however, replace the lines below with
  122. * parse_early_param();
  123. * early_platform_driver_probe("earlyprintk", 1, 1);
  124. * ^^
  125. */
  126. early_platform_driver_register_all("earlyprintk");
  127. early_platform_driver_probe("earlyprintk", 1, 0);
  128. /*
  129. * This is to make sure that arc uart would be preferred console
  130. * despite one/more of following:
  131. * -command line lacked "console=ttyARC0" or
  132. * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever)
  133. * Note that this needs to be done after above early console is reg,
  134. * otherwise the early console never gets a chance to run.
  135. */
  136. add_preferred_console("ttyARC", 0, "115200");
  137. #endif /* CONFIG_SERIAL_ARC_CONSOLE */
  138. }
  139. #else /* !IS_ENABLED(CONFIG_SERIAL_ARC) */
  140. static void arc_fpga_serial_init(void)
  141. {
  142. }
  143. #endif
  144. static void __init plat_fpga_early_init(void)
  145. {
  146. pr_info("[plat-arcfpga]: registering early dev resources\n");
  147. setup_bvci_lat_unit();
  148. arc_fpga_serial_init();
  149. #ifdef CONFIG_SMP
  150. iss_model_init_early_smp();
  151. #endif
  152. }
  153. static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = {
  154. #if IS_ENABLED(CONFIG_SERIAL_ARC)
  155. OF_DEV_AUXDATA("snps,arc-uart", UART0_BASE, "arc-uart", arc_uart_info),
  156. #endif
  157. {}
  158. };
  159. static void __init plat_fpga_populate_dev(void)
  160. {
  161. pr_info("[plat-arcfpga]: registering device resources\n");
  162. /*
  163. * Traverses flattened DeviceTree - registering platform devices
  164. * complete with their resources
  165. */
  166. of_platform_populate(NULL, of_default_bus_match_table,
  167. plat_auxdata_lookup, NULL);
  168. }
  169. /*----------------------- Machine Descriptions ------------------------------
  170. *
  171. * Machine description is simply a set of platform/board specific callbacks
  172. * This is not directly related to DeviceTree based dynamic device creation,
  173. * however as part of early device tree scan, we also select the right
  174. * callback set, by matching the DT compatible name.
  175. */
  176. static const char *aa4_compat[] __initdata = {
  177. "snps,arc-angel4",
  178. NULL,
  179. };
  180. MACHINE_START(ANGEL4, "angel4")
  181. .dt_compat = aa4_compat,
  182. .init_early = plat_fpga_early_init,
  183. .init_machine = plat_fpga_populate_dev,
  184. .init_irq = plat_fpga_init_IRQ,
  185. #ifdef CONFIG_SMP
  186. .init_smp = iss_model_init_smp,
  187. #endif
  188. MACHINE_END
  189. static const char *ml509_compat[] __initdata = {
  190. "snps,arc-ml509",
  191. NULL,
  192. };
  193. MACHINE_START(ML509, "ml509")
  194. .dt_compat = ml509_compat,
  195. .init_early = plat_fpga_early_init,
  196. .init_machine = plat_fpga_populate_dev,
  197. .init_irq = plat_fpga_init_IRQ,
  198. #ifdef CONFIG_SMP
  199. .init_smp = iss_model_init_smp,
  200. #endif
  201. MACHINE_END
  202. static const char *nsimosci_compat[] __initdata = {
  203. "snps,nsimosci",
  204. NULL,
  205. };
  206. MACHINE_START(NSIMOSCI, "nsimosci")
  207. .dt_compat = nsimosci_compat,
  208. .init_early = NULL,
  209. .init_machine = plat_fpga_populate_dev,
  210. .init_irq = NULL,
  211. MACHINE_END