fsl_soc.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * FSL SoC setup code
  4. *
  5. * Maintained by Kumar Gala (see MAINTAINERS for contact information)
  6. *
  7. * 2006 (c) MontaVista Software, Inc.
  8. * Vitaly Bordug <[email protected]>
  9. */
  10. #include <linux/stddef.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/errno.h>
  14. #include <linux/major.h>
  15. #include <linux/delay.h>
  16. #include <linux/irq.h>
  17. #include <linux/export.h>
  18. #include <linux/device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/of.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/phy.h>
  23. #include <linux/spi/spi.h>
  24. #include <linux/fsl_devices.h>
  25. #include <linux/fs_enet_pd.h>
  26. #include <linux/fs_uart_pd.h>
  27. #include <linux/reboot.h>
  28. #include <linux/atomic.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/time.h>
  32. #include <asm/machdep.h>
  33. #include <sysdev/fsl_soc.h>
  34. #include <mm/mmu_decl.h>
  35. #include <asm/cpm2.h>
  36. #include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
  37. extern void init_fcc_ioports(struct fs_platform_info*);
  38. extern void init_fec_ioports(struct fs_platform_info*);
  39. extern void init_smc_ioports(struct fs_uart_platform_info*);
  40. static phys_addr_t immrbase = -1;
  41. phys_addr_t get_immrbase(void)
  42. {
  43. struct device_node *soc;
  44. if (immrbase != -1)
  45. return immrbase;
  46. soc = of_find_node_by_type(NULL, "soc");
  47. if (soc) {
  48. int size;
  49. u32 naddr;
  50. const __be32 *prop = of_get_property(soc, "#address-cells", &size);
  51. if (prop && size == 4)
  52. naddr = be32_to_cpup(prop);
  53. else
  54. naddr = 2;
  55. prop = of_get_property(soc, "ranges", &size);
  56. if (prop)
  57. immrbase = of_translate_address(soc, prop + naddr);
  58. of_node_put(soc);
  59. }
  60. return immrbase;
  61. }
  62. EXPORT_SYMBOL(get_immrbase);
  63. u32 fsl_get_sys_freq(void)
  64. {
  65. static u32 sysfreq = -1;
  66. struct device_node *soc;
  67. if (sysfreq != -1)
  68. return sysfreq;
  69. soc = of_find_node_by_type(NULL, "soc");
  70. if (!soc)
  71. return -1;
  72. of_property_read_u32(soc, "clock-frequency", &sysfreq);
  73. if (sysfreq == -1 || !sysfreq)
  74. of_property_read_u32(soc, "bus-frequency", &sysfreq);
  75. of_node_put(soc);
  76. return sysfreq;
  77. }
  78. EXPORT_SYMBOL(fsl_get_sys_freq);
  79. #if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
  80. u32 get_brgfreq(void)
  81. {
  82. static u32 brgfreq = -1;
  83. struct device_node *node;
  84. if (brgfreq != -1)
  85. return brgfreq;
  86. node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
  87. if (node) {
  88. of_property_read_u32(node, "clock-frequency", &brgfreq);
  89. of_node_put(node);
  90. return brgfreq;
  91. }
  92. /* Legacy device binding -- will go away when no users are left. */
  93. node = of_find_node_by_type(NULL, "cpm");
  94. if (!node)
  95. node = of_find_compatible_node(NULL, NULL, "fsl,qe");
  96. if (!node)
  97. node = of_find_node_by_type(NULL, "qe");
  98. if (node) {
  99. of_property_read_u32(node, "brg-frequency", &brgfreq);
  100. if (brgfreq == -1 || !brgfreq)
  101. if (!of_property_read_u32(node, "bus-frequency",
  102. &brgfreq))
  103. brgfreq /= 2;
  104. of_node_put(node);
  105. }
  106. return brgfreq;
  107. }
  108. EXPORT_SYMBOL(get_brgfreq);
  109. u32 get_baudrate(void)
  110. {
  111. static u32 fs_baudrate = -1;
  112. struct device_node *node;
  113. if (fs_baudrate != -1)
  114. return fs_baudrate;
  115. node = of_find_node_by_type(NULL, "serial");
  116. if (node) {
  117. of_property_read_u32(node, "current-speed", &fs_baudrate);
  118. of_node_put(node);
  119. }
  120. return fs_baudrate;
  121. }
  122. EXPORT_SYMBOL(get_baudrate);
  123. #endif /* CONFIG_CPM2 */
  124. #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
  125. static __be32 __iomem *rstcr;
  126. static int fsl_rstcr_restart(struct notifier_block *this,
  127. unsigned long mode, void *cmd)
  128. {
  129. local_irq_disable();
  130. /* set reset control register */
  131. out_be32(rstcr, 0x2); /* HRESET_REQ */
  132. return NOTIFY_DONE;
  133. }
  134. static int __init setup_rstcr(void)
  135. {
  136. struct device_node *np;
  137. static struct notifier_block restart_handler = {
  138. .notifier_call = fsl_rstcr_restart,
  139. .priority = 128,
  140. };
  141. for_each_node_by_name(np, "global-utilities") {
  142. if ((of_get_property(np, "fsl,has-rstcr", NULL))) {
  143. rstcr = of_iomap(np, 0) + 0xb0;
  144. if (!rstcr) {
  145. printk (KERN_ERR "Error: reset control "
  146. "register not mapped!\n");
  147. } else {
  148. register_restart_handler(&restart_handler);
  149. }
  150. break;
  151. }
  152. }
  153. of_node_put(np);
  154. return 0;
  155. }
  156. arch_initcall(setup_rstcr);
  157. #endif
  158. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  159. struct platform_diu_data_ops diu_ops;
  160. EXPORT_SYMBOL(diu_ops);
  161. #endif
  162. #ifdef CONFIG_EPAPR_PARAVIRT
  163. /*
  164. * Restart the current partition
  165. *
  166. * This function should be assigned to the ppc_md.restart function pointer,
  167. * to initiate a partition restart when we're running under the Freescale
  168. * hypervisor.
  169. */
  170. void __noreturn fsl_hv_restart(char *cmd)
  171. {
  172. pr_info("hv restart\n");
  173. fh_partition_restart(-1);
  174. while (1) ;
  175. }
  176. /*
  177. * Halt the current partition
  178. *
  179. * This function should be assigned to the pm_power_off and ppc_md.halt
  180. * function pointers, to shut down the partition when we're running under
  181. * the Freescale hypervisor.
  182. */
  183. void __noreturn fsl_hv_halt(void)
  184. {
  185. pr_info("hv exit\n");
  186. fh_partition_stop(-1);
  187. while (1) ;
  188. }
  189. #endif