platform.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/irq.h>
  19. #include <asm/clk.h>
  20. #include <plat/memmap.h>
  21. /*-----------------------BVCI Latency Unit -----------------------------*/
  22. #ifdef CONFIG_ARC_HAS_BVCI_LAT_UNIT
  23. int lat_cycles = CONFIG_BVCI_LAT_CYCLES;
  24. /* BVCI Bus Profiler: Latency Unit */
  25. static void __init setup_bvci_lat_unit(void)
  26. {
  27. #define MAX_BVCI_UNITS 12
  28. unsigned int i;
  29. unsigned int *base = (unsigned int *)BVCI_LAT_UNIT_BASE;
  30. const unsigned long units_req = CONFIG_BVCI_LAT_UNITS;
  31. const unsigned int REG_UNIT = 21;
  32. const unsigned int REG_VAL = 22;
  33. /*
  34. * There are multiple Latency Units corresponding to the many
  35. * interfaces of the system bus arbiter (both CPU side as well as
  36. * the peripheral side).
  37. *
  38. * Unit 0 - System Arb and Mem Controller - adds latency to all
  39. * memory trasactions
  40. * Unit 1 - I$ and System Bus
  41. * Unit 2 - D$ and System Bus
  42. * ..
  43. * Unit 12 - IDE Disk controller and System Bus
  44. *
  45. * The programmers model requires writing to lat_unit reg first
  46. * and then the latency value (cycles) to lat_value reg
  47. */
  48. if (CONFIG_BVCI_LAT_UNITS == 0) {
  49. writel(0, base + REG_UNIT);
  50. writel(lat_cycles, base + REG_VAL);
  51. pr_info("BVCI Latency for all Memory Transactions %d cycles\n",
  52. lat_cycles);
  53. } else {
  54. for_each_set_bit(i, &units_req, MAX_BVCI_UNITS) {
  55. writel(i + 1, base + REG_UNIT); /* loop is 0 based */
  56. writel(lat_cycles, base + REG_VAL);
  57. pr_info("BVCI Latency for Unit[%d] = %d cycles\n",
  58. (i + 1), lat_cycles);
  59. }
  60. }
  61. }
  62. #else
  63. static void __init setup_bvci_lat_unit(void)
  64. {
  65. }
  66. #endif
  67. /*----------------------- Platform Devices -----------------------------*/
  68. static unsigned long arc_uart_info[] = {
  69. 0, /* uart->is_emulated (runtime @running_on_hw) */
  70. 0, /* uart->port.uartclk */
  71. 0, /* uart->baud */
  72. 0
  73. };
  74. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  75. /*
  76. * static platform data - but only for early serial
  77. * TBD: derive this from a special DT node
  78. */
  79. static struct resource arc_uart0_res[] = {
  80. {
  81. .start = UART0_BASE,
  82. .end = UART0_BASE + 0xFF,
  83. .flags = IORESOURCE_MEM,
  84. },
  85. {
  86. .start = UART0_IRQ,
  87. .end = UART0_IRQ,
  88. .flags = IORESOURCE_IRQ,
  89. },
  90. };
  91. static struct platform_device arc_uart0_dev = {
  92. .name = "arc-uart",
  93. .id = 0,
  94. .num_resources = ARRAY_SIZE(arc_uart0_res),
  95. .resource = arc_uart0_res,
  96. .dev = {
  97. .platform_data = &arc_uart_info,
  98. },
  99. };
  100. static struct platform_device *fpga_early_devs[] __initdata = {
  101. &arc_uart0_dev,
  102. };
  103. #endif
  104. static void arc_fpga_serial_init(void)
  105. {
  106. /* To let driver workaround ISS bug: baudh Reg can't be set to 0 */
  107. arc_uart_info[0] = !running_on_hw;
  108. arc_uart_info[1] = arc_get_core_freq();
  109. arc_uart_info[2] = CONFIG_ARC_SERIAL_BAUD;
  110. #if defined(CONFIG_SERIAL_ARC_CONSOLE)
  111. early_platform_add_devices(fpga_early_devs,
  112. ARRAY_SIZE(fpga_early_devs));
  113. /*
  114. * ARC console driver registers itself as an early platform driver
  115. * of class "earlyprintk".
  116. * Install it here, followed by probe of devices.
  117. * The installation here doesn't require earlyprintk in command line
  118. * To do so however, replace the lines below with
  119. * parse_early_param();
  120. * early_platform_driver_probe("earlyprintk", 1, 1);
  121. * ^^
  122. */
  123. early_platform_driver_register_all("earlyprintk");
  124. early_platform_driver_probe("earlyprintk", 1, 0);
  125. /*
  126. * This is to make sure that arc uart would be preferred console
  127. * despite one/more of following:
  128. * -command line lacked "console=ttyARC0" or
  129. * -CONFIG_VT_CONSOLE was enabled (for no reason whatsoever)
  130. * Note that this needs to be done after above early console is reg,
  131. * otherwise the early console never gets a chance to run.
  132. */
  133. add_preferred_console("ttyARC", 0, "115200");
  134. #endif
  135. }
  136. /*
  137. * Early Platform Initialization called from setup_arch()
  138. */
  139. void __init arc_platform_early_init(void)
  140. {
  141. pr_info("[plat-arcfpga]: registering early dev resources\n");
  142. setup_bvci_lat_unit();
  143. arc_fpga_serial_init();
  144. }
  145. static struct of_dev_auxdata plat_auxdata_lookup[] __initdata = {
  146. #if defined(CONFIG_SERIAL_ARC) || defined(CONFIG_SERIAL_ARC_MODULE)
  147. OF_DEV_AUXDATA("snps,arc-uart", UART0_BASE, "arc-uart", arc_uart_info),
  148. #endif
  149. {}
  150. };
  151. int __init fpga_plat_init(void)
  152. {
  153. pr_info("[plat-arcfpga]: registering device resources\n");
  154. /*
  155. * Traverses flattened DeviceTree - registering platform devices
  156. * complete with their resources
  157. */
  158. of_platform_populate(NULL, of_default_bus_match_table,
  159. plat_auxdata_lookup, NULL);
  160. return 0;
  161. }
  162. arch_initcall(fpga_plat_init);