of-generic.c 4.0 KB

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