init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (C) 2016 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #include <linux/clk.h>
  11. #include <linux/clk-provider.h>
  12. #include <linux/clocksource.h>
  13. #include <linux/init.h>
  14. #include <linux/irqchip.h>
  15. #include <linux/of_fdt.h>
  16. #include <linux/of_platform.h>
  17. #include <asm/fw/fw.h>
  18. #include <asm/irq_cpu.h>
  19. #include <asm/machine.h>
  20. #include <asm/mips-cpc.h>
  21. #include <asm/prom.h>
  22. #include <asm/smp-ops.h>
  23. #include <asm/time.h>
  24. static __initdata const void *fdt;
  25. static __initdata const struct mips_machine *mach;
  26. static __initdata const void *mach_match_data;
  27. void __init prom_init(void)
  28. {
  29. plat_get_fdt();
  30. BUG_ON(!fdt);
  31. }
  32. void __init *plat_get_fdt(void)
  33. {
  34. const struct mips_machine *check_mach;
  35. const struct of_device_id *match;
  36. if (fdt)
  37. /* Already set up */
  38. return (void *)fdt;
  39. if ((fw_arg0 == -2) && !fdt_check_header((void *)fw_arg1)) {
  40. /*
  41. * We booted using the UHI boot protocol, so we have been
  42. * provided with the appropriate device tree for the board.
  43. * Make use of it & search for any machine struct based upon
  44. * the root compatible string.
  45. */
  46. fdt = (void *)fw_arg1;
  47. for_each_mips_machine(check_mach) {
  48. match = mips_machine_is_compatible(check_mach, fdt);
  49. if (match) {
  50. mach = check_mach;
  51. mach_match_data = match->data;
  52. break;
  53. }
  54. }
  55. } else if (IS_ENABLED(CONFIG_LEGACY_BOARDS)) {
  56. /*
  57. * We weren't booted using the UHI boot protocol, but do
  58. * support some number of boards with legacy boot protocols.
  59. * Attempt to find the right one.
  60. */
  61. for_each_mips_machine(check_mach) {
  62. if (!check_mach->detect)
  63. continue;
  64. if (!check_mach->detect())
  65. continue;
  66. mach = check_mach;
  67. }
  68. /*
  69. * If we don't recognise the machine then we can't continue, so
  70. * die here.
  71. */
  72. BUG_ON(!mach);
  73. /* Retrieve the machine's FDT */
  74. fdt = mach->fdt;
  75. }
  76. return (void *)fdt;
  77. }
  78. void __init plat_mem_setup(void)
  79. {
  80. if (mach && mach->fixup_fdt)
  81. fdt = mach->fixup_fdt(fdt, mach_match_data);
  82. strlcpy(arcs_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  83. __dt_setup_arch((void *)fdt);
  84. }
  85. void __init device_tree_init(void)
  86. {
  87. int err;
  88. unflatten_and_copy_device_tree();
  89. mips_cpc_probe();
  90. err = register_cps_smp_ops();
  91. if (err)
  92. err = register_up_smp_ops();
  93. }
  94. void __init plat_time_init(void)
  95. {
  96. struct device_node *np;
  97. struct clk *clk;
  98. of_clk_init(NULL);
  99. if (!cpu_has_counter) {
  100. mips_hpt_frequency = 0;
  101. } else if (mach && mach->measure_hpt_freq) {
  102. mips_hpt_frequency = mach->measure_hpt_freq();
  103. } else {
  104. np = of_get_cpu_node(0, NULL);
  105. if (!np) {
  106. pr_err("Failed to get CPU node\n");
  107. return;
  108. }
  109. clk = of_clk_get(np, 0);
  110. if (IS_ERR(clk)) {
  111. pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk));
  112. return;
  113. }
  114. mips_hpt_frequency = clk_get_rate(clk);
  115. clk_put(clk);
  116. switch (boot_cpu_type()) {
  117. case CPU_20KC:
  118. case CPU_25KF:
  119. /* The counter runs at the CPU clock rate */
  120. break;
  121. default:
  122. /* The counter runs at half the CPU clock rate */
  123. mips_hpt_frequency /= 2;
  124. break;
  125. }
  126. }
  127. clocksource_probe();
  128. }
  129. void __init arch_init_irq(void)
  130. {
  131. struct device_node *intc_node;
  132. intc_node = of_find_compatible_node(NULL, NULL,
  133. "mti,cpu-interrupt-controller");
  134. if (!cpu_has_veic && !intc_node)
  135. mips_cpu_irq_init();
  136. irqchip_init();
  137. }
  138. static int __init publish_devices(void)
  139. {
  140. if (!of_have_populated_dt())
  141. panic("Device-tree not present");
  142. if (of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL))
  143. panic("Failed to populate DT");
  144. return 0;
  145. }
  146. arch_initcall(publish_devices);
  147. void __init prom_free_prom_memory(void)
  148. {
  149. }