of-generic.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SH generic board support, using device tree
  4. *
  5. * Copyright (C) 2015-2016 Smart Energy Instruments, Inc.
  6. */
  7. #include <linux/of.h>
  8. #include <linux/of_clk.h>
  9. #include <linux/of_fdt.h>
  10. #include <linux/clocksource.h>
  11. #include <linux/irqchip.h>
  12. #include <asm/clock.h>
  13. #include <asm/machvec.h>
  14. #include <asm/rtc.h>
  15. #ifdef CONFIG_SMP
  16. static void dummy_smp_setup(void)
  17. {
  18. }
  19. static void dummy_prepare_cpus(unsigned int max_cpus)
  20. {
  21. }
  22. static void dummy_start_cpu(unsigned int cpu, unsigned long entry_point)
  23. {
  24. }
  25. static unsigned int dummy_smp_processor_id(void)
  26. {
  27. return 0;
  28. }
  29. static void dummy_send_ipi(unsigned int cpu, unsigned int message)
  30. {
  31. }
  32. static struct plat_smp_ops dummy_smp_ops = {
  33. .smp_setup = dummy_smp_setup,
  34. .prepare_cpus = dummy_prepare_cpus,
  35. .start_cpu = dummy_start_cpu,
  36. .smp_processor_id = dummy_smp_processor_id,
  37. .send_ipi = dummy_send_ipi,
  38. .cpu_die = native_cpu_die,
  39. .cpu_disable = native_cpu_disable,
  40. .play_dead = native_play_dead,
  41. };
  42. extern const struct of_cpu_method __cpu_method_of_table[];
  43. const struct of_cpu_method __cpu_method_of_table_sentinel
  44. __section("__cpu_method_of_table_end");
  45. static void sh_of_smp_probe(void)
  46. {
  47. struct device_node *np;
  48. const char *method = NULL;
  49. const struct of_cpu_method *m = __cpu_method_of_table;
  50. pr_info("SH generic board support: scanning for cpus\n");
  51. init_cpu_possible(cpumask_of(0));
  52. for_each_of_cpu_node(np) {
  53. u64 id = of_get_cpu_hwid(np, 0);
  54. if (id < NR_CPUS) {
  55. if (!method)
  56. of_property_read_string(np, "enable-method", &method);
  57. set_cpu_possible(id, true);
  58. set_cpu_present(id, true);
  59. __cpu_number_map[id] = id;
  60. __cpu_logical_map[id] = id;
  61. }
  62. }
  63. if (!method) {
  64. np = of_find_node_by_name(NULL, "cpus");
  65. of_property_read_string(np, "enable-method", &method);
  66. of_node_put(np);
  67. }
  68. pr_info("CPU enable method: %s\n", method);
  69. if (method)
  70. for (; m->method; m++)
  71. if (!strcmp(m->method, method)) {
  72. register_smp_ops(m->ops);
  73. return;
  74. }
  75. register_smp_ops(&dummy_smp_ops);
  76. }
  77. #else
  78. static void sh_of_smp_probe(void)
  79. {
  80. }
  81. #endif
  82. static void noop(void)
  83. {
  84. }
  85. static int noopi(void)
  86. {
  87. return 0;
  88. }
  89. static void __init sh_of_mem_reserve(void)
  90. {
  91. early_init_fdt_reserve_self();
  92. early_init_fdt_scan_reserved_mem();
  93. }
  94. static void __init sh_of_setup(char **cmdline_p)
  95. {
  96. struct device_node *root;
  97. sh_mv.mv_name = "Unknown SH model";
  98. root = of_find_node_by_path("/");
  99. if (root) {
  100. of_property_read_string(root, "model", &sh_mv.mv_name);
  101. of_node_put(root);
  102. }
  103. sh_of_smp_probe();
  104. }
  105. static int sh_of_irq_demux(int irq)
  106. {
  107. /* FIXME: eventually this should not be used at all;
  108. * the interrupt controller should set_handle_irq(). */
  109. return irq;
  110. }
  111. static void __init sh_of_init_irq(void)
  112. {
  113. pr_info("SH generic board support: scanning for interrupt controllers\n");
  114. irqchip_init();
  115. }
  116. static int __init sh_of_clk_init(void)
  117. {
  118. #ifdef CONFIG_COMMON_CLK
  119. /* Disabled pending move to COMMON_CLK framework. */
  120. pr_info("SH generic board support: scanning for clk providers\n");
  121. of_clk_init(NULL);
  122. #endif
  123. return 0;
  124. }
  125. static struct sh_machine_vector __initmv sh_of_generic_mv = {
  126. .mv_setup = sh_of_setup,
  127. .mv_name = "devicetree", /* replaced by DT root's model */
  128. .mv_irq_demux = sh_of_irq_demux,
  129. .mv_init_irq = sh_of_init_irq,
  130. .mv_clk_init = sh_of_clk_init,
  131. .mv_mode_pins = noopi,
  132. .mv_mem_init = noop,
  133. .mv_mem_reserve = sh_of_mem_reserve,
  134. };
  135. struct sh_clk_ops;
  136. void __init __weak arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  137. {
  138. }
  139. void __init __weak plat_irq_setup(void)
  140. {
  141. }