/arch/powerpc/sysdev/fsl_soc.c

http://github.com/mirrors/linux · C · 232 lines · 165 code · 42 blank · 25 comment · 34 complexity · 30a3e7b6a46153827624f3479c7872f3 MD5 · raw file

  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 <vbordug@ru.mvista.com>
  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/prom.h>
  33. #include <asm/machdep.h>
  34. #include <sysdev/fsl_soc.h>
  35. #include <mm/mmu_decl.h>
  36. #include <asm/cpm2.h>
  37. #include <asm/fsl_hcalls.h> /* For the Freescale hypervisor */
  38. extern void init_fcc_ioports(struct fs_platform_info*);
  39. extern void init_fec_ioports(struct fs_platform_info*);
  40. extern void init_smc_ioports(struct fs_uart_platform_info*);
  41. static phys_addr_t immrbase = -1;
  42. phys_addr_t get_immrbase(void)
  43. {
  44. struct device_node *soc;
  45. if (immrbase != -1)
  46. return immrbase;
  47. soc = of_find_node_by_type(NULL, "soc");
  48. if (soc) {
  49. int size;
  50. u32 naddr;
  51. const __be32 *prop = of_get_property(soc, "#address-cells", &size);
  52. if (prop && size == 4)
  53. naddr = be32_to_cpup(prop);
  54. else
  55. naddr = 2;
  56. prop = of_get_property(soc, "ranges", &size);
  57. if (prop)
  58. immrbase = of_translate_address(soc, prop + naddr);
  59. of_node_put(soc);
  60. }
  61. return immrbase;
  62. }
  63. EXPORT_SYMBOL(get_immrbase);
  64. u32 fsl_get_sys_freq(void)
  65. {
  66. static u32 sysfreq = -1;
  67. struct device_node *soc;
  68. if (sysfreq != -1)
  69. return sysfreq;
  70. soc = of_find_node_by_type(NULL, "soc");
  71. if (!soc)
  72. return -1;
  73. of_property_read_u32(soc, "clock-frequency", &sysfreq);
  74. if (sysfreq == -1 || !sysfreq)
  75. of_property_read_u32(soc, "bus-frequency", &sysfreq);
  76. of_node_put(soc);
  77. return sysfreq;
  78. }
  79. EXPORT_SYMBOL(fsl_get_sys_freq);
  80. #if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
  81. u32 get_brgfreq(void)
  82. {
  83. static u32 brgfreq = -1;
  84. struct device_node *node;
  85. if (brgfreq != -1)
  86. return brgfreq;
  87. node = of_find_compatible_node(NULL, NULL, "fsl,cpm-brg");
  88. if (node) {
  89. of_property_read_u32(node, "clock-frequency", &brgfreq);
  90. of_node_put(node);
  91. return brgfreq;
  92. }
  93. /* Legacy device binding -- will go away when no users are left. */
  94. node = of_find_node_by_type(NULL, "cpm");
  95. if (!node)
  96. node = of_find_compatible_node(NULL, NULL, "fsl,qe");
  97. if (!node)
  98. node = of_find_node_by_type(NULL, "qe");
  99. if (node) {
  100. of_property_read_u32(node, "brg-frequency", &brgfreq);
  101. if (brgfreq == -1 || !brgfreq)
  102. if (!of_property_read_u32(node, "bus-frequency",
  103. &brgfreq))
  104. brgfreq /= 2;
  105. of_node_put(node);
  106. }
  107. return brgfreq;
  108. }
  109. EXPORT_SYMBOL(get_brgfreq);
  110. u32 get_baudrate(void)
  111. {
  112. static u32 fs_baudrate = -1;
  113. struct device_node *node;
  114. if (fs_baudrate != -1)
  115. return fs_baudrate;
  116. node = of_find_node_by_type(NULL, "serial");
  117. if (node) {
  118. of_property_read_u32(node, "current-speed", &fs_baudrate);
  119. of_node_put(node);
  120. }
  121. return fs_baudrate;
  122. }
  123. EXPORT_SYMBOL(get_baudrate);
  124. #endif /* CONFIG_CPM2 */
  125. #if defined(CONFIG_FSL_SOC_BOOKE) || defined(CONFIG_PPC_86xx)
  126. static __be32 __iomem *rstcr;
  127. static int fsl_rstcr_restart(struct notifier_block *this,
  128. unsigned long mode, void *cmd)
  129. {
  130. local_irq_disable();
  131. /* set reset control register */
  132. out_be32(rstcr, 0x2); /* HRESET_REQ */
  133. return NOTIFY_DONE;
  134. }
  135. static int __init setup_rstcr(void)
  136. {
  137. struct device_node *np;
  138. static struct notifier_block restart_handler = {
  139. .notifier_call = fsl_rstcr_restart,
  140. .priority = 128,
  141. };
  142. for_each_node_by_name(np, "global-utilities") {
  143. if ((of_get_property(np, "fsl,has-rstcr", NULL))) {
  144. rstcr = of_iomap(np, 0) + 0xb0;
  145. if (!rstcr) {
  146. printk (KERN_ERR "Error: reset control "
  147. "register not mapped!\n");
  148. } else {
  149. register_restart_handler(&restart_handler);
  150. }
  151. break;
  152. }
  153. }
  154. of_node_put(np);
  155. return 0;
  156. }
  157. arch_initcall(setup_rstcr);
  158. #endif
  159. #if defined(CONFIG_FB_FSL_DIU) || defined(CONFIG_FB_FSL_DIU_MODULE)
  160. struct platform_diu_data_ops diu_ops;
  161. EXPORT_SYMBOL(diu_ops);
  162. #endif
  163. #ifdef CONFIG_EPAPR_PARAVIRT
  164. /*
  165. * Restart the current partition
  166. *
  167. * This function should be assigned to the ppc_md.restart function pointer,
  168. * to initiate a partition restart when we're running under the Freescale
  169. * hypervisor.
  170. */
  171. void __noreturn fsl_hv_restart(char *cmd)
  172. {
  173. pr_info("hv restart\n");
  174. fh_partition_restart(-1);
  175. while (1) ;
  176. }
  177. /*
  178. * Halt the current partition
  179. *
  180. * This function should be assigned to the pm_power_off and ppc_md.halt
  181. * function pointers, to shut down the partition when we're running under
  182. * the Freescale hypervisor.
  183. */
  184. void __noreturn fsl_hv_halt(void)
  185. {
  186. pr_info("hv exit\n");
  187. fh_partition_stop(-1);
  188. while (1) ;
  189. }
  190. #endif