of-generic.c 3.5 KB

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