of-generic.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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;
  50. const char *method = NULL;
  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. for_each_of_cpu_node(np) {
  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. of_node_put(np);
  71. }
  72. pr_info("CPU enable method: %s\n", method);
  73. if (method)
  74. for (; m->method; m++)
  75. if (!strcmp(m->method, method)) {
  76. register_smp_ops(m->ops);
  77. return;
  78. }
  79. register_smp_ops(&dummy_smp_ops);
  80. }
  81. #else
  82. static void sh_of_smp_probe(void)
  83. {
  84. }
  85. #endif
  86. static void noop(void)
  87. {
  88. }
  89. static int noopi(void)
  90. {
  91. return 0;
  92. }
  93. static void __init sh_of_mem_reserve(void)
  94. {
  95. early_init_fdt_reserve_self();
  96. early_init_fdt_scan_reserved_mem();
  97. }
  98. static void __init sh_of_time_init(void)
  99. {
  100. pr_info("SH generic board support: scanning for clocksource devices\n");
  101. timer_probe();
  102. }
  103. static void __init sh_of_setup(char **cmdline_p)
  104. {
  105. struct device_node *root;
  106. board_time_init = sh_of_time_init;
  107. sh_mv.mv_name = "Unknown SH model";
  108. root = of_find_node_by_path("/");
  109. if (root) {
  110. of_property_read_string(root, "model", &sh_mv.mv_name);
  111. of_node_put(root);
  112. }
  113. sh_of_smp_probe();
  114. }
  115. static int sh_of_irq_demux(int irq)
  116. {
  117. /* FIXME: eventually this should not be used at all;
  118. * the interrupt controller should set_handle_irq(). */
  119. return irq;
  120. }
  121. static void __init sh_of_init_irq(void)
  122. {
  123. pr_info("SH generic board support: scanning for interrupt controllers\n");
  124. irqchip_init();
  125. }
  126. static int __init sh_of_clk_init(void)
  127. {
  128. #ifdef CONFIG_COMMON_CLK
  129. /* Disabled pending move to COMMON_CLK framework. */
  130. pr_info("SH generic board support: scanning for clk providers\n");
  131. of_clk_init(NULL);
  132. #endif
  133. return 0;
  134. }
  135. static struct sh_machine_vector __initmv sh_of_generic_mv = {
  136. .mv_setup = sh_of_setup,
  137. .mv_name = "devicetree", /* replaced by DT root's model */
  138. .mv_irq_demux = sh_of_irq_demux,
  139. .mv_init_irq = sh_of_init_irq,
  140. .mv_clk_init = sh_of_clk_init,
  141. .mv_mode_pins = noopi,
  142. .mv_mem_init = noop,
  143. .mv_mem_reserve = sh_of_mem_reserve,
  144. };
  145. struct sh_clk_ops;
  146. void __init arch_init_clk_ops(struct sh_clk_ops **ops, int idx)
  147. {
  148. }
  149. void __init plat_irq_setup(void)
  150. {
  151. }