fsl_soc.c 5.1 KB

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